fix downloader tests

This commit is contained in:
Mike Fährmann
2018-06-07 22:27:36 +02:00
parent 37d97ff02c
commit b344f2290f

View File

@@ -54,9 +54,8 @@ class TestDownloaderBase(unittest.TestCase):
pathfmt.set_keywords(kwdict) pathfmt.set_keywords(kwdict)
if content: if content:
path = pathfmt.realpath + (".part" if part else "")
mode = "w" + ("b" if isinstance(content, bytes) else "") mode = "w" + ("b" if isinstance(content, bytes) else "")
with open(path, mode) as file: with pathfmt.open(mode) as file:
file.write(content) file.write(content)
return pathfmt return pathfmt
@@ -65,20 +64,23 @@ class TestDownloaderBase(unittest.TestCase):
extension, expected_extension=None): extension, expected_extension=None):
pathfmt = self._prepare_destination(input, extension=extension) pathfmt = self._prepare_destination(input, extension=extension)
success = self.downloader.download(url, pathfmt) success = self.downloader.download(url, pathfmt)
path = pathfmt.realpath
# test successful download # test successful download
self.assertTrue(success, "downloading '{}' failed".format(url)) self.assertTrue(success, "downloading '{}' failed".format(url))
# test content # test content
mode = "r" + ("b" if isinstance(output, bytes) else "") mode = "r" + ("b" if isinstance(output, bytes) else "")
with open(path, mode) as file: with pathfmt.open(mode) as file:
content = file.read() content = file.read()
self.assertEqual(content, output) self.assertEqual(content, output)
# test filename extension # test filename extension
self.assertEqual( self.assertEqual(
os.path.splitext(path)[1][1:], pathfmt.keywords["extension"],
expected_extension,
)
self.assertEqual(
os.path.splitext(pathfmt.realpath)[1][1:],
expected_extension, expected_extension,
) )