Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

upgrade/fix tests #13

Merged
merged 2 commits into from
Aug 23, 2022
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
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ["3.7", "3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v2
Expand All @@ -16,6 +16,6 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install Python Dependencies
run: pip install -r requirements/ci.txt
run: pip install -r requirements/nox-deps.txt
- name: Run Tests
run: tox
run: nox -s test
6 changes: 2 additions & 4 deletions flake8_idom_hooks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from pkg_resources import (
get_distribution as _get_distribution,
DistributionNotFound as _DistributionNotFound,
)
from pkg_resources import DistributionNotFound as _DistributionNotFound
from pkg_resources import get_distribution as _get_distribution

try:
__version__: str = _get_distribution(__name__).version
Expand Down
5 changes: 2 additions & 3 deletions flake8_idom_hooks/exhaustive_deps.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import ast
from typing import Optional, Union, Set

from .utils import is_hook_def, is_component_def, ErrorVisitor, set_current
from typing import Optional, Set, Union

from .utils import ErrorVisitor, is_component_def, is_hook_def, set_current

HOOKS_WITH_DEPS = ("use_effect", "use_callback", "use_memo")

Expand Down
6 changes: 3 additions & 3 deletions flake8_idom_hooks/rules_of_hooks.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import ast
from typing import Union, Optional
from typing import Optional, Union

from .utils import (
is_hook_def,
is_component_def,
ErrorVisitor,
is_component_def,
is_hook_def,
is_hook_function_name,
set_current,
)
Expand Down
2 changes: 1 addition & 1 deletion flake8_idom_hooks/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import ast

from .utils import ErrorVisitor
from .exhaustive_deps import ExhaustiveDepsVisitor
from .rules_of_hooks import RulesOfHooksVisitor
from .utils import ErrorVisitor


def run_checks(
Expand Down
2 changes: 1 addition & 1 deletion flake8_idom_hooks/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ast
from contextlib import contextmanager
from typing import List, Tuple, Iterator, Any
from typing import Any, Iterator, List, Tuple


@contextmanager
Expand Down
45 changes: 45 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from pathlib import Path

from nox import Session, session

ROOT = Path(".")
REQUIREMENTS_DIR = ROOT / "requirements"


@session
def test(session: Session) -> None:
session.notify("test_style")
session.notify("test_types")
session.notify("test_coverage")
session.notify("test_suite")


@session
def test_style(session: Session) -> None:
install_requirements(session, "style")
session.run("isort", "--check", ".")
session.run("flake8", ".")


@session
def test_types(session: Session) -> None:
install_requirements(session, "types")
session.run("mypy", "--strict", "flake8_idom_hooks")


@session
def test_suite(session: Session) -> None:
install_requirements(session, "test-env")
session.install(".")
session.run("pytest", "tests")


@session
def test_coverage(session: Session) -> None:
install_requirements(session, "test-env")
session.install("-e", ".")
session.run("pytest", "tests", "--cov=flake8_idom_hooks", "--cov-report=term")


def install_requirements(session: Session, name: str) -> None:
session.install("-r", str(REQUIREMENTS_DIR / f"{name}.txt"))
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"

[tool.isort]
profile = "black"
9 changes: 5 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-r requirements/dev.txt
-r requirements/prod.txt
-r requirements/test.txt
-r requirements/lint.txt
-r requirements/nox-deps.txt
-r requirements/pkg-deps.txt
-r requirements/style.txt
-r requirements/test-env.txt
-r requirements/types.txt
3 changes: 0 additions & 3 deletions requirements/ci.txt

This file was deleted.

2 changes: 0 additions & 2 deletions requirements/dev.txt

This file was deleted.

1 change: 1 addition & 0 deletions requirements/nox-deps.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nox
1 change: 1 addition & 0 deletions requirements/prod.txt → requirements/pkg-deps.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
flake8 >=3.7
black
4 changes: 4 additions & 0 deletions requirements/style.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
flake8 >=3.7
black
isort
flake8-tidy-imports
File renamed without changes.
2 changes: 0 additions & 2 deletions requirements/lint.txt → requirements/types.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
flake8 >=3.7
black
mypy
types-setuptools
9 changes: 4 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ warn_unused_ignores = True
[flake8]
ignore = E203, E266, E501, W503, F811, N802
max-line-length = 88
max-complexity = 18
exclude =
.eggs/*
.tox/*
extend-exclude =
.nox
venv
.venv
tests/hook_usage_test_cases.py

[coverage:report]
Expand All @@ -26,4 +26,3 @@ exclude_lines =
[tool:pytest]
testpaths = tests
xfail_strict = True
addopts = --cov=flake8_idom_hooks --cov-report term
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

import setuptools

# the name of the project
Expand Down Expand Up @@ -46,7 +47,7 @@


requirements = []
with open(os.path.join(here, "requirements", "prod.txt"), "r") as f:
with open(os.path.join(here, "requirements", "pkg-deps.txt"), "r") as f:
for line in map(str.strip, f):
if not line.startswith("#"):
requirements.append(line)
Expand Down
21 changes: 13 additions & 8 deletions tests/test_flake8_idom_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

from flake8.options.manager import OptionManager

from flake8_idom_hooks import Plugin
import flake8_idom_hooks


options_manager = OptionManager("test", "0.0.0")
Plugin.add_options(options_manager)
options_manager = OptionManager(
version="0.0.0",
plugin_versions=flake8_idom_hooks.__version__,
parents=[],
)
flake8_idom_hooks.Plugin.add_options(options_manager)


def test_flake8_idom_hooks():
Expand All @@ -25,9 +28,11 @@ def test_flake8_idom_hooks():
lineno = index + 2 # use 2 since error should be on next line
col_offset = len(line) - len(lstrip_line)
message = line.replace("# error:", "", 1).strip()
expected_errors.add((lineno, col_offset, message, Plugin))
expected_errors.add(
(lineno, col_offset, message, flake8_idom_hooks.Plugin)
)

options, filenames = options_manager.parse_args(["--exhaustive-hook-deps"])
Plugin.parse_options(options)
options = options_manager.parse_args(["--exhaustive-hook-deps"])
flake8_idom_hooks.Plugin.parse_options(options)

assert set(Plugin(tree).run()) == expected_errors
assert set(flake8_idom_hooks.Plugin(tree).run()) == expected_errors