Skip to content

Commit

Permalink
hmm
Browse files Browse the repository at this point in the history
  • Loading branch information
azuline committed May 6, 2024
1 parent 7defec3 commit c585789
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions rose/rule_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

from __future__ import annotations

import dataclasses
import io
import logging
import re
import shlex
from collections.abc import Sequence
from dataclasses import dataclass
from typing import Literal

import click
Expand Down Expand Up @@ -223,7 +223,7 @@ def __str__(self) -> str:
]


@dataclass
@dataclasses.dataclass
class ReplaceAction:
"""
Replaces the matched tag with `replacement`. For multi-valued tags, `;` is treated as a
Expand All @@ -233,7 +233,7 @@ class ReplaceAction:
replacement: str


@dataclass
@dataclasses.dataclass
class SedAction:
"""
Executes a regex substitution on a tag value.
Expand All @@ -243,7 +243,7 @@ class SedAction:
dst: str


@dataclass
@dataclasses.dataclass
class SplitAction:
"""
Splits a tag into multiple tags on the provided delimiter. This action is only allowed on
Expand All @@ -253,7 +253,7 @@ class SplitAction:
delimiter: str


@dataclass
@dataclasses.dataclass
class AddAction:
"""
Adds a value to the tag. This action is only allowed on multi-value tags. If the value already
Expand All @@ -263,14 +263,14 @@ class AddAction:
value: str


@dataclass
@dataclasses.dataclass
class DeleteAction:
"""
Deletes the tag value.
"""


@dataclass
@dataclasses.dataclass(slots=True)
class Pattern:
# Substring match with support for `^$` strict start / strict end matching.
needle: str
Expand Down Expand Up @@ -314,7 +314,7 @@ def __str__(self) -> str:
return r


@dataclass()
@dataclasses.dataclass(slots=True)
class Matcher:
# Tags to test against the pattern. If any tags match the pattern, the action will be ran
# against the track.
Expand Down Expand Up @@ -411,7 +411,7 @@ def parse(cls, raw: str, *, rule_name: str = "matcher") -> Matcher:
return matcher


@dataclass
@dataclasses.dataclass(slots=True)
class Action:
# The tags to apply the action on. Defaults to the tag that the pattern matched.
tags: list[Tag]
Expand Down Expand Up @@ -727,7 +727,7 @@ def parse(
return action


@dataclass
@dataclasses.dataclass
class Rule:
matcher: Matcher
actions: list[Action]
Expand Down
10 changes: 5 additions & 5 deletions rose/rule_parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def test_rule_parse_matcher() -> None:
assert Matcher.parse("tracktitle:Track$") == Matcher(
["tracktitle"], Pattern("Track", strict_end=True)
)
assert Matcher.parse(r"tracktitle:\^Track") == Matcher(["tracktitle"], Pattern("^Track"))
assert Matcher.parse(r"tracktitle:Track\$") == Matcher(["tracktitle"], Pattern("Track$"))
assert Matcher.parse(r"tracktitle:\^Track") == Matcher(["tracktitle"], Pattern(r"\^Track"))
assert Matcher.parse(r"tracktitle:Track\$") == Matcher(["tracktitle"], Pattern(r"Track\$"))

def test_err(rule: str, err: str) -> None:
with pytest.raises(RuleSyntaxError) as exc:
Expand Down Expand Up @@ -535,13 +535,13 @@ def test_rule_parsing_multi_value_validation() -> None:
def test_rule_parsing_defaults() -> None:
rule = Rule.parse("tracktitle:Track", ["replace:hi"])
assert rule.actions[0].pattern is not None
assert rule.actions[0].pattern.pattern == "Track"
assert rule.actions[0].pattern.needle == "Track"
rule = Rule.parse("tracktitle:Track", ["tracktitle/replace:hi"])
assert rule.actions[0].pattern is not None
assert rule.actions[0].pattern.pattern == "Track"
assert rule.actions[0].pattern.needle == "Track"
rule = Rule.parse("tracktitle:Track", ["tracktitle:Lack/replace:hi"])
assert rule.actions[0].pattern is not None
assert rule.actions[0].pattern.pattern == "Lack"
assert rule.actions[0].pattern.needle == "Lack"


def test_parser_take() -> None:
Expand Down

0 comments on commit c585789

Please sign in to comment.