Skip to content

Commit

Permalink
Add case name as a nested key (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytrostriletskyi authored Sep 20, 2024
1 parent 287da21 commit eed1a12
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .project-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.9
0.0.10
14 changes: 12 additions & 2 deletions intentions/render/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def collect_test_cases(storage: dict, file: Path) -> None:
continue

test_case_intentions = []
test_case_case_description = None

for node in function_node.body:
if not isinstance(node, ast.With):
Expand All @@ -63,6 +64,9 @@ def collect_test_cases(storage: dict, file: Path) -> None:
with_node_item_code_line = with_node_item.context_expr.args[0].lineno
with_node_item_description = with_node_item.context_expr.args[0].value

if with_node_item_name == 'case':
test_case_case_description = with_node_item_description

test_sase_intention = TestCaseIntention(
type=Intention(with_node_item_name),
code_line=with_node_item_code_line,
Expand Down Expand Up @@ -99,7 +103,10 @@ def collect_test_cases(storage: dict, file: Path) -> None:
storage[describe.domain][describe.component] = {}

if describe.layer not in storage[describe.domain][describe.component]:
storage[describe.domain][describe.component][describe.layer] = []
storage[describe.domain][describe.component][describe.layer] = {}

if test_case_case_description not in storage[describe.domain][describe.component][describe.layer]:
storage[describe.domain][describe.component][describe.layer][test_case_case_description] = []

test_function = TestCase(
case_name=convert_test_function_name_to_case_name(test_function_name=function_node.name),
Expand All @@ -112,7 +119,10 @@ def collect_test_cases(storage: dict, file: Path) -> None:
)

test_case_as_dict = asdict(test_function)
storage[describe.domain][describe.component][describe.layer].append(test_case_as_dict)

storage[describe.domain][describe.component][describe.layer][test_case_case_description].append(
test_case_as_dict,
)


def create_intentions_json(directory: str) -> None:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ignore = [
"PTH109",
"PERF402",
"ANN101",
"PLR0915",
]

[tool.ruff.per-file-ignores]
Expand Down
15 changes: 8 additions & 7 deletions tests/render/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_create_intentions_json_accounts_service(self, remove_intentions_json) -
]
}

assert expected_test_case in intentions_json['accounts']['accounts']['service']
assert expected_test_case in intentions_json['accounts']['accounts']['service']['Transfer money from one sender to receiver']

with expect('Test transfer money with sufficient balance test case is in accounts service test cases'):
expected_test_case = {
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_create_intentions_json_accounts_service(self, remove_intentions_json) -
]
}

assert expected_test_case in intentions_json['accounts']['accounts']['service']
assert expected_test_case in intentions_json['accounts']['accounts']['service']['Transfer money from one sender to receiver']

with expect('Test transfer money to non existing receiver account test case is in accounts service test cases'):
expected_test_case = {
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_create_intentions_json_accounts_service(self, remove_intentions_json) -
]
}

assert expected_test_case in intentions_json['accounts']['accounts']['service']
assert expected_test_case in intentions_json['accounts']['accounts']['service']['Transfer money from one sender to receiver']

def test_create_intentions_json_investments_service(self, remove_intentions_json) -> None:
with when('Tests folder with tests for investments service exist'):
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_create_intentions_json_investments_service(self, remove_intentions_json
]
}

assert expected_test_case in intentions_json['investments']['investments']['service']
assert expected_test_case in intentions_json['investments']['investments']['service']['Invest money into stocks']

with expect('Invest money into crypto test case is in investments service test cases'):
expected_test_case = {
Expand All @@ -181,7 +181,7 @@ def test_create_intentions_json_investments_service(self, remove_intentions_json
]
}

assert expected_test_case in intentions_json['investments']['investments']['service']
assert expected_test_case in intentions_json['investments']['investments']['service']['Invest money into crypto']

with expect('Invest money into non-existing stocks test case is in investments service test cases'):
expected_test_case = {
Expand Down Expand Up @@ -210,7 +210,7 @@ def test_create_intentions_json_investments_service(self, remove_intentions_json
]
}

assert expected_test_case in intentions_json['investments']['investments']['service']
assert expected_test_case in intentions_json['investments']['investments']['service']['Invest money into stocks']

def test_create_intentions_json_ignore_test_cases_without_intentions(self, remove_intentions_json) -> None:
with when('Tests folder with described test cases without intentions'):
Expand All @@ -232,4 +232,5 @@ def test_create_intentions_json_ignore_test_cases_without_intentions(self, remov
'intentions': [],
}

assert expected_test_case not in intentions_json['investments']['investments']['service']
for test_case in intentions_json['investments']['investments']['service'].values():
assert expected_test_case not in test_case

0 comments on commit eed1a12

Please sign in to comment.