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

Commit

Permalink
parse options in test
Browse files Browse the repository at this point in the history
  • Loading branch information
rmorshea committed Nov 3, 2021
1 parent df5ddd5 commit 8d9dcdb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
8 changes: 3 additions & 5 deletions flake8_idom_hooks/flake8_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Plugin:
name = __name__
version = __version__

options: Namespace = Namespace()
exhaustive_hook_deps: bool

@classmethod
def add_options(cls, option_manager: OptionManager) -> None:
Expand All @@ -28,15 +28,13 @@ def add_options(cls, option_manager: OptionManager) -> None:

@classmethod
def parse_options(cls, options: Namespace) -> None:
cls.options = options
cls.exhaustive_hook_deps = getattr(options, "exhaustive_hook_deps", False)

def __init__(self, tree: ast.Module) -> None:
self._tree = tree

def run(self) -> list[tuple[int, int, str, type[Plugin]]]:
return [
error + (self.__class__,)
for error in run_checks(
self._tree, getattr(self.options, "exhaustive_hook_deps", False)
)
for error in run_checks(self._tree, self.exhaustive_hook_deps)
]
16 changes: 13 additions & 3 deletions tests/test_flake8_idom_hooks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import ast
from pathlib import Path

from flake8_idom_hooks import run_checks
from flake8.options.manager import OptionManager

from flake8_idom_hooks import Plugin


options_manager = OptionManager("test", "0.0.0")
Plugin.add_options(options_manager)


def test_flake8_idom_hooks():
Expand All @@ -19,5 +25,9 @@ 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))
assert set(run_checks(tree, exhaustive_hook_deps=True)) == expected_errors
expected_errors.add((lineno, col_offset, message, Plugin))

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

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

0 comments on commit 8d9dcdb

Please sign in to comment.