def test_build_hierarchy_with_useless_wildcards():
    hierarchy = build_hierarchy(classes, {})
    assert_all_in_unknown_layer_and_original_package(hierarchy)

    hierarchy = build_hierarchy(classes, {'lib': []})
    assert_all_in_unknown_layer_and_original_package(hierarchy)
    hierarchy = build_hierarchy(classes, {'lib': [{}]})
    assert_all_in_unknown_layer_and_original_package(hierarchy)

    hierarchy = build_hierarchy(
        classes, {
            'lib': [{
                "module": "not.exist"
            }, {
                "module": "a",
                "package": "not.exist"
            }, {
                "module": "a",
                "package": "a.package",
                "class": "NotExist"
            }, {
                "module": "*not.exist"
            }, {
                "module": "a",
                "package": "*not.exist"
            }, {
                "module": "a",
                "package": "a.package",
                "class": "*NotExist"
            }]
        })

    assert_all_in_unknown_layer_and_original_package(hierarchy)

    hierarchy = build_hierarchy(
        classes, {
            'lib': [{
                "path": ":not.exist"
            }, {
                "path": ":a:not.exist"
            }, {
                "path": ":a:a.package:NotExist"
            }, {
                "path": ":*not.exist"
            }, {
                "path": ":a:*not.exist"
            }, {
                "path": ":a:a.package:*NotExist"
            }]
        })

    assert_all_in_unknown_layer_and_original_package(hierarchy)
Exemple #2
0
def main() -> None:
    args = _init_argparse().parse_args()

    if args.verbose:
        logging.basicConfig(level=logging.DEBUG)

    design = load_design(args.design, generate_example=True)

    full_hierarchy = build_hierarchy(_input_parsers[args.parser](args.index),
                                     design.layers)

    hierarchy = Hierarchy()
    for f in args.filters:
        hierarchy = filter_hierarchy(full_hierarchy, f, hierarchy)

        for cls in hierarchy.classes:
            for d in cls.dependencies:
                if d.is_production:
                    _add_to(
                        full_hierarchy[d.layer][d.module][d.package][d.name],
                        hierarchy)

    find_smells(hierarchy, design.smells)

    timestamp = time.strftime("%Y%m%d-%H-%M", time.localtime())
    for format_key in args.outputs:
        _output_formats[format_key](os.path.join("report-" + timestamp,
                                                 format_key), hierarchy)
def test_build_hierarchy_with_wrong_wildcards(capsys):
    hierarchy = build_hierarchy(classes,
                                {'lib': [{
                                    "no_module_key": "*not.exist"
                                }]})
    out, _ = capsys.readouterr()
    assert out == "Warning: missing module {'no_module_key': '*not.exist'}\n"
    assert_all_in_unknown_layer_and_original_package(hierarchy)

    hierarchy = build_hierarchy(classes,
                                {'lib': [{
                                    "no_module_key": "*not.exist"
                                }]})
    out, _ = capsys.readouterr()
    assert out == "Warning: missing module {'no_module_key': '*not.exist'}\n"
    assert_all_in_unknown_layer_and_original_package(hierarchy)

    hierarchy = build_hierarchy(
        classes,
        {'lib': [{
            "module_must_be_specified": "a",
            "package": "*not.exist"
        }]})
    out, _ = capsys.readouterr()
    assert out == "Warning: missing module {'module_must_be_specified': 'a', 'package': '*not.exist'}\n"
    assert_all_in_unknown_layer_and_original_package(hierarchy)

    hierarchy = build_hierarchy(
        classes, {
            'lib': [{
                "module": "a",
                "package_must_be_specified": "a.package",
                "class": "*NotExist"
            }]
        })
    out, _ = capsys.readouterr()
    assert out == "Warning: missing package {'module': 'a', " + \
        "'package_must_be_specified': 'a.package', 'class': '*NotExist'}\n"
    assert_all_in_unknown_layer_and_original_package(hierarchy)

    hierarchy = build_hierarchy(
        classes, {
            'lib': [{
                "module_must_be_specified": "a",
                "package": "a.package",
                "class": "*NotExist"
            }]
        })
    out, _ = capsys.readouterr()
    assert out == "Warning: missing module {'module_must_be_specified': 'a', " +\
        "'package': 'a.package', 'class': '*NotExist'}\n"
    assert_all_in_unknown_layer_and_original_package(hierarchy)

    hierarchy = build_hierarchy(
        classes,
        {'lib': [{}]},
    )
    out, _ = capsys.readouterr()
    assert out == 'Warning: missing module {}\n'
    assert_all_in_unknown_layer_and_original_package(hierarchy)
Exemple #4
0
def main() -> None:
    design = load_design("design.ini")

    full_hierarchy = build_hierarchy(input_idea.read_file("index.xml"),
                                     design.layers)
    hierarchy = filter_hierarchy(full_hierarchy,
                                 "unknown:app:com.fastaccess:A*", Hierarchy())

    find_smells(hierarchy, design.smells)

    dt = time.strftime("report-%Y%m%d-%H-%M", time.localtime())
    output_md.write_files(os.path.join(dt, 'md'), hierarchy)
    output_uml.write_files(os.path.join(dt, 'uml'), hierarchy)
def test_build_hierarchy_with_specified_pacakge():
    hierarchy = build_hierarchy(classes, {})

    assert hierarchy[LAYER_UNKNOWN]['b'][
        'b.package.subpackage1'].package == 'b.package.subpackage1'
    assert hierarchy[LAYER_UNKNOWN]['b']['b.package.subpackage1'][
        'Class2'].name == 'Class2'
    assert hierarchy[LAYER_UNKNOWN]['b']['b.package.subpackage1'][
        'Class2'].package == 'b.package.subpackage1'
    assert hierarchy[LAYER_UNKNOWN]['b']['b.package.subpackage1'][
        'Class2'].full_name == 'b.package.subpackage1.Class2'
    assert hierarchy[LAYER_UNKNOWN]['b']['b.package.subpackage2'][
        'Class3'].name == 'Class3'
    assert hierarchy[LAYER_UNKNOWN]['b']['b.package.subpackage2'][
        'Class3'].package == 'b.package.subpackage2'
    assert hierarchy[LAYER_UNKNOWN]['b']['b.package.subpackage2'][
        'Class3'].full_name == 'b.package.subpackage2.Class3'
Exemple #6
0
def hierarchy():
    return build_hierarchy([http_cls, app_cls, log_cls, page_cls, unknown_cls],
                           layers)