diff --git a/rose/releases_test.py b/rose/releases_test.py index d99ad82..280ebe9 100644 --- a/rose/releases_test.py +++ b/rose/releases_test.py @@ -24,11 +24,12 @@ delete_release, delete_release_cover_art, edit_release, + find_releases_matching_rule, run_actions_on_release, set_release_cover_art, toggle_release_new, ) -from rose.rule_parser import MetadataAction +from rose.rule_parser import MetadataAction, MetadataMatcher def test_delete_release(config: Config) -> None: @@ -448,3 +449,25 @@ def test_run_action_on_release(config: Config, source_dir: Path) -> None: run_actions_on_release(config, "ilovecarly", [action]) af = AudioTags.from_file(source_dir / "Test Release 2" / "01.m4a") assert af.tracktitle == "Bop" + + +@pytest.mark.usefixtures("seeded_cache") +def test_find_matching_releases(config: Config) -> None: + results = find_releases_matching_rule(config, MetadataMatcher.parse("releasetitle:Release 2")) + assert {r.id for r in results} == {"r2"} + results = find_releases_matching_rule(config, MetadataMatcher.parse("artist:^Techno Man$")) + assert {r.id for r in results} == {"r1"} + results = find_releases_matching_rule(config, MetadataMatcher.parse("artist:Techno Man")) + assert {r.id for r in results} == {"r1"} + results = find_releases_matching_rule(config, MetadataMatcher.parse("genre:^Deep House$")) + assert {r.id for r in results} == {"r1"} + results = find_releases_matching_rule(config, MetadataMatcher.parse("genre:Deep House")) + assert {r.id for r in results} == {"r1"} + results = find_releases_matching_rule(config, MetadataMatcher.parse("descriptor:^Wet$")) + assert {r.id for r in results} == {"r2"} + results = find_releases_matching_rule(config, MetadataMatcher.parse("descriptor:Wet")) + assert {r.id for r in results} == {"r2"} + results = find_releases_matching_rule(config, MetadataMatcher.parse("label:^Native State$")) + assert {r.id for r in results} == {"r2"} + results = find_releases_matching_rule(config, MetadataMatcher.parse("label:Native State")) + assert {r.id for r in results} == {"r2"} diff --git a/rose/tracks_test.py b/rose/tracks_test.py index b7d7cb6..b1b250e 100644 --- a/rose/tracks_test.py +++ b/rose/tracks_test.py @@ -1,9 +1,11 @@ from pathlib import Path +import pytest + from rose.audiotags import AudioTags from rose.config import Config -from rose.rule_parser import MetadataAction -from rose.tracks import run_actions_on_track +from rose.rule_parser import MetadataAction, MetadataMatcher +from rose.tracks import find_tracks_matching_rule, run_actions_on_track def test_run_action_on_track(config: Config, source_dir: Path) -> None: @@ -13,3 +15,27 @@ def test_run_action_on_track(config: Config, source_dir: Path) -> None: run_actions_on_track(config, af.id, [action]) af = AudioTags.from_file(source_dir / "Test Release 2" / "01.m4a") assert af.tracktitle == "Bop" + + +@pytest.mark.usefixtures("seeded_cache") +def test_find_matching_tracks(config: Config) -> None: + results = find_tracks_matching_rule(config, MetadataMatcher.parse("releasetitle:Release 2")) + assert {r.id for r in results} == {"t3"} + results = find_tracks_matching_rule(config, MetadataMatcher.parse("tracktitle:Track 2")) + assert {r.id for r in results} == {"t2"} + results = find_tracks_matching_rule(config, MetadataMatcher.parse("artist:^Techno Man$")) + assert {r.id for r in results} == {"t1", "t2"} + results = find_tracks_matching_rule(config, MetadataMatcher.parse("artist:Techno Man")) + assert {r.id for r in results} == {"t1", "t2"} + results = find_tracks_matching_rule(config, MetadataMatcher.parse("genre:^Deep House$")) + assert {r.id for r in results} == {"t1", "t2"} + results = find_tracks_matching_rule(config, MetadataMatcher.parse("genre:Deep House")) + assert {r.id for r in results} == {"t1", "t2"} + results = find_tracks_matching_rule(config, MetadataMatcher.parse("descriptor:^Wet$")) + assert {r.id for r in results} == {"t3"} + results = find_tracks_matching_rule(config, MetadataMatcher.parse("descriptor:Wet")) + assert {r.id for r in results} == {"t3"} + results = find_tracks_matching_rule(config, MetadataMatcher.parse("label:^Native State$")) + assert {r.id for r in results} == {"t3"} + results = find_tracks_matching_rule(config, MetadataMatcher.parse("label:Native State")) + assert {r.id for r in results} == {"t3"}