From 39d1a756a2452ad9b3525252ffd8aee77b34c40a Mon Sep 17 00:00:00 2001 From: Bee Date: Thu, 7 Oct 2021 14:52:35 +0100 Subject: [PATCH] Revert "Fix nox tests (#172)" This reverts commit 524b6fe8879d9955160165fc2e3fe821eda8aee5. --- .github/workflows/main.yaml | 2 +- noxfile.py | 45 +++++++++++--- poetry.lock | 107 +-------------------------------- pyproject.toml | 8 +-- pywhat/filter.py | 4 +- pywhat/helper.py | 2 +- pywhat/identifier.py | 8 +-- pywhat/printer.py | 4 -- scripts/get_file_sigs.py | 4 +- tests/test_regex_identifier.py | 7 ++- 10 files changed, 53 insertions(+), 138 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 09edc8a..f66d008 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -16,6 +16,6 @@ jobs: with: python-version: ${{ matrix.python-version }} architecture: x64 - - run: python -m pip install flake8 nox poetry + - run: python -m pip install flake8==3.8.4 nox==2020.12.31 poetry==1.1.4 - run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - run: python -m nox diff --git a/noxfile.py b/noxfile.py index abe1c7d..7e00364 100644 --- a/noxfile.py +++ b/noxfile.py @@ -4,7 +4,8 @@ import nox from nox.sessions import Session -nox.options.sessions = ["tests"] +package = "hypermodern_python" +nox.options.sessions = "lint", "tests" locations = "src", "tests", "noxfile.py", "docs/conf.py" @@ -33,17 +34,41 @@ def install_with_constraints(session: Session, *args: str, **kwargs: Any) -> Non session.install("--constraint=requirements.txt", *args, **kwargs) -@nox.session +@nox.session(python="3.8") +def black(session: Session) -> None: + """Run black code formatter.""" + args = session.posargs or locations + install_with_constraints(session, "black") + session.run("black", *args) + + +@nox.session(python=["3.8", "3.7"]) +def lint(session: Session) -> None: + pass + + +@nox.session(python=["3.8", "3.7"]) def tests(session: Session) -> None: """Run the test suite.""" session.run("poetry", "install", "--no-dev", external=True) + install_with_constraints(session, "pytest", "pytest-black", "pytest-isort") + session.run("pytest") + + +@nox.session(python=["3.8", "3.7"]) +def typeguard(session: Session) -> None: + """Runtime type checking using Typeguard.""" + args = session.posargs or ["-m", "not e2e"] + session.run("poetry", "install", "--no-dev", external=True) install_with_constraints( - session, - "pytest", - "pytest-black", - "pytest-isort", - "pytest-mypy", - "types-requests", - "types-orjson", + session, "pytest", "pytest-mock", "typeguard", "pytest-black", "pytest-isort" ) - session.run("pytest") + session.run("pytest", f"--typeguard-packages={package}", *args) + + +@nox.session(python="3.8") +def coverage(session: Session) -> None: + """Upload coverage data.""" + install_with_constraints(session, "coverage[toml]", "codecov") + session.run("coverage", "xml", "--fail-under=50") + session.run("codecov", *session.posargs) diff --git a/poetry.lock b/poetry.lock index 5e53cbe..b3aec46 100644 --- a/poetry.lock +++ b/poetry.lock @@ -103,18 +103,6 @@ category = "main" optional = false python-versions = ">=3.6, <3.7" -[[package]] -name = "filelock" -version = "3.3.0" -description = "A platform independent file lock." -category = "dev" -optional = false -python-versions = ">=3.6" - -[package.extras] -docs = ["furo (>=2021.8.17b43)", "sphinx (>=4.1)", "sphinx-autodoc-typehints (>=1.12)"] -testing = ["covdefaults (>=1.2.0)", "coverage (>=4)", "pytest (>=4)", "pytest-cov", "pytest-timeout (>=1.4.2)"] - [[package]] name = "flake8" version = "3.8.4" @@ -184,24 +172,6 @@ category = "dev" optional = false python-versions = "*" -[[package]] -name = "mypy" -version = "0.910" -description = "Optional static typing for Python" -category = "dev" -optional = false -python-versions = ">=3.5" - -[package.dependencies] -mypy-extensions = ">=0.4.3,<0.5.0" -toml = "*" -typed-ast = {version = ">=1.4.0,<1.5.0", markers = "python_version < \"3.8\""} -typing-extensions = ">=3.7.4" - -[package.extras] -dmypy = ["psutil (>=4.0)"] -python2 = ["typed-ast (>=1.4.0,<1.5.0)"] - [[package]] name = "mypy-extensions" version = "0.4.3" @@ -353,24 +323,6 @@ isort = ">=4.0" [package.extras] tests = ["mock"] -[[package]] -name = "pytest-mypy" -version = "0.8.1" -description = "Mypy static type checker plugin for Pytest" -category = "dev" -optional = false -python-versions = ">=3.5" - -[package.dependencies] -attrs = ">=19.0" -filelock = ">=3.0" -mypy = [ - {version = ">=0.500", markers = "python_version < \"3.8\""}, - {version = ">=0.700", markers = "python_version >= \"3.8\" and python_version < \"3.9\""}, - {version = ">=0.780", markers = "python_version >= \"3.9\""}, -] -pytest = ">=3.5" - [[package]] name = "regex" version = "2021.9.30" @@ -439,22 +391,6 @@ category = "dev" optional = false python-versions = "*" -[[package]] -name = "types-orjson" -version = "3.6.0" -description = "Typing stubs for orjson" -category = "dev" -optional = false -python-versions = "*" - -[[package]] -name = "types-requests" -version = "2.25.9" -description = "Typing stubs for requests" -category = "dev" -optional = false -python-versions = "*" - [[package]] name = "typing-extensions" version = "3.10.0.2" @@ -494,7 +430,7 @@ optimize = ["orjson"] [metadata] lock-version = "1.1" python-versions = "^3.6" -content-hash = "a78669cf63b492bdde411ba7e3bebbcc2dfb468d740ae134c815ea6792195698" +content-hash = "4ed01b54ba6576d755dee7580abfa8bafee9afc574676c75045ef1578b297152" [metadata.files] atomicwrites = [ @@ -533,10 +469,6 @@ dataclasses = [ {file = "dataclasses-0.8-py3-none-any.whl", hash = "sha256:0201d89fa866f68c8ebd9d08ee6ff50c0b255f8ec63a71c16fda7af82bb887bf"}, {file = "dataclasses-0.8.tar.gz", hash = "sha256:8479067f342acf957dc82ec415d355ab5edb7e7646b90dc6e2fd1d96ad084c97"}, ] -filelock = [ - {file = "filelock-3.3.0-py3-none-any.whl", hash = "sha256:bbc6a0382fe8ec4744ecdf6683a2e07f65eb10ff1aff53fc02a202565446cde0"}, - {file = "filelock-3.3.0.tar.gz", hash = "sha256:8c7eab13dc442dc249e95158bcc12dec724465919bdc9831fdbf0660f03d1785"}, -] flake8 = [ {file = "flake8-3.8.4-py2.py3-none-any.whl", hash = "sha256:749dbbd6bfd0cf1318af27bf97a14e28e5ff548ef8e5b1566ccfb25a11e7c839"}, {file = "flake8-3.8.4.tar.gz", hash = "sha256:aadae8761ec651813c24be05c6f7b4680857ef6afaae4651a4eccaef97ce6c3b"}, @@ -561,31 +493,6 @@ mccabe = [ {file = "mccabe-0.6.1-py2.py3-none-any.whl", hash = "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42"}, {file = "mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"}, ] -mypy = [ - {file = "mypy-0.910-cp35-cp35m-macosx_10_9_x86_64.whl", hash = "sha256:a155d80ea6cee511a3694b108c4494a39f42de11ee4e61e72bc424c490e46457"}, - {file = "mypy-0.910-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:b94e4b785e304a04ea0828759172a15add27088520dc7e49ceade7834275bedb"}, - {file = "mypy-0.910-cp35-cp35m-manylinux2010_x86_64.whl", hash = "sha256:088cd9c7904b4ad80bec811053272986611b84221835e079be5bcad029e79dd9"}, - {file = "mypy-0.910-cp35-cp35m-win_amd64.whl", hash = "sha256:adaeee09bfde366d2c13fe6093a7df5df83c9a2ba98638c7d76b010694db760e"}, - {file = "mypy-0.910-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:ecd2c3fe726758037234c93df7e98deb257fd15c24c9180dacf1ef829da5f921"}, - {file = "mypy-0.910-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:d9dd839eb0dc1bbe866a288ba3c1afc33a202015d2ad83b31e875b5905a079b6"}, - {file = "mypy-0.910-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:3e382b29f8e0ccf19a2df2b29a167591245df90c0b5a2542249873b5c1d78212"}, - {file = "mypy-0.910-cp36-cp36m-win_amd64.whl", hash = "sha256:53fd2eb27a8ee2892614370896956af2ff61254c275aaee4c230ae771cadd885"}, - {file = "mypy-0.910-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:b6fb13123aeef4a3abbcfd7e71773ff3ff1526a7d3dc538f3929a49b42be03f0"}, - {file = "mypy-0.910-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:e4dab234478e3bd3ce83bac4193b2ecd9cf94e720ddd95ce69840273bf44f6de"}, - {file = "mypy-0.910-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:7df1ead20c81371ccd6091fa3e2878559b5c4d4caadaf1a484cf88d93ca06703"}, - {file = "mypy-0.910-cp37-cp37m-win_amd64.whl", hash = "sha256:0aadfb2d3935988ec3815952e44058a3100499f5be5b28c34ac9d79f002a4a9a"}, - {file = "mypy-0.910-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:ec4e0cd079db280b6bdabdc807047ff3e199f334050db5cbb91ba3e959a67504"}, - {file = "mypy-0.910-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:119bed3832d961f3a880787bf621634ba042cb8dc850a7429f643508eeac97b9"}, - {file = "mypy-0.910-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:866c41f28cee548475f146aa4d39a51cf3b6a84246969f3759cb3e9c742fc072"}, - {file = "mypy-0.910-cp38-cp38-win_amd64.whl", hash = "sha256:ceb6e0a6e27fb364fb3853389607cf7eb3a126ad335790fa1e14ed02fba50811"}, - {file = "mypy-0.910-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:1a85e280d4d217150ce8cb1a6dddffd14e753a4e0c3cf90baabb32cefa41b59e"}, - {file = "mypy-0.910-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:42c266ced41b65ed40a282c575705325fa7991af370036d3f134518336636f5b"}, - {file = "mypy-0.910-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:3c4b8ca36877fc75339253721f69603a9c7fdb5d4d5a95a1a1b899d8b86a4de2"}, - {file = "mypy-0.910-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:c0df2d30ed496a08de5daed2a9ea807d07c21ae0ab23acf541ab88c24b26ab97"}, - {file = "mypy-0.910-cp39-cp39-win_amd64.whl", hash = "sha256:c6c2602dffb74867498f86e6129fd52a2770c48b7cd3ece77ada4fa38f94eba8"}, - {file = "mypy-0.910-py3-none-any.whl", hash = "sha256:ef565033fa5a958e62796867b1df10c40263ea9ded87164d67572834e57a174d"}, - {file = "mypy-0.910.tar.gz", hash = "sha256:704098302473cb31a218f1775a873b376b30b4c18229421e9e9dc8916fd16150"}, -] mypy-extensions = [ {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, @@ -666,10 +573,6 @@ pytest-isort = [ {file = "pytest-isort-2.0.0.tar.gz", hash = "sha256:821a8c5c9c4f3a3c52cfa9c541fbe89ac9e28728125125af53724c4c3f129117"}, {file = "pytest_isort-2.0.0-py3-none-any.whl", hash = "sha256:ab949c593213dad38ba75db32a0ce361fcddd11d4152be4a2c93b85104cc4376"}, ] -pytest-mypy = [ - {file = "pytest-mypy-0.8.1.tar.gz", hash = "sha256:1fa55723a4bf1d054fcba1c3bd694215a2a65cc95ab10164f5808afd893f3b11"}, - {file = "pytest_mypy-0.8.1-py3-none-any.whl", hash = "sha256:6e68e8eb7ceeb7d1c83a1590912f784879f037b51adfb9c17b95c6b2fc57466b"}, -] regex = [ {file = "regex-2021.9.30-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:66696c8336a1b5d1182464f3af3427cc760118f26d0b09a2ddc16a976a4d2637"}, {file = "regex-2021.9.30-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4d87459ad3ab40cd8493774f8a454b2e490d8e729e7e402a0625867a983e4e02"}, @@ -761,14 +664,6 @@ typed-ast = [ {file = "typed_ast-1.4.3-cp39-cp39-win_amd64.whl", hash = "sha256:9c6d1a54552b5330bc657b7ef0eae25d00ba7ffe85d9ea8ae6540d2197a3788c"}, {file = "typed_ast-1.4.3.tar.gz", hash = "sha256:fb1bbeac803adea29cedd70781399c99138358c26d05fcbd23c13016b7f5ec65"}, ] -types-orjson = [ - {file = "types-orjson-3.6.0.tar.gz", hash = "sha256:e8513f75886a13e6061f5658d53d57d97b3af20cb9c3dcee09e31793f3cee28f"}, - {file = "types_orjson-3.6.0-py3-none-any.whl", hash = "sha256:cdbc920c1354a2b54f2b96ffd95523bbfecdd645063ac5ab40915d0680880d8d"}, -] -types-requests = [ - {file = "types-requests-2.25.9.tar.gz", hash = "sha256:4ec8b71da73e5344adb9bee725a74ec8598e7286f9bcb17500d627f259fe4fb9"}, - {file = "types_requests-2.25.9-py3-none-any.whl", hash = "sha256:543ba8b3b23e38ac028da1d163aecbbc27d3cc8f654ae64339da539a191a2b1c"}, -] typing-extensions = [ {file = "typing_extensions-3.10.0.2-py2-none-any.whl", hash = "sha256:d8226d10bc02a29bcc81df19a26e56a9647f8b0a6d4a83924139f4a8b01f17b7"}, {file = "typing_extensions-3.10.0.2-py3-none-any.whl", hash = "sha256:f1d25edafde516b146ecd0613dabcc61409817af4766fbbcfb8d1ad4ec441a34"}, diff --git a/pyproject.toml b/pyproject.toml index 4115114..f379f88 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,9 +21,6 @@ flake8 = "3.8.4" requests = "^2.26.0" pytest-black = "^0.3.12" pytest-isort = "^2.0.0" -pytest-mypy = "^0.8.1" -types-requests = "^2.25.9" -types-orjson = "^3.6.0" [tool.poetry.extras] optimize = ["orjson"] @@ -45,8 +42,5 @@ use_parentheses = true ensure_newline_before_comments = true line_length = 88 -[tool.mypy] -ignore_missing_imports = true - [tool.pytest.ini_options] -addopts = "--black --isort --mypy" +addopts = "--black --isort" \ No newline at end of file diff --git a/pywhat/filter.py b/pywhat/filter.py index aa47c00..cb06d16 100644 --- a/pywhat/filter.py +++ b/pywhat/filter.py @@ -15,9 +15,9 @@ class Filter(Mapping): * {"Tags": ["Identifiers"], "ExcludeTags": ["Credentials"], "MinRarity": 0.6} """ - def __init__(self, filters_dict=None): + def __init__(self, filters_dict: Optional[Mapping] = None): tags = CaseInsensitiveSet(AvailableTags().get_tags()) - self._dict = {} + self._dict = dict() if filters_dict is None: filters_dict = {} diff --git a/pywhat/helper.py b/pywhat/helper.py index 233de6b..67c16ed 100644 --- a/pywhat/helper.py +++ b/pywhat/helper.py @@ -8,7 +8,7 @@ try: import orjson as json except ImportError: - import json # type: ignore + import json class AvailableTags: diff --git a/pywhat/identifier.py b/pywhat/identifier.py index 3cdf874..a69f7d1 100644 --- a/pywhat/identifier.py +++ b/pywhat/identifier.py @@ -13,7 +13,7 @@ def __init__( self, *, dist: Optional[Distribution] = None, - key=Keys.NONE, + key: Callable = Keys.NONE, reverse=False, boundaryless: Optional[Filter] = None, ): @@ -45,7 +45,7 @@ def identify( if boundaryless is None: boundaryless = self.boundaryless - identify_obj: dict = {"File Signatures": {}, "Regexes": {}} + identify_obj = {"File Signatures": {}, "Regexes": {}} search = [] if not only_text and os.path.isdir(text): @@ -64,8 +64,8 @@ def identify( short_name = os.path.basename(string) magic_numbers = pywhat.magic_numbers.get_magic_nums(string) - with open(string, "r", encoding="utf-8", errors="ignore") as file: - contents = [file.read()] + with open(string, "r", encoding="utf-8", errors="ignore") as myfile: + contents = [myfile.read()] if include_filenames: contents.append(os.path.basename(string)) diff --git a/pywhat/printer.py b/pywhat/printer.py index fe56936..5d2226a 100644 --- a/pywhat/printer.py +++ b/pywhat/printer.py @@ -178,8 +178,6 @@ def print_raw(self, text: dict, text_input) -> str: if output_str.strip(): self.console.print(output_str.rstrip()) - return output_str - def _check_if_exploit_in_json(self, text: dict) -> bool: if "File Signatures" in text and text["File Signatures"]: # loops files @@ -192,7 +190,5 @@ def _check_if_exploit_in_json(self, text: dict) -> bool: if "Exploit" in value["Regex Pattern"].keys(): self.bug_bounty_mode = True - return self.bug_bounty_mode - def _check_if_directory(self, text_input): return os.path.isdir(text_input) diff --git a/scripts/get_file_sigs.py b/scripts/get_file_sigs.py index 4b7451e..bda3f46 100644 --- a/scripts/get_file_sigs.py +++ b/scripts/get_file_sigs.py @@ -31,8 +31,8 @@ def cleanhtml(raw_html): wt = wtp.parse(r.text) # prints first 3 items of json, delete [0:3] to print all. -sig_dict = {"root": wt.tables[0].data()} -to_iter = sig_dict["root"] +to_iter = {"root": wt.tables[0].data()} +to_iter = to_iter["root"] to_dump = [] populars = {"23 21"} diff --git a/tests/test_regex_identifier.py b/tests/test_regex_identifier.py index 9a153e5..41c7899 100644 --- a/tests/test_regex_identifier.py +++ b/tests/test_regex_identifier.py @@ -761,7 +761,7 @@ def test_instapayment(): _assert_match_first_item("Insta Payment Card Number", res) -def test_stackhawk(): +def test_instapayment(): res = r.check(["hawk.wz6bAoFDwcVQFCD9dofE.w2R1PWI8UTvEM4jd56XQ"]) _assert_match_first_item("StackHawk API Key", res) @@ -822,6 +822,11 @@ def test_github_refresh_token(): _assert_match_first_item("GitHub Refresh Token", res) +def test_stripe_api_key(): + res = r.check(["sk_live_26PHem9AhJZvU623DfE1x4sd"]) + _assert_match_first_item("Stripe API Key", res) + + def test_zapier_webhook(): res = r.check(["https://hooks.zapier.com/hooks/catch/1234567/f8f22dgg/"]) _assert_match_first_item("Zapier Webhook Token", res)