Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Fix nox tests" #180

Merged
merged 1 commit into from
Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
45 changes: 35 additions & 10 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down Expand Up @@ -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)
107 changes: 1 addition & 106 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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"
4 changes: 2 additions & 2 deletions pywhat/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
2 changes: 1 addition & 1 deletion pywhat/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
try:
import orjson as json
except ImportError:
import json # type: ignore
import json


class AvailableTags:
Expand Down
8 changes: 4 additions & 4 deletions pywhat/identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(
self,
*,
dist: Optional[Distribution] = None,
key=Keys.NONE,
key: Callable = Keys.NONE,
reverse=False,
boundaryless: Optional[Filter] = None,
):
Expand Down Expand Up @@ -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):
Expand All @@ -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))
Expand Down
4 changes: 0 additions & 4 deletions pywhat/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
4 changes: 2 additions & 2 deletions scripts/get_file_sigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
7 changes: 6 additions & 1 deletion tests/test_regex_identifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down