Skip to content

Commit

Permalink
fix tests and minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
azuline committed Apr 26, 2024
1 parent ea78c66 commit d73039a
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 64 deletions.
8 changes: 4 additions & 4 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ def seeded_cache(config: Config) -> None:
conn.executescript(
f"""\
INSERT INTO releases
(id , source_path , cover_image_path , added_at , datafile_mtime, title , releasetype, releasedate, originaldate, compositiondate, catalognumber, edition , disctotal, new , metahash)
VALUES ('r1', '{dirpaths[0]}', null , '0000-01-01T00:00:00+00:00', '999' , 'Release 1', 'album' , 2023 , null , null , null , null , 1 , false, '1')
, ('r2', '{dirpaths[1]}', '{imagepaths[0]}', '0000-01-01T00:00:00+00:00', '999' , 'Release 2', 'album' , 2021 , 2019 , null , 'DG-001' , 'Deluxe', 1 , false, '2')
, ('r3', '{dirpaths[2]}', null , '0000-01-01T00:00:00+00:00', '999' , 'Release 3', 'album' , 2021 , null , 1780 , 'DG-002' , null , 1 , true , '3');
(id , source_path , cover_image_path , added_at , datafile_mtime, title , releasetype, releasedate , originaldate, compositiondate, catalognumber, edition , disctotal, new , metahash)
VALUES ('r1', '{dirpaths[0]}', null , '0000-01-01T00:00:00+00:00', '999' , 'Release 1', 'album' , '2023' , null , null , null , null , 1 , false, '1')
, ('r2', '{dirpaths[1]}', '{imagepaths[0]}', '0000-01-01T00:00:00+00:00', '999' , 'Release 2', 'album' , '2021' , '2019' , null , 'DG-001' , 'Deluxe', 1 , false, '2')
, ('r3', '{dirpaths[2]}', null , '0000-01-01T00:00:00+00:00', '999' , 'Release 3', 'album' , '2021-04-20', null , '1780' , 'DG-002' , null , 1 , true , '3');
INSERT INTO releases_genres
(release_id, genre , position)
Expand Down
2 changes: 1 addition & 1 deletion rose/audiotags.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class RoseDate:
def parse(cls, value: str | None) -> RoseDate | None:
if not value:
return None
if YEAR_REGEX.match(value):
with contextlib.suppress(ValueError):
return RoseDate(year=int(value), month=None, day=None)
# There may be a time value after the date... allow that and other crap.
if m := DATE_REGEX.match(value):
Expand Down
38 changes: 22 additions & 16 deletions rose/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ def from_view(cls, c: Config, row: dict[str, Any], aliases: bool = True) -> Cach
datafile_mtime=row["datafile_mtime"],
releasetitle=row["releasetitle"],
releasetype=row["releasetype"],
releasedate=row["releasedate"],
originaldate=row["originaldate"],
compositiondate=row["compositiondate"],
releasedate=RoseDate.parse(row["releasedate"]),
originaldate=RoseDate.parse(row["originaldate"]),
compositiondate=RoseDate.parse(row["compositiondate"]),
catalognumber=row["catalognumber"],
edition=row["edition"],
disctotal=row["disctotal"],
Expand All @@ -266,9 +266,9 @@ def dump(self) -> dict[str, Any]:
"added_at": self.added_at,
"releasetitle": self.releasetitle,
"releasetype": self.releasetype,
"releasedate": str(self.releasedate),
"originaldate": str(self.originaldate),
"compositiondate": str(self.compositiondate),
"releasedate": str(self.releasedate) if self.releasedate else None,
"originaldate": str(self.originaldate) if self.originaldate else None,
"compositiondate": str(self.compositiondate) if self.compositiondate else None,
"catalognumber": self.catalognumber,
"edition": self.edition,
"new": self.new,
Expand Down Expand Up @@ -344,9 +344,15 @@ def dump(self, with_release_info: bool = True) -> dict[str, Any]:
"releasetitle": self.release.releasetitle,
"releasetype": self.release.releasetype,
"disctotal": self.release.disctotal,
"releasedate": str(self.release.releasedate),
"originaldate": str(self.release.originaldate),
"compositiondate": str(self.release.compositiondate),
"releasedate": str(self.release.releasedate)
if self.release.releasedate
else None,
"originaldate": str(self.release.originaldate)
if self.release.originaldate
else None,
"compositiondate": str(self.release.compositiondate)
if self.release.compositiondate
else None,
"catalognumber": self.release.catalognumber,
"edition": self.release.edition,
"new": self.release.new,
Expand Down Expand Up @@ -1034,9 +1040,9 @@ def _update_cache_for_releases_executor(
release.datafile_mtime,
release.releasetitle,
release.releasetype,
release.releasedate,
release.originaldate,
release.compositiondate,
str(release.releasedate) if release.releasedate else None,
str(release.originaldate) if release.originaldate else None,
str(release.compositiondate) if release.compositiondate else None,
release.edition,
release.catalognumber,
release.disctotal,
Expand Down Expand Up @@ -1507,7 +1513,7 @@ def update_cache_for_collages(
for row in cursor:
desc_map[row["id"]] = calculate_release_logtext(
title=row["releasetitle"],
releasedate=row["releasedate"],
releasedate=RoseDate.parse(row["releasedate"]),
artists=_unpack_artists(
c, row["releaseartist_names"], row["releaseartist_roles"]
),
Expand Down Expand Up @@ -1735,7 +1741,7 @@ def update_cache_for_playlists(
artists=_unpack_artists(
c, row["trackartist_names"], row["trackartist_roles"]
),
releasedate=row["releasedate"],
releasedate=RoseDate.parse(row["releasedate"]),
suffix=Path(row["source_path"]).suffix,
)
for i, trk in enumerate(tracks):
Expand Down Expand Up @@ -1903,7 +1909,7 @@ def get_release_logtext(c: Config, release_id: str) -> str | None:
return None
return calculate_release_logtext(
title=row["releasetitle"],
releasedate=row["releasedate"],
releasedate=RoseDate.parse(row["releasedate"]),
artists=_unpack_artists(c, row["releaseartist_names"], row["releaseartist_roles"]),
)

Expand Down Expand Up @@ -2080,7 +2086,7 @@ def get_track_logtext(c: Config, track_id: str) -> str | None:
return calculate_track_logtext(
title=row["tracktitle"],
artists=_unpack_artists(c, row["trackartist_names"], row["trackartist_roles"]),
releasedate=row["releasedate"],
releasedate=RoseDate.parse(row["releasedate"]),
suffix=Path(row["source_path"]).suffix,
)

Expand Down
6 changes: 3 additions & 3 deletions rose/cache.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ CREATE TABLE releases (
datafile_mtime TEXT NOT NULL,
title TEXT NOT NULL,
releasetype TEXT NOT NULL,
releasedate INTEGER,
originaldate INTEGER,
compositiondate INTEGER,
releasedate TEXT,
originaldate TEXT,
compositiondate TEXT,
edition TEXT,
catalognumber TEXT,
disctotal INTEGER NOT NULL,
Expand Down
12 changes: 6 additions & 6 deletions rose/cache_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_update_cache_releases(config: Config) -> None:
assert row["source_path"] == str(release_dir)
assert row["title"] == "I Love Blackpink"
assert row["releasetype"] == "album"
assert row["releasedate"] == 1990
assert row["releasedate"] == "1990-02-05"
assert row["compositiondate"] is None
assert row["catalognumber"] is None
assert row["new"]
Expand Down Expand Up @@ -317,7 +317,7 @@ def test_update_cache_releases_already_fully_cached(config: Config) -> None:
assert row["source_path"] == str(release_dir)
assert row["title"] == "I Love Blackpink"
assert row["releasetype"] == "album"
assert row["releasedate"] == 1990
assert row["releasedate"] == "1990-02-05"
assert row["new"]


Expand All @@ -342,7 +342,7 @@ def test_update_cache_releases_disk_update_to_previously_cached(config: Config)
assert row["source_path"] == str(release_dir)
assert row["title"] == "I Love Blackpink"
assert row["releasetype"] == "album"
assert row["releasedate"] == 1990
assert row["releasedate"] == "1990-02-05"
assert row["new"]


Expand Down Expand Up @@ -402,7 +402,7 @@ def test_update_cache_releases_source_path_renamed(config: Config) -> None:
assert row["source_path"] == str(moved_release_dir)
assert row["title"] == "I Love Blackpink"
assert row["releasetype"] == "album"
assert row["releasedate"] == 1990
assert row["releasedate"] == "1990-02-05"
assert row["new"]


Expand Down Expand Up @@ -1153,7 +1153,7 @@ def test_list_releases(config: Config) -> None:
added_at="0000-01-01T00:00:00+00:00",
releasetitle="Release 3",
releasetype="album",
releasedate=RoseDate(2021),
releasedate=RoseDate(2021, 4, 20),
compositiondate=RoseDate(1780),
catalognumber="DG-002",
disctotal=1,
Expand Down Expand Up @@ -1441,7 +1441,7 @@ def test_list_tracks(config: Config) -> None:
datafile_mtime="999",
releasetitle="Release 3",
releasetype="album",
releasedate=RoseDate(2021),
releasedate=RoseDate(2021, 4, 20),
compositiondate=RoseDate(1780),
catalognumber="DG-002",
new=True,
Expand Down
12 changes: 6 additions & 6 deletions rose/collages_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def test_dump_collage(config: Config) -> None:
"added_at": "0000-01-01T00:00:00+00:00",
"releasetitle": "Release 1",
"releasetype": "album",
"releasedate": 2023,
"releasedate": "2023",
"compositiondate": None,
"catalognumber": None,
"new": False,
Expand Down Expand Up @@ -177,15 +177,15 @@ def test_dump_collage(config: Config) -> None:
"added_at": "0000-01-01T00:00:00+00:00",
"releasetitle": "Release 2",
"releasetype": "album",
"releasedate": 2021,
"releasedate": "2021",
"compositiondate": None,
"catalognumber": "DG-001",
"new": False,
"disctotal": 1,
"genres": ["Classical"],
"parent_genres": [],
"labels": ["Native State"],
"originaldate": 2019,
"originaldate": "2019",
"edition": "Deluxe",
"secondary_genres": ["Orchestral"],
"parent_secondary_genres": [
Expand Down Expand Up @@ -222,7 +222,7 @@ def test_dump_collages(config: Config) -> None:
"added_at": "0000-01-01T00:00:00+00:00",
"releasetitle": "Release 1",
"releasetype": "album",
"releasedate": 2023,
"releasedate": "2023",
"compositiondate": None,
"catalognumber": None,
"new": False,
Expand Down Expand Up @@ -267,15 +267,15 @@ def test_dump_collages(config: Config) -> None:
"added_at": "0000-01-01T00:00:00+00:00",
"releasetitle": "Release 2",
"releasetype": "album",
"releasedate": 2021,
"releasedate": "2021",
"compositiondate": None,
"catalognumber": "DG-001",
"new": False,
"disctotal": 1,
"genres": ["Classical"],
"parent_genres": [],
"labels": ["Native State"],
"originaldate": 2019,
"originaldate": "2019",
"edition": "Deluxe",
"secondary_genres": ["Orchestral"],
"parent_secondary_genres": [
Expand Down
12 changes: 6 additions & 6 deletions rose/playlists_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_dump_playlist(config: Config) -> None:
"release_id": "r1",
"releasetitle": "Release 1",
"releasetype": "album",
"releasedate": 2023,
"releasedate": "2023",
"compositiondate": None,
"catalognumber": None,
"new": False,
Expand Down Expand Up @@ -216,14 +216,14 @@ def test_dump_playlist(config: Config) -> None:
"release_id": "r2",
"releasetitle": "Release 2",
"releasetype": "album",
"releasedate": 2021,
"releasedate": "2021",
"compositiondate": None,
"catalognumber": "DG-001",
"new": False,
"genres": ["Classical"],
"parent_genres": [],
"labels": ["Native State"],
"originaldate": 2019,
"originaldate": "2019",
"edition": "Deluxe",
"secondary_genres": ["Orchestral"],
"parent_secondary_genres": [
Expand Down Expand Up @@ -279,7 +279,7 @@ def test_dump_playlists(config: Config) -> None:
"release_id": "r1",
"releasetitle": "Release 1",
"releasetype": "album",
"releasedate": 2023,
"releasedate": "2023",
"compositiondate": None,
"catalognumber": None,
"new": False,
Expand Down Expand Up @@ -338,14 +338,14 @@ def test_dump_playlists(config: Config) -> None:
"release_id": "r2",
"releasetitle": "Release 2",
"releasetype": "album",
"releasedate": 2021,
"releasedate": "2021",
"compositiondate": None,
"catalognumber": "DG-001",
"new": False,
"genres": ["Classical"],
"parent_genres": [],
"labels": ["Native State"],
"originaldate": 2019,
"originaldate": "2019",
"edition": "Deluxe",
"secondary_genres": ["Orchestral"],
"parent_secondary_genres": [
Expand Down
8 changes: 4 additions & 4 deletions rose/releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ def serialize(self) -> str:
# LOL TOML DOESN'T HAVE A NULL TYPE. Use -9999 as sentinel. If your music is legitimately
# released in -9999, you should probably lay off the shrooms.
data = asdict(self)
data["releasedate"] = self.releasedate or -9999
data["originaldate"] = self.originaldate or -9999
data["compositiondate"] = self.compositiondate or -9999
data["releasedate"] = str(self.releasedate) if self.releasedate else ""
data["originaldate"] = str(self.originaldate) if self.originaldate else ""
data["compositiondate"] = str(self.compositiondate) if self.compositiondate else ""
data["edition"] = self.edition or -9999
data["catalognumber"] = self.catalognumber or ""
return tomli_w.dumps(data)
Expand Down Expand Up @@ -502,7 +502,7 @@ def create_single_release(c: Config, track_path: Path) -> None:

dirname = f"{artistsfmt(af.trackartists)} - "
if af.releasedate:
dirname += f"{af.releasedate}. "
dirname += f"{af.releasedate.year}. "
dirname += title
# Handle directory name collisions.
collision_no = 2
Expand Down
16 changes: 8 additions & 8 deletions rose/releases_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def test_dump_release(config: Config) -> None:
"added_at": "0000-01-01T00:00:00+00:00",
"releasetitle": "Release 1",
"releasetype": "album",
"releasedate": 2023,
"releasedate": "2023",
"compositiondate": None,
"catalognumber": None,
"new": False,
Expand Down Expand Up @@ -548,7 +548,7 @@ def test_dump_releases(config: Config) -> None:
"added_at": "0000-01-01T00:00:00+00:00",
"releasetitle": "Release 1",
"releasetype": "album",
"releasedate": 2023,
"releasedate": "2023",
"compositiondate": None,
"catalognumber": None,
"new": False,
Expand Down Expand Up @@ -636,15 +636,15 @@ def test_dump_releases(config: Config) -> None:
"added_at": "0000-01-01T00:00:00+00:00",
"releasetitle": "Release 2",
"releasetype": "album",
"releasedate": 2021,
"releasedate": "2021",
"compositiondate": None,
"catalognumber": "DG-001",
"new": False,
"disctotal": 1,
"genres": ["Classical"],
"parent_genres": [],
"labels": ["Native State"],
"originaldate": 2019,
"originaldate": "2019",
"edition": "Deluxe",
"secondary_genres": ["Orchestral"],
"parent_secondary_genres": [
Expand Down Expand Up @@ -689,8 +689,8 @@ def test_dump_releases(config: Config) -> None:
"added_at": "0000-01-01T00:00:00+00:00",
"releasetitle": "Release 3",
"releasetype": "album",
"releasedate": 2021,
"compositiondate": 1780,
"releasedate": "2021-04-20",
"compositiondate": "1780",
"catalognumber": "DG-002",
"new": True,
"disctotal": 1,
Expand Down Expand Up @@ -746,15 +746,15 @@ def test_dump_releases_matcher(config: Config) -> None:
"added_at": "0000-01-01T00:00:00+00:00",
"releasetitle": "Release 2",
"releasetype": "album",
"releasedate": 2021,
"releasedate": "2021",
"compositiondate": None,
"catalognumber": "DG-001",
"new": False,
"disctotal": 1,
"genres": ["Classical"],
"parent_genres": [],
"labels": ["Native State"],
"originaldate": 2019,
"originaldate": "2019",
"edition": "Deluxe",
"secondary_genres": ["Orchestral"],
"parent_secondary_genres": [
Expand Down
2 changes: 1 addition & 1 deletion rose/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class PathTemplatePair:
DEFAULT_RELEASE_TEMPLATE = PathTemplate(
"""
{{ releaseartists | artistsfmt }} -
{% if releasedate %}{{ releasedate }}.{% endif %}
{% if releasedate %}{{ releasedate.year }}.{% endif %}
{{ releasetitle }}
{% if releasetype == "single" %}- {{ releasetype | releasetypefmt }}{% endif %}
{% if new %}[NEW]{% endif %}
Expand Down
Loading

0 comments on commit d73039a

Please sign in to comment.