Clarify tests

This commit is contained in:
Šarūnas Nejus 2026-02-27 17:52:50 +00:00
parent 10d13992e6
commit a540a8174a
No known key found for this signature in database
2 changed files with 21 additions and 30 deletions

View file

@ -304,15 +304,15 @@ class ImportSingletonTest(AutotagImportTestCase):
assert len(self.lib.albums()) == 2
def test_set_fields(self):
genre = "\U0001f3b7 Jazz"
genres = ["\U0001f3b7 Jazz", "Rock"]
collection = "To Listen"
disc = 0
config["import"]["set_fields"] = {
"genres": "; ".join(genres),
"collection": collection,
"genres": genre,
"title": "$title - formatted",
"disc": disc,
"title": "$title - formatted",
}
# As-is item import.
@ -322,7 +322,7 @@ class ImportSingletonTest(AutotagImportTestCase):
for item in self.lib.items():
item.load() # TODO: Not sure this is necessary.
assert item.genres == [genre]
assert item.genres == genres
assert item.collection == collection
assert item.title == "Tag Track 1 - formatted"
assert item.disc == disc
@ -337,7 +337,7 @@ class ImportSingletonTest(AutotagImportTestCase):
for item in self.lib.items():
item.load()
assert item.genres == [genre]
assert item.genres == genres
assert item.collection == collection
assert item.title == "Applied Track 1 - formatted"
assert item.disc == disc
@ -464,17 +464,17 @@ class ImportTest(PathsMixin, AutotagImportTestCase):
self.lib.items().get().data_source
def test_set_fields(self):
genre = "\U0001f3b7 Jazz"
genres = ["\U0001f3b7 Jazz", "Rock"]
collection = "To Listen"
comments = "managed by beets"
disc = 0
comments = "managed by beets"
config["import"]["set_fields"] = {
"genres": genre,
"genres": "; ".join(genres),
"collection": collection,
"disc": disc,
"comments": comments,
"album": "$album - formatted",
"disc": disc,
}
# As-is album import.
@ -483,10 +483,10 @@ class ImportTest(PathsMixin, AutotagImportTestCase):
self.importer.run()
for album in self.lib.albums():
assert album.genres == [genre]
assert album.genres == genres
assert album.comments == comments
for item in album.items():
assert item.get("genres", with_album=False) == [genre]
assert item.get("genres", with_album=False) == genres
assert item.get("collection", with_album=False) == collection
assert item.get("comments", with_album=False) == comments
assert (
@ -504,10 +504,10 @@ class ImportTest(PathsMixin, AutotagImportTestCase):
self.importer.run()
for album in self.lib.albums():
assert album.genres == [genre]
assert album.genres == genres
assert album.comments == comments
for item in album.items():
assert item.get("genres", with_album=False) == [genre]
assert item.get("genres", with_album=False) == genres
assert item.get("collection", with_album=False) == collection
assert item.get("comments", with_album=False) == comments
assert (

View file

@ -56,27 +56,18 @@ class LoadTest(ItemInDBTestCase):
class StoreTest(ItemInDBTestCase):
def test_store_changes_database_value(self):
self.i.year = 1987
new_year = 1987
self.i.year = new_year
self.i.store()
new_year = (
self.lib._connection()
.execute("select year from items where title = ?", (self.i.title,))
.fetchone()["year"]
)
assert new_year == 1987
assert self.lib.get_item(self.i.id).year == new_year
def test_store_only_writes_dirty_fields(self):
original_genres = self.i.genres
self.i._values_fixed["genres"] = ["beatboxing"] # change w/o dirtying
new_year = 1987
self.i._values_fixed["year"] = new_year # change w/o dirtying
self.i.store()
new_genre = (
self.lib._connection()
.execute(
"select genres from items where title = ?", (self.i.title,)
)
.fetchone()["genres"]
)
assert [new_genre] == original_genres
assert self.lib.get_item(self.i.id).year != new_year
def test_store_clears_dirty_flags(self):
self.i.composer = "tvp"