Skip to content

Commit

Permalink
test_oneof_usage improved
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey Chvalyuk <[email protected]>
  • Loading branch information
grubberr committed Apr 6, 2022
1 parent ff71102 commit 6da5d8f
Showing 1 changed file with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,22 @@ def test_oneof_usage(self, actual_connector_spec: ConnectorSpecification):
for variant in variants:
assert "properties" in variant, f"Each item in the oneOf array should be a property with type object. {docs_msg}"

variant_props = [set(list(v["properties"].keys())) for v in variants]
oneof_path = '.'.join(variant_path)
variant_props = [set(v["properties"].keys()) for v in variants]
common_props = set.intersection(*variant_props)
assert common_props, "There should be at least one common property for oneOf subobjects"
assert any(
[all(["const" in var["properties"][prop] for var in variants]) for prop in common_props]
), f"Any of {common_props} properties in {'.'.join(variant_path)} has no const keyword. {docs_msg}"

for variant in variants:
for common_prop in common_props:
prop_obj = variant['properties'][common_prop]
if prop_obj.get("type") == "string" and {"const", "enum", "default"} & prop_obj.keys():
const = prop_obj["const"]
default = prop_obj["default"]
enum = prop_obj["enum"]
assert const == default, f"{const} != {default}"
assert const in enum
assert common_props, f"There should be at least one common property for {oneof_path} subobjects. {docs_msg}"

const_common_props = set()
for common_prop in common_props:
if all(["const" in variant["properties"][common_prop] for variant in variants]):
const_common_props.add(common_prop)
assert len(const_common_props) == 1, f"There should be exactly one common property with 'const' keyword for {oneof_path} subobjects. {docs_msg}"

const_common_prop = const_common_props.pop()
for n, variant in enumerate(variants):
prop_obj = variant["properties"][const_common_prop]
assert "default" not in prop_obj, f"There should not be 'default' keyword in common property {oneof_path}[{n}].{const_common_prop}. {docs_msg}"
assert "enum" not in prop_obj, f"There should not be 'enum' keyword in common property {oneof_path}[{n}].{const_common_prop}. {docs_msg}"

def test_required(self):
"""Check that connector will fail if any required field is missing"""
Expand Down

1 comment on commit 6da5d8f

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SonarQube Report

SonarQube report for Airbyte Bases Source Acceptance Test(#11704)

Measures

Name Value Name Value Name Value
Vulnerabilities 0 Duplicated Lines (%) 0.0 Code Smells 25
Lines of Code 1202 Reliability Rating A Security Rating A
Duplicated Blocks 0 Quality Gate Status OK Lines to Cover 1021
Coverage 60.5 Bugs 0 Blocker Issues 0
Critical Issues 4 Major Issues 3 Minor Issues 18

Detected Issues

Rule File Description Message
python:black_need_format (MINOR) tests/test_core.py Please run one of the commands: "black --config ./pyproject.toml <path_to_updated_folder>" or "./gradlew format" 1 code part(s) should be updated.
python:S2772 (MINOR) source_acceptance_test/conftest.py:208 "pass" should not be used needlessly Remove this unneeded "pass".
python:S3776 (CRITICAL) utils/common.py:86 Cognitive Complexity of functions should not be too high Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.
python:S3776 (CRITICAL) utils/connector_runner.py:114 Cognitive Complexity of functions should not be too high Refactor this function to reduce its Cognitive Complexity from 21 to the 15 allowed.
python:S5799 (MAJOR) utils/connector_runner.py:94 Implicit string and byte concatenations should not be confusing Merge these implicitly concatenated strings; or did you forget a comma?
python:mypy_return (MINOR) utils/common.py:70 Check that function always returns a value Missing return statement . Code line: def find_key_inside_schema(schema_item: Union[dict, list, str], key: s...
python:S5886 (MAJOR) utils/compare.py:96 Function return types should be consistent with their type hint Return a value of type "str" instead of "DictWithHashMixin" or update function "make_hashable" type hint.
python:S5886 (MAJOR) utils/compare.py:98 Function return types should be consistent with their type hint Return a value of type "str" instead of "ListWithHashMixin" or update function "make_hashable" type hint.
python:mypy_misc (MINOR) utils/compare.py:74 Miscellaneous other checks Definition of "hash" in base class "HashMixin" is incompatible with definition in base class "dict" . Code line: class DictWithHashMixin(HashMixin, dict):
python:mypy_misc (MINOR) utils/compare.py:78 Miscellaneous other checks Definition of "hash" in base class "HashMixin" is incompatible with definition in base class "list" . Code line: class ListWithHashMixin(HashMixin, list):
python:mypy_return_value (MINOR) utils/compare.py:96 Check that return value is compatible with signature Incompatible return value type (got "DictWithHashMixin", expected "str") . Code line: return DictWithHashMixin(obj)
python:mypy_return_value (MINOR) utils/compare.py:98 Check that return value is compatible with signature Incompatible return value type (got "ListWithHashMixin", expected "str") . Code line: return ListWithHashMixin(obj)
python:mypy_no_any_return (MINOR) utils/compare.py:99 Reject returning value with "Any" type if return type is not "Any" Returning Any from function declared to return "str" . Code line: return obj
python:S3776 (CRITICAL) utils/json_schema_helper.py:169 Cognitive Complexity of functions should not be too high Refactor this function to reduce its Cognitive Complexity from 21 to the 15 allowed.
python:mypy_attr_defined (MINOR) utils/asserts.py:27 Check that attribute exists Module has no attribute "parse" . Code line: pendulum.parse(value, strict=False)
python:mypy_return_value (MINOR) utils/asserts.py:32 Check that return value is compatible with signature Incompatible return value type (got "Union[Match[str], None, bool]", expected "bool") . Code line: return valid_format and valid_time
python:S3776 (CRITICAL) tests/test_core.py:414 Cognitive Complexity of functions should not be too high Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed.
python:mypy_var_annotated (MINOR) utils/asserts.py:52 Require variable annotation if type can't be inferred Need type annotation for "stream_errors" . Code line: stream_errors = defaultdict(dict)
python:mypy_attr_defined (MINOR) utils/json_schema_helper.py:42 Check that attribute exists Module has no attribute "parse" . Code line: return pendulum.parse(value)
python:mypy_no_any_return (MINOR) utils/json_schema_helper.py:48 Reject returning value with "Any" type if return type is not "Any" Returning Any from function declared to return "Mapping[str, Any]" . Code line: value = reduce(lambda data, key: data[key], path, record)
python:mypy_import (MINOR) utils/common.py:11 Require that imported module can be found or has stubs Library stubs not installed for "yaml" (or incompatible with Python 3.7) . Code line: from yaml import load
python:mypy_assignment (MINOR) utils/common.py:24 Check that assigned value is compatible with target Incompatible types in assignment (expression has type "Path", variable has type "str") . Code line: path = Path(path) / "acceptance-test-config.yml"
python:mypy_attr_defined (MINOR) utils/common.py:25 Check that attribute exists "str" has no attribute "exists" . Code line: if not path.exists():
python:mypy_attr_defined (MINOR) utils/common.py:26 Check that attribute exists "str" has no attribute "absolute" . Code line: pytest.fail(f"config file {path.absolute()} does not exist")
python:mypy_no_any_return (MINOR) utils/json_schema_helper.py:98 Reject returning value with "Any" type if return type is not "Any" Returning Any from function declared to return "Mapping[str, Any]" . Code line: return node

Coverage (60.5%)

File Coverage File Coverage
source_acceptance_test/init.py 100.0 source_acceptance_test/base.py 50.0
source_acceptance_test/config.py 91.7 source_acceptance_test/conftest.py 0.0
source_acceptance_test/plugin.py 0.0 source_acceptance_test/tests/init.py 100.0
source_acceptance_test/tests/test_core.py 62.5 source_acceptance_test/tests/test_full_refresh.py 96.2
source_acceptance_test/tests/test_incremental.py 44.9 source_acceptance_test/utils/init.py 100.0
source_acceptance_test/utils/asserts.py 94.6 source_acceptance_test/utils/common.py 75.7
source_acceptance_test/utils/compare.py 61.7 source_acceptance_test/utils/connector_runner.py 56.0
source_acceptance_test/utils/json_schema_helper.py 87.6

Please sign in to comment.