diff --git a/src/flake8_aaa/block.py b/src/flake8_aaa/block.py index ce1a73e..4e7b1a1 100644 --- a/src/flake8_aaa/block.py +++ b/src/flake8_aaa/block.py @@ -2,7 +2,7 @@ from typing import Iterable, List, Tuple, Type, TypeVar from .exceptions import EmptyBlock -from .helpers import add_node_parents, filter_arrange_nodes, filter_assert_nodes, get_first_token, get_last_token +from .helpers import filter_arrange_nodes, filter_assert_nodes, get_first_token, get_last_token from .types import LineType _Block = TypeVar('_Block', bound='Block') @@ -26,17 +26,11 @@ def __init__(self, nodes: Iterable[ast.AST], lt: LineType) -> None: self.line_type = lt @classmethod - def build_act(cls: Type[_Block], node: ast.stmt, test_func_node: ast.FunctionDef) -> _Block: + def build_act(cls: Type[_Block], node: ast.stmt) -> _Block: """ - Act block is a single node - either the act node itself, or the node - that wraps the act node. + Act block is a single node. """ - add_node_parents(test_func_node) - # Walk up the parent nodes of the parent node to find test's definition. - act_block_node = node - while act_block_node.parent != test_func_node: # type: ignore - act_block_node = act_block_node.parent # type: ignore - return cls([act_block_node], LineType.act) + return cls([node], LineType.act) @classmethod def build_arrange(cls: Type[_Block], nodes: List[ast.stmt], max_line_number: int) -> _Block: diff --git a/src/flake8_aaa/function.py b/src/flake8_aaa/function.py index 34c99af..cd373eb 100644 --- a/src/flake8_aaa/function.py +++ b/src/flake8_aaa/function.py @@ -78,7 +78,7 @@ def check_all(self) -> Generator[AAAError, None, None]: # ACT # Load act block and kick out when none is found self.act_node = self.load_act_node() - self.act_block = Block.build_act(self.act_node.node, self.node) + self.act_block = Block.build_act(self.act_node.node) act_block_first_line_no, act_block_last_line_no = self.act_block.get_span(0) # ARRANGE self.arrange_block = Block.build_arrange(self.node.body, act_block_first_line_no) diff --git a/tests/block/test_build_act.py b/tests/block/test_build_act.py index 8fb743c..409fddf 100644 --- a/tests/block/test_build_act.py +++ b/tests/block/test_build_act.py @@ -15,10 +15,13 @@ def test(): ] ) def test(first_node_with_tokens): + """ + `pytest.raises()` with statement is the Act node. + """ with_mock_node = first_node_with_tokens.body[0] with_pytest_node = with_mock_node.body[0] - result = Block.build_act(with_pytest_node, first_node_with_tokens) + result = Block.build_act(with_pytest_node) - assert result.nodes == (with_mock_node, ) + assert result.nodes == (with_pytest_node, ) assert result.line_type == LineType.act