Skip to content

Commit

Permalink
Add auto case name based on function name (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytrostriletskyi authored Sep 16, 2024
1 parent 03fa256 commit 287da21
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .project-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.8
0.0.9
1 change: 1 addition & 0 deletions intentions/render/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class TestCase:
file_path: str
class_name: str
class_code_line: int
case_name: str
function_name: str
function_code_line: int
intentions: list[TestCaseIntention]
6 changes: 5 additions & 1 deletion intentions/render/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
)
from intentions.render.encoders import JsonEncoderWithEnumSupport
from intentions.render.enums import Intention
from intentions.utils import is_test_function
from intentions.utils import (
convert_test_function_name_to_case_name,
is_test_function,
)


def collect_test_files(directory: str) -> list[Path]:
Expand Down Expand Up @@ -99,6 +102,7 @@ def collect_test_cases(storage: dict, file: Path) -> None:
storage[describe.domain][describe.component][describe.layer] = []

test_function = TestCase(
case_name=convert_test_function_name_to_case_name(test_function_name=function_node.name),
function_name=function_node.name,
function_code_line=function_node.lineno,
intentions=test_case_intentions,
Expand Down
8 changes: 8 additions & 0 deletions intentions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ def is_test_function(name: str) -> bool:
return True

return False


def convert_test_function_name_to_case_name(test_function_name: str) -> str:
test_function_name = test_function_name.replace('test_', '')
test_function_name = test_function_name.replace('_', ' ')
test_function_name = test_function_name.capitalize()

return test_function_name
6 changes: 6 additions & 0 deletions tests/render/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def test_create_intentions_json_accounts_service(self, remove_intentions_json) -
'file_path': 'fixtures/test_file.py',
'class_name': 'TestAccountsService',
'class_code_line': 10,
'case_name': 'Transfer money with insufficient balance',
'function_name': 'test_transfer_money_with_insufficient_balance',
'function_code_line': 12,
'intentions': [
Expand Down Expand Up @@ -71,6 +72,7 @@ def test_create_intentions_json_accounts_service(self, remove_intentions_json) -
'file_path': 'fixtures/test_file.py',
'class_name': 'TestAccountsService',
'class_code_line': 10,
'case_name': 'Transfer money with sufficient balance',
'function_name': 'test_transfer_money_with_sufficient_balance',
'function_code_line': 22,
'intentions': [
Expand Down Expand Up @@ -99,6 +101,7 @@ def test_create_intentions_json_accounts_service(self, remove_intentions_json) -
'file_path': 'fixtures/test_file.py',
'class_name': None,
'class_code_line': None,
'case_name': 'Transfer money to non existing receiver account',
'function_name': 'test_transfer_money_to_non_existing_receiver_account',
'function_code_line': 34,
'intentions': [
Expand Down Expand Up @@ -137,6 +140,7 @@ def test_create_intentions_json_investments_service(self, remove_intentions_json
'file_path': 'fixtures/test_file.py',
'class_name': 'TestInvestmentsService',
'class_code_line': 46,
'case_name': 'Invest money into stocks',
'function_name': 'test_invest_money_into_stocks',
'function_code_line': 48,
'intentions': [
Expand All @@ -160,6 +164,7 @@ def test_create_intentions_json_investments_service(self, remove_intentions_json
'file_path': 'fixtures/test_file.py',
'class_name': 'TestInvestmentsService',
'class_code_line': 46,
'case_name': 'Invest money into crypto',
'function_name': 'test_invest_money_into_crypto',
'function_code_line': 55,
'intentions': [
Expand All @@ -183,6 +188,7 @@ def test_create_intentions_json_investments_service(self, remove_intentions_json
'file_path': 'fixtures/test_file.py',
'class_name': None,
'class_code_line': None,
'case_name': 'Invest into non existing stocks',
'function_name': 'test_invest_into_non_existing_stocks',
'function_code_line': 64,
'intentions': [
Expand Down

0 comments on commit 287da21

Please sign in to comment.