Repository navigation
test(python): one assertion per line and one raising call per pytest.raises - #2148
Merged
Merged
Conversation
…raises Splits the composite assert-and chains in the element-properties, instance and unnamed-children tests into one assert per operand, and builds the Symbol and Instance under test before the pytest.raises block so only the call expected to raise sits inside it. Co-Authored-By: jason.han <hanhuijun@gmail.com>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
SonarCloud's analysis of
developreports 14 open findings in the Python client tests: 12 composite assertions (python:S9073, "Split this composite assertion into separate assertions") and 2pytest.raisesblocks holding more than one call that could raise (python:S5778, "Refactor this exception test to have only one invocation possibly throwing an exception"). This fixes each at the source; nothing is suppressed and no expectation changes.python:S9073 — composite
assert a and bsplit into one assert per operand (every operand stays asserted, in the same order, so a failure now names the operand that failed instead of the whole chain):client/python/tests/test_element_properties.pytest_a_response_decodes_as_a_mapping_of_properties: thelen(read) == 4 and "isAbstract" in read and "name" not in readchain, thedefining_class/many/derivedchain, theisAbstractvalue/many chain and theownedSubclassificationsupported/falsy chain (4 findings)test_every_value_arm_decodes_to_its_python_value: theidentity == … and str(identity) == …chaintest_the_connection_sends_the_element_and_the_names: themodel_hash/element_idchain and theisinstance … and qualified_namechaintest_an_unnamed_connector_is_read_by_position_and_walked_by_form_id: themetaclass … and qualified_name == ""chaintest_why_a_property_has_no_answer_is_said: thesupported and len(values) == 1chaintest_every_inherited_membership_and_its_member_read_back: the per-membershipid … and metaclasschain and the finallen(unnamed) >= 18 and … in unnamed and … in unnamedchainclient/python/tests/test_unnamed_children.pytest_children_list_every_member_the_query_reports: theanonymous is not None and kind == … and name == ""chain (theis not Noneassert still runs first, so the attribute reads are guarded exactly as before)python:S5778 — only the call under test inside
pytest.raises(the construction moves to a local above the block, so aValueError/RuntimeErrorfrom the constructor would now fail the test instead of satisfying it):client/python/tests/test_element_properties.pytest_the_model_and_the_symbol_reach_the_connection:Symbol(sysml_pb2.SymbolInfo(id="EP::Pair"), None, "hash1")is built asunconnected; thewith pytest.raises(ValueError)block holds onlyunconnected.properties()client/python/tests/test_instance.pytest_paths_needs_the_connection:Instance(vehicle, graph)is built asroot; thewith pytest.raises(RuntimeError, match="connection")block holds onlyroot.paths()Test-only change; no production code, documentation or changelog entry is affected.
How it was verified
make build-grpc, thencd client/python && OPENSYSML_REQUIRE_SERVICE=1 pytest tests/ -qagainst abin/sysml-grpc -port 50051started as the CI job does: 1780 passed, 5 skipped (the three touched files: 39 passed, 0 skipped, so the service-backed@pytest.mark.integrationtests ran rather than skipped)go build ./... && go vet ./... && test -z "$(gofmt -l .)" && make lintclean;go test -count=1 ./tests/hygieneandmake test-quick SHARDS="grpc"pass (no Go file changes)python3 scripts/check-doc-ids.pyandpython3 scripts/changelog.py checkcleangit merge-tree --write-tree) against the open PRs that also edittest_element_properties.py, feat(grpc): GetElementProperties reads the symbol-backed metamodel structure #2042 and fix(grpc): GetElementProperties reads a model one document at a time #2052: no conflict in anyclient/python/testsfile; the conflicts those merges report are exactly the ones each PR already has againstorigin/developChecklist
make testandmake lintpass locallychanges/unreleased/<slug>.<section>.md, not as an edit toCHANGELOG.md— not applicable, test-onlymake docs-countsrun if a gate count moved — no gate count movedF4,K5) in the body, docs, or changelogLink to Devin session: https://nasa-jpl-demo.devinenterprise.com/sessions/c85391e5049643fa9cc5a7d381fd85d8
Open in Devin Desktop: https://nasa-jpl-demo.devinenterprise.com/desktop/session/c85391e5049643fa9cc5a7d381fd85d8?variant=devin
Requested by: @HuiJun
🟢 Devin Review found nothing to fix · View findings