Exemplo n.º 1
0
def test_discover_classes():
    # Note: package_a basically just contains a module base with:
    # class Base(object): pass
    ret = discover(
        testing.testing_package.package_a,
        lambda cls: True,
    )
    assert ret == {Base}
Exemplo n.º 2
0
def test_discover_excludes_imported_classes():
    # Note: package_b has a module derived which
    # imports Base from package_a.base and has
    # class Base2(Base): pass
    ret = discover(
        testing.testing_package.package_b,
        lambda cls: True,
    )
    assert Base not in ret
Exemplo n.º 3
0
def test_returns_metrics_defined_in_tests_when_specified():
    import tests
    metrics_in_tests = discover(tests, is_metric_cls)
    if not metrics_in_tests:
        raise AssertionError(
            'Expected at least one metric in `tests` but found none', )

    assert (metrics_in_tests == get_metric_parsers((tests, ),
                                                   include_defaults=False))
Exemplo n.º 4
0
def get_metric_parsers(metric_packages=tuple(), include_defaults=True):
    """Gets all of the metric parsers.

    Args:
        metric_packages - Defaults to no extra packages. An iterable of
            metric containing packages.  A metric inherits DiffParserBase
            and does not have __metric__ = False
            A metric package must be imported using import a.b.c
        include_defaults - Whether to include the generic metric parsers
    """
    metric_parsers = set()

    if include_defaults:
        import git_code_debt.metrics
        metric_parsers.update(discover(git_code_debt.metrics, is_metric_cls))

    for metric_package in metric_packages:
        metric_parsers.update(discover(metric_package, is_metric_cls))
    return metric_parsers
Exemplo n.º 5
0
def get_metric_parsers(metric_packages=tuple(), include_defaults=True):
    """Gets all of the metric parsers.

    Args:
        metric_packages - Defaults to no extra packages. An iterable of
            metric containing packages.  A metric inherits DiffParserBase
            and does not have __metric__ = False
            A metric package must be imported using import a.b.c
        include_defaults - Whether to include the generic metric parsers
    """
    metric_parsers = set()

    if include_defaults:
        import git_code_debt.metrics
        metric_parsers.update(discover(git_code_debt.metrics, is_metric_cls))

    for metric_package in metric_packages:
        metric_parsers.update(discover(metric_package, is_metric_cls))
    return metric_parsers
def test_returns_metrics_defined_in_tests_when_specified():
    import tests
    metrics_in_tests = discover(tests, is_metric_cls)
    if not metrics_in_tests:
        raise AssertionError(
            'Expected at least one metric in `tests` but found none'
        )

    assert (
        metrics_in_tests ==
        get_metric_parsers((tests,), include_defaults=False)
    )