Skip to content

Commit

Permalink
update releases dump output to be reasonable
Browse files Browse the repository at this point in the history
  • Loading branch information
azuline committed Nov 3, 2023
1 parent 7ad3c23 commit d903089
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 14 deletions.
11 changes: 1 addition & 10 deletions rose/releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import shutil
from dataclasses import asdict, dataclass
from pathlib import Path
from typing import Any

import click
import tomli_w
Expand Down Expand Up @@ -47,16 +46,8 @@ class UnknownArtistRoleError(RoseError):
pass


class CustomJSONEncoder(json.JSONEncoder):
def default(self, obj: Any) -> Any:
if isinstance(obj, Path):
return str(obj)
return super().default(obj)


def dump_releases(c: Config) -> str:
releases = [asdict(r) for r in list_releases(c)]
return json.dumps(releases, cls=CustomJSONEncoder)
return json.dumps([r.dump() for r in list_releases(c)])


def delete_release(c: Config, release_id_or_virtual_dirname: str) -> None:
Expand Down
59 changes: 55 additions & 4 deletions rose/releases_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import shutil
from pathlib import Path
from typing import Any
Expand All @@ -22,10 +23,6 @@
)


def test_dump_releases(config: Config) -> None:
assert dump_releases(config) == "[]"


def test_delete_release(config: Config) -> None:
shutil.copytree(TEST_RELEASE_1, config.music_source_dir / TEST_RELEASE_1.name)
update_cache(config)
Expand Down Expand Up @@ -240,6 +237,60 @@ def test_extract_single_release(config: Config) -> None:
assert af.album_artists == af.artists


@pytest.mark.usefixtures("seeded_cache")
def test_dump_releases(config: Config) -> None:
assert json.loads(dump_releases(config)) == [
{
"added_at": "0000-01-01T00:00:00+00:00",
"artists": [
{"alias": False, "name": "Bass Man", "role": "main"},
{"alias": False, "name": "Techno Man", "role": "main"},
],
"cover_image_path": None,
"formatted_artists": "Techno Man;Bass Man",
"genres": ["Deep House", "Techno"],
"id": "r1",
"labels": ["Silk Music"],
"new": False,
"releasetype": "album",
"source_path": f"{config.music_source_dir}/r1",
"title": "Release 1",
"year": 2023,
},
{
"added_at": "0000-01-01T00:00:00+00:00",
"artists": [
{"alias": False, "name": "Conductor Woman", "role": "guest"},
{"alias": False, "name": "Violin Woman", "role": "main"},
],
"cover_image_path": f"{config.music_source_dir}/r2/cover.jpg",
"formatted_artists": "Violin Woman feat. Conductor Woman",
"genres": ["Classical"],
"id": "r2",
"labels": ["Native State"],
"new": False,
"releasetype": "album",
"source_path": f"{config.music_source_dir}/r2",
"title": "Release 2",
"year": 2021,
},
{
"added_at": "0000-01-01T00:00:00+00:00",
"artists": [],
"cover_image_path": None,
"formatted_artists": "",
"genres": [],
"id": "r3",
"labels": [],
"new": True,
"releasetype": "album",
"source_path": f"{config.music_source_dir}/r3",
"title": "Release 3",
"year": 2021,
},
]


def test_resolve_release_ids(config: Config) -> None:
shutil.copytree(TEST_RELEASE_1, config.music_source_dir / TEST_RELEASE_1.name)
update_cache(config)
Expand Down

0 comments on commit d903089

Please sign in to comment.