Replace assertAlmostEqual and assertEqualTimes

This commit is contained in:
Šarūnas Nejus 2024-08-05 18:59:38 +01:00
parent e36e8f1f51
commit 038843cdb2
No known key found for this signature in database
GPG key ID: DD28F6704DBE3435

View file

@ -68,10 +68,6 @@ class ImportAddedTest(PluginMixin, AutotagImportTestCase):
"No MediaFile found for Item " + displayable_path(item.path) "No MediaFile found for Item " + displayable_path(item.path)
) )
def assertEqualTimes(self, first, second, msg=None):
"""For comparing file modification times at a sufficient precision"""
assert first == pytest.approx(second, rel=1e-4), msg
def assertAlbumImport(self): def assertAlbumImport(self):
self.importer.run() self.importer.run()
album = self.lib.albums().get() album = self.lib.albums().get()
@ -95,10 +91,12 @@ class ImportAddedTest(PluginMixin, AutotagImportTestCase):
album = self.lib.albums().get() album = self.lib.albums().get()
assert album.added == self.min_mtime assert album.added == self.min_mtime
for item in album.items(): for item in album.items():
self.assertEqualTimes(item.added, self.min_mtime) assert item.added == pytest.approx(self.min_mtime, rel=1e-4)
mediafile_mtime = os.path.getmtime(self.find_media_file(item).path) mediafile_mtime = os.path.getmtime(self.find_media_file(item).path)
self.assertEqualTimes(item.mtime, mediafile_mtime) assert item.mtime == pytest.approx(mediafile_mtime, rel=1e-4)
self.assertEqualTimes(os.path.getmtime(item.path), mediafile_mtime) assert os.path.getmtime(item.path) == pytest.approx(
mediafile_mtime, rel=1e-4
)
def test_reimported_album_skipped(self): def test_reimported_album_skipped(self):
# Import and record the original added dates # Import and record the original added dates
@ -113,22 +111,21 @@ class ImportAddedTest(PluginMixin, AutotagImportTestCase):
self.importer.run() self.importer.run()
# Verify the reimported items # Verify the reimported items
album = self.lib.albums().get() album = self.lib.albums().get()
self.assertEqualTimes(album.added, album_added_before) assert album.added == pytest.approx(album_added_before, rel=1e-4)
items_added_after = {item.path: item.added for item in album.items()} items_added_after = {item.path: item.added for item in album.items()}
for item_path, added_after in items_added_after.items(): for item_path, added_after in items_added_after.items():
self.assertEqualTimes( assert items_added_before[item_path] == pytest.approx(
items_added_before[item_path], added_after, rel=1e-4
added_after, ), "reimport modified Item.added for " + displayable_path(item_path)
"reimport modified Item.added for "
+ displayable_path(item_path),
)
def test_import_singletons_with_added_dates(self): def test_import_singletons_with_added_dates(self):
self.config["import"]["singletons"] = True self.config["import"]["singletons"] = True
self.importer.run() self.importer.run()
for item in self.lib.items(): for item in self.lib.items():
mfile = self.find_media_file(item) mfile = self.find_media_file(item)
self.assertEqualTimes(item.added, os.path.getmtime(mfile.path)) assert item.added == pytest.approx(
os.path.getmtime(mfile.path), rel=1e-4
)
def test_import_singletons_with_preserved_mtimes(self): def test_import_singletons_with_preserved_mtimes(self):
self.config["import"]["singletons"] = True self.config["import"]["singletons"] = True
@ -136,9 +133,11 @@ class ImportAddedTest(PluginMixin, AutotagImportTestCase):
self.importer.run() self.importer.run()
for item in self.lib.items(): for item in self.lib.items():
mediafile_mtime = os.path.getmtime(self.find_media_file(item).path) mediafile_mtime = os.path.getmtime(self.find_media_file(item).path)
self.assertEqualTimes(item.added, mediafile_mtime) assert item.added == pytest.approx(mediafile_mtime, rel=1e-4)
self.assertEqualTimes(item.mtime, mediafile_mtime) assert item.mtime == pytest.approx(mediafile_mtime, rel=1e-4)
self.assertEqualTimes(os.path.getmtime(item.path), mediafile_mtime) assert os.path.getmtime(item.path) == pytest.approx(
mediafile_mtime, rel=1e-4
)
def test_reimported_singletons_skipped(self): def test_reimported_singletons_skipped(self):
self.config["import"]["singletons"] = True self.config["import"]["singletons"] = True
@ -155,9 +154,6 @@ class ImportAddedTest(PluginMixin, AutotagImportTestCase):
# Verify the reimported items # Verify the reimported items
items_added_after = {item.path: item.added for item in self.lib.items()} items_added_after = {item.path: item.added for item in self.lib.items()}
for item_path, added_after in items_added_after.items(): for item_path, added_after in items_added_after.items():
self.assertEqualTimes( assert items_added_before[item_path] == pytest.approx(
items_added_before[item_path], added_after, rel=1e-4
added_after, ), "reimport modified Item.added for " + displayable_path(item_path)
"reimport modified Item.added for "
+ displayable_path(item_path),
)