Replace assertIsFile

This commit is contained in:
Šarūnas Nejus 2024-08-06 22:40:36 +01:00
parent 038843cdb2
commit ca4fa6ba10
No known key found for this signature in database
GPG key ID: DD28F6704DBE3435
2 changed files with 8 additions and 8 deletions

View file

@ -115,11 +115,6 @@ def import_session(lib=None, loghandler=None, paths=[], query=[], cli=False):
class Assertions:
"""A mixin with additional unit test assertions."""
def assertIsFile(self, path):
path = Path(os.fsdecode(path))
assert path.exists()
assert path.is_file()
def assertIsDir(self, path):
path = Path(os.fsdecode(path))
assert path.exists()

View file

@ -58,13 +58,18 @@ class ConvertMixin:
shell_quote(sys.executable), shell_quote(stub), tag
)
def assert_is_file(self, path):
path = Path(os.fsdecode(path))
assert path.exists()
assert path.is_file()
def assertFileTag(self, path, tag):
"""Assert that the path is a file and the files content ends
with `tag`.
"""
display_tag = tag
tag = tag.encode("utf-8")
self.assertIsFile(path)
self.assert_is_file(path)
with open(path, "rb") as f:
f.seek(-len(display_tag), os.SEEK_END)
assert f.read() == tag, (
@ -77,7 +82,7 @@ class ConvertMixin:
"""
display_tag = tag
tag = tag.encode("utf-8")
self.assertIsFile(path)
self.assert_is_file(path)
with open(path, "rb") as f:
f.seek(-len(tag), os.SEEK_END)
assert f.read() != tag, (
@ -117,7 +122,7 @@ class ImportConvertTest(AsIsImporterMixin, ImportHelper, ConvertTestCase):
item = self.lib.items().get()
assert item is not None
self.assertIsFile(item.path)
self.assert_is_file(item.path)
def test_delete_originals(self):
self.config["convert"]["delete_originals"] = True