MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / generate_test_classes

Function generate_test_classes

test/unified_format.py:1576–1654  ·  view source on GitHub ↗

Method for generating test classes. Returns a dictionary where keys are the names of test classes and values are the test class objects.

(
    test_path,
    module=__name__,
    class_name_prefix="",
    expected_failures=[],  # noqa: B006
    bypass_test_generation_errors=False,
    **kwargs,
)

Source from the content-addressed store, hash-verified

1574
1575
1576def generate_test_classes(
1577 test_path,
1578 module=__name__,
1579 class_name_prefix="",
1580 expected_failures=[], # noqa: B006
1581 bypass_test_generation_errors=False,
1582 **kwargs,
1583):
1584 """Method for generating test classes. Returns a dictionary where keys are
1585 the names of test classes and values are the test class objects.
1586 """
1587 test_klasses = {}
1588
1589 def test_base_class_factory(test_spec):
1590 """Utility that creates the base class to use for test generation.
1591 This is needed to ensure that cls.TEST_SPEC is appropriately set when
1592 the metaclass __init__ is invoked.
1593 """
1594
1595 class SpecTestBase(with_metaclass(UnifiedSpecTestMeta)): # type: ignore
1596 TEST_SPEC = test_spec
1597 EXPECTED_FAILURES = expected_failures
1598
1599 base = SpecTestBase
1600
1601 # Add "encryption" marker if the "csfle" runOnRequirement is set.
1602 for req in test_spec.get("runOnRequirements", []):
1603 if "csfle" in req:
1604 base = pytest.mark.encryption(base)
1605
1606 return base
1607
1608 found_any = False
1609 for dirpath, _, filenames in os.walk(test_path):
1610 dirname = os.path.split(dirpath)[-1]
1611
1612 for filename in filenames:
1613 found_any = True
1614 fpath = os.path.join(dirpath, filename)
1615 with open(fpath) as scenario_stream:
1616 # Use tz_aware=False to match how CodecOptions decodes
1617 # dates.
1618 opts = json_util.JSONOptions(tz_aware=False)
1619 scenario_def = json_util.loads(scenario_stream.read(), json_options=opts)
1620
1621 test_type = os.path.splitext(filename)[0]
1622 snake_class_name = "Test{}_{}_{}".format(
1623 class_name_prefix,
1624 dirname.replace("-", "_"),
1625 test_type.replace("-", "_").replace(".", "_"),
1626 )
1627 class_name = snake_to_camel(snake_class_name)
1628
1629 try:
1630 schema_version = Version.from_string(scenario_def["schemaVersion"])
1631 mixin_class = _SCHEMA_VERSION_MAJOR_TO_MIXIN_CLASS.get(schema_version[0])
1632 if mixin_class is None:
1633 raise ValueError(

Calls 7

snake_to_camelFunction · 0.90
from_stringMethod · 0.80
test_base_class_factoryFunction · 0.70
joinMethod · 0.45
readMethod · 0.45
getMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected