summaryrefslogtreecommitdiffstats
path: root/test/test_downloader.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_downloader.py')
-rw-r--r--test/test_downloader.py28
1 files changed, 14 insertions, 14 deletions
diff --git a/test/test_downloader.py b/test/test_downloader.py
index 3e5bf84..ecd8b85 100644
--- a/test/test_downloader.py
+++ b/test/test_downloader.py
@@ -183,7 +183,7 @@ class TestDownloaderBase(unittest.TestCase):
@classmethod
def _prepare_destination(cls, content=None, part=True, extension=None):
- name = "file-{}".format(cls.fnum)
+ name = f"file-{cls.fnum}"
cls.fnum += 1
kwdict = {
@@ -199,7 +199,7 @@ class TestDownloaderBase(unittest.TestCase):
pathfmt.build_path()
if content:
- mode = "w" + ("b" if isinstance(content, bytes) else "")
+ mode = "wb" if isinstance(content, bytes) else "w"
with pathfmt.open(mode) as fp:
fp.write(content)
@@ -211,10 +211,10 @@ class TestDownloaderBase(unittest.TestCase):
success = self.downloader.download(url, pathfmt)
# test successful download
- self.assertTrue(success, "downloading '{}' failed".format(url))
+ self.assertTrue(success, f"downloading '{url}' failed")
# test content
- mode = "r" + ("b" if isinstance(output, bytes) else "")
+ mode = "rb" if isinstance(output, bytes) else "r"
with pathfmt.open(mode) as fp:
content = fp.read()
self.assertEqual(content, output)
@@ -245,16 +245,16 @@ class TestHTTPDownloader(TestDownloaderBase):
server = http.server.HTTPServer((host, port), HttpRequestHandler)
except OSError as exc:
raise unittest.SkipTest(
- "cannot spawn local HTTP server ({})".format(exc))
+ f"cannot spawn local HTTP server ({exc})")
host, port = server.server_address
- cls.address = "http://{}:{}".format(host, port)
+ cls.address = f"http://{host}:{port}"
threading.Thread(target=server.serve_forever, daemon=True).start()
def _run_test(self, ext, input, output,
extension, expected_extension=None):
TestDownloaderBase._run_test(
- self, self.address + "/" + ext, input, output,
+ self, f"{self.address}/{ext}", input, output,
extension, expected_extension)
def tearDown(self):
@@ -281,7 +281,7 @@ class TestHTTPDownloader(TestDownloaderBase):
self._run_test("gif", None, DATA["gif"], "jpg", "gif")
def test_http_filesize_min(self):
- url = self.address + "/gif"
+ url = f"{self.address}/gif"
pathfmt = self._prepare_destination(None, extension=None)
self.downloader.minsize = 100
with self.assertLogs(self.downloader.log, "WARNING"):
@@ -290,7 +290,7 @@ class TestHTTPDownloader(TestDownloaderBase):
self.assertEqual(pathfmt.temppath, "")
def test_http_filesize_max(self):
- url = self.address + "/jpg"
+ url = f"{self.address}/jpg"
pathfmt = self._prepare_destination(None, extension=None)
self.downloader.maxsize = 100
with self.assertLogs(self.downloader.log, "WARNING"):
@@ -334,8 +334,8 @@ class HttpRequestHandler(http.server.BaseHTTPRequestHandler):
match = re.match(r"bytes=(\d+)-", self.headers["Range"])
start = int(match[1])
- headers["Content-Range"] = "bytes {}-{}/{}".format(
- start, len(output)-1, len(output))
+ headers["Content-Range"] = \
+ f"bytes {start}-{len(output) - 1}/{len(output)}"
output = output[start:]
else:
status = 200
@@ -408,7 +408,7 @@ for ext, content in SAMPLES:
DATA[ext] = content
for idx, (_, content) in enumerate(SAMPLES):
- DATA["S{:>02}".format(idx)] = content
+ DATA[f"S{idx:>02}"] = content
# reverse mime types mapping
@@ -421,8 +421,8 @@ MIME_TYPES = {
def generate_tests():
def generate_test(idx, ext, content):
def test(self):
- self._run_test("S{:>02}".format(idx), None, content, "bin", ext)
- test.__name__ = "test_http_ext_{:>02}_{}".format(idx, ext)
+ self._run_test(f"S{idx:>02}", None, content, "bin", ext)
+ test.__name__ = f"test_http_ext_{idx:>02}_{ext}"
return test
for idx, (ext, content) in enumerate(SAMPLES):