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

Commit 8d9dcdb

Browse files
committed
parse options in test
1 parent df5ddd5 commit 8d9dcdb

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Diff for: flake8_idom_hooks/flake8_plugin.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Plugin:
1414
name = __name__
1515
version = __version__
1616

17-
options: Namespace = Namespace()
17+
exhaustive_hook_deps: bool
1818

1919
@classmethod
2020
def add_options(cls, option_manager: OptionManager) -> None:
@@ -28,15 +28,13 @@ def add_options(cls, option_manager: OptionManager) -> None:
2828

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

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

3636
def run(self) -> list[tuple[int, int, str, type[Plugin]]]:
3737
return [
3838
error + (self.__class__,)
39-
for error in run_checks(
40-
self._tree, getattr(self.options, "exhaustive_hook_deps", False)
41-
)
39+
for error in run_checks(self._tree, self.exhaustive_hook_deps)
4240
]

Diff for: tests/test_flake8_idom_hooks.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import ast
22
from pathlib import Path
33

4-
from flake8_idom_hooks import run_checks
4+
from flake8.options.manager import OptionManager
5+
6+
from flake8_idom_hooks import Plugin
7+
8+
9+
options_manager = OptionManager("test", "0.0.0")
10+
Plugin.add_options(options_manager)
511

612

713
def test_flake8_idom_hooks():
@@ -19,5 +25,9 @@ def test_flake8_idom_hooks():
1925
lineno = index + 2 # use 2 since error should be on next line
2026
col_offset = len(line) - len(lstrip_line)
2127
message = line.replace("# error:", "", 1).strip()
22-
expected_errors.add((lineno, col_offset, message))
23-
assert set(run_checks(tree, exhaustive_hook_deps=True)) == expected_errors
28+
expected_errors.add((lineno, col_offset, message, Plugin))
29+
30+
options, filenames = options_manager.parse_args(["--exhaustive-hook-deps"])
31+
Plugin.parse_options(options)
32+
33+
assert set(Plugin(tree).run()) == expected_errors

0 commit comments

Comments
 (0)