Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #4

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 0 additions & 58 deletions .github/workflows/main.yaml

This file was deleted.

64 changes: 0 additions & 64 deletions .github/workflows/pull_request.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .project-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.7
0.0.8
10 changes: 5 additions & 5 deletions fixtures/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
)


@describe(object='Accounts Service', domain='accounts')
@describe(domain='accounts', component='accounts', layer='service')
class TestAccountsService:

def test_transfer_money_with_insufficient_balance(self):
Expand All @@ -30,7 +30,7 @@ def test_transfer_money_with_sufficient_balance(self):
pass


@describe(object='Accounts Service', domain='accounts')
@describe(domain='accounts', component='accounts', layer='service')
def test_transfer_money_to_non_existing_receiver_account():
with when('Receiver account does not exist'):
pass
Expand All @@ -42,7 +42,7 @@ def test_transfer_money_to_non_existing_receiver_account():
pass


@describe(object='Investments Service', domain='investments')
@describe(domain='investments', component='investments', layer='service')
class TestInvestmentsService:

def test_invest_money_into_stocks(self):
Expand All @@ -60,7 +60,7 @@ def test_invest_money_into_crypto(self):
pass


@describe(object='Investments Service', domain='investments')
@describe(domain='investments', component='investments', layer='service')
def test_invest_into_non_existing_stocks():
with when('Stock to buy does not exist'):
pass
Expand All @@ -83,6 +83,6 @@ def test_invest_into_non_existing_crypto():
pass


@describe(object='Investments Service', domain='investments')
@describe(domain='investments', component='investments', layer='service')
def test_sum():
assert 4 == 2 + 2
2 changes: 1 addition & 1 deletion intentions/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class expect(AbstractIntention):
"""


def describe(object: str, domain: str) -> Callable[[Callable[..., T]], Callable[..., T]]: # noqa: ARG001
def describe(domain: str, component: str, layer: str) -> Callable[[Callable[..., T]], Callable[..., T]]: # noqa: ARG001
def decorator(func: [..., T]) -> Callable[..., T]:
def wrapper(*args: tuple[Any, ...], **kwargs: dict[str, Any]) -> T:
result = func(*args, **kwargs)
Expand Down
10 changes: 6 additions & 4 deletions intentions/render/ast_.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ def get_describe(self, decorators: [ast.Call]) -> Optional[Describe]:
if decorator.func.id != 'describe':
continue

assert decorator.keywords[0].arg == 'object' # noqa: S101
assert decorator.keywords[1].arg == 'domain' # noqa: S101
assert decorator.keywords[0].arg == 'domain' # noqa: S101
assert decorator.keywords[1].arg == 'component' # noqa: S101
assert decorator.keywords[2].arg == 'layer' # noqa: S101

return Describe(
object=decorator.keywords[0].value.value,
domain=decorator.keywords[1].value.value,
domain=decorator.keywords[0].value.value,
component=decorator.keywords[1].value.value,
layer=decorator.keywords[2].value.value,
)

return None
3 changes: 2 additions & 1 deletion intentions/render/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

@dataclass
class Describe:
object: str # noqa: A003
domain: str
component: str
layer: str


@dataclass
Expand Down
9 changes: 6 additions & 3 deletions intentions/render/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ def collect_test_cases(storage: dict, file: Path) -> None:
if describe.domain not in storage:
storage[describe.domain] = {}

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

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

test_function = TestCase(
function_name=function_node.name,
Expand All @@ -105,7 +108,7 @@ def collect_test_cases(storage: dict, file: Path) -> None:
)

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


def create_intentions_json(directory: str) -> None:
Expand Down
18 changes: 9 additions & 9 deletions tests/render/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def test_create_intentions_json(self, remove_intentions_json) -> None:
assert intentions_json['investments'] is not None

with expect('Each intentions JSON domain consist of its objects'):
assert intentions_json['accounts']['Accounts Service']
assert intentions_json['investments']['Investments Service']
assert intentions_json['accounts']['accounts']['service']
assert intentions_json['investments']['investments']['service']

def test_create_intentions_json_accounts_service(self, remove_intentions_json) -> None:
with when('Tests folder with tests for accounts service exist'):
Expand Down Expand Up @@ -64,7 +64,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']

with expect('Test transfer money with sufficient balance test case is in accounts service test cases'):
expected_test_case = {
Expand Down Expand Up @@ -92,7 +92,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']

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 @@ -120,7 +120,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']

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 @@ -153,7 +153,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']

with expect('Invest money into crypto test case is in investments service test cases'):
expected_test_case = {
Expand All @@ -176,7 +176,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']

with expect('Invest money into non-existing stocks test case is in investments service test cases'):
expected_test_case = {
Expand Down Expand Up @@ -204,7 +204,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']

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 @@ -226,4 +226,4 @@ def test_create_intentions_json_ignore_test_cases_without_intentions(self, remov
'intentions': [],
}

assert expected_test_case not in intentions_json['investments']['Investments Service']
assert expected_test_case not in intentions_json['investments']['investments']['service']
Loading