Skip to content

Commit

Permalink
add tests for fast search
Browse files Browse the repository at this point in the history
  • Loading branch information
azuline committed May 6, 2024
1 parent 1f5713a commit 4e01bb6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
25 changes: 24 additions & 1 deletion rose/releases_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"}
30 changes: 28 additions & 2 deletions rose/tracks_test.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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"}

0 comments on commit 4e01bb6

Please sign in to comment.