diff --git a/tests/test_commands.py b/tests/test_commands.py index 668ef9b..d069dbf 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -26,7 +26,7 @@ from argparse import Namespace from hashlib import sha1, sha256 # nosec from pathlib import Path -from urllib.parse import quote_plus +from urllib.parse import quote import pyben import pytest @@ -54,7 +54,7 @@ def test_magnet_uri(metafile1): magnet_link = magnet(metafile1) meta = pyben.load(metafile1) announce = meta["announce"] - assert quote_plus(announce) in magnet_link + assert quote(announce) in magnet_link def test_magnet_hex(metafile1): @@ -105,16 +105,18 @@ def test_magnet_no_announce(metafile2): magnet_link = magnet(metafile2) assert magnet_link.startswith("magnet") + def test_magnet_web_seed(metafile2): """ Test create magnet function scheme. """ - fake_web_seed = "fake-web-seed" + fake_web_seed = ["fake-web-seed"] meta = pyben.load(metafile2) meta["url-list"] = fake_web_seed pyben.dump(meta, metafile2) magnet_link = magnet(metafile2) - assert quote_plus(fake_web_seed) in magnet_link + assert quote(fake_web_seed[0]) in magnet_link + def test_magnet_empty(): """ diff --git a/torrentfile/cli.py b/torrentfile/cli.py index da985a5..823b288 100644 --- a/torrentfile/cli.py +++ b/torrentfile/cli.py @@ -42,6 +42,7 @@ import sys import logging from argparse import ArgumentParser, HelpFormatter +from typing import List from torrentfile import commands from torrentfile.utils import toggle_debug_mode @@ -98,7 +99,7 @@ class TorrentFileHelpFormatter(HelpFormatter): def __init__(self, prog: str, width: int = 45, - max_help_positions: int = 45): + max_help_positions: int = 45) -> None: """ Construct HelpFormat class for usage output. @@ -194,7 +195,7 @@ def _format_headers(parts: list) -> list: return parts -def execute(args: list = None) -> list: +def execute(args: List[str] = None) -> List[str]: """ Execute program with provided list of arguments. diff --git a/torrentfile/commands.py b/torrentfile/commands.py index 33882c5..b9e5548 100644 --- a/torrentfile/commands.py +++ b/torrentfile/commands.py @@ -412,7 +412,6 @@ def magnet(metafile: str, version: int = 0) -> str: ] elif "announce" in meta: announce_args = ["&tr=" + quote_plus(meta["announce"])] - trackers = "".join(announce_args) @@ -422,7 +421,7 @@ def magnet(metafile: str, version: int = 0) -> str: if "url-list" in meta: web_sources = [ "&ws=" + quote_plus(urllist) for urllist in meta["url-list"] - ] + ] web_seed = "".join(web_sources) diff --git a/torrentfile/recheck.py b/torrentfile/recheck.py index 7ef6c3a..ff549b5 100644 --- a/torrentfile/recheck.py +++ b/torrentfile/recheck.py @@ -429,8 +429,7 @@ def extract(self, path: str, partial: bytearray) -> bytearray: yield partial partial = bytearray(0) if length != read: - for pad in self._gen_padding(partial, length, read): - yield pad + yield from self._gen_padding(partial, length, read) def _gen_padding(self, partial: bytes, length: int, read=0) -> bytes: """ diff --git a/torrentfile/utils.py b/torrentfile/utils.py index d95cbd2..d7773fb 100644 --- a/torrentfile/utils.py +++ b/torrentfile/utils.py @@ -25,6 +25,7 @@ import ctypes import shutil import platform +from typing import Callable, Any, Tuple, List from pathlib import Path if platform.system() == "Windows": # pragma: nocover @@ -42,7 +43,7 @@ class Memo: The results of this callable will be cached. """ - def __init__(self, func): + def __init__(self, func: Callable) -> None: """ Construct cache. """ @@ -50,7 +51,7 @@ def __init__(self, func): self.counter = 0 self.cache = {} - def __call__(self, path: str): + def __call__(self, path: str) -> Any: """ Invoke each time memo function is executed. @@ -239,7 +240,7 @@ def filelist_total(pathstring: str) -> os.PathLike: raise MissingPathError -def _filelist_total(path: os.PathLike) -> tuple: +def _filelist_total(path: os.PathLike) -> Tuple[int, List[str]]: """ Recursively search directory tree for files. @@ -303,7 +304,7 @@ def get_file_list(path: str) -> list: return filelist -def path_stat(path: str) -> tuple: +def path_stat(path: str) -> Tuple: """ Calculate directory statistics. @@ -397,7 +398,7 @@ def copypath(source: str, dest: str) -> None: shutil.copy(source, dest) -def toggle_debug_mode(switch_on: bool): +def toggle_debug_mode(switch_on: bool) -> None: """ Switch the environment variable debug indicator on or off. diff --git a/tox.ini b/tox.ini index 982151e..257c48e 100644 --- a/tox.ini +++ b/tox.ini @@ -5,12 +5,7 @@ [tox] envlist = - pylint - pycodestyle - pydocstyle - flake8 - pyroma - security + linting format twinecheck py @@ -47,48 +42,23 @@ commands = isort torrentfile tests autopep8 -r torrentfile tests -[testenv:security] -basepython = python3 -deps = - bandit[toml] -commands = - bandit -r -c pyproject.toml torrentfile tests - -[testenv:flake8] +[testenv:linting] basepython = python3 deps = flake8 mccabe -commands = - flake8 torrentfile tests - -[testenv:pyroma] -basepython = python3 -deps = + bandit[toml] pyroma -commands = - pyroma . - -[testenv:pycodestyle] -basepython = python3 -deps = pycodestyle -commands = - pycodestyle torrentfile tests - -[testenv:pydocstyle] -basepython = python3 -deps = pydocstyle -commands = - pydocstyle torrentfile tests - -[testenv:pylint] -basepython = python3 -deps = pylint pytest commands = + flake8 torrentfile tests + bandit -r -c pyproject.toml torrentfile tests + pyroma . + pycodestyle torrentfile tests + pydocstyle torrentfile tests pylint torrentfile tests [testenv:twinecheck]