Beispiel #1
0
def test_remove_complex_package_logic_filtered():
    tree = ast.parse(complex_package_logic)
    spec = Spec("has-many-metadata-attributes")
    tree = ph.RemoveDirectives(spec).visit(tree)
    unparsed = unparse(tree, py_ver_consistent=True)

    assert unparsed == complex_package_logic_filtered
Beispiel #2
0
def test_remove_spack_attributes():
    tree = ast.parse(many_attributes)
    spec = Spec("has-many-metadata-attributes")
    tree = ph.RemoveDirectives(spec).visit(tree)
    unparsed = unparse(tree, py_ver_consistent=True)

    assert unparsed == many_attributes_canonical
Beispiel #3
0
def test_remove_all_directives():
    """Ensure all directives are removed from packages before hashing."""
    for name in spack.directives.directive_names:
        assert name in many_directives

    tree = ast.parse(many_directives)
    spec = Spec("has-many-directives")
    tree = ph.RemoveDirectives(spec).visit(tree)
    unparsed = unparse(tree, py_ver_consistent=True)

    for name in spack.directives.directive_names:
        assert name not in unparsed
Beispiel #4
0
def canonical_source(spec, filter_multimethods=True, source=None):
    """Get canonical source for a spec's package.py by unparsing its AST.

    Arguments:
        filter_multimethods (bool): By default, filter multimethods out of the
            AST if they are known statically to be unused. Supply False to disable.
        source (str): Optionally provide a string to read python code from.
    """
    return unparse(
        package_ast(spec, filter_multimethods, source=source),
        py_ver_consistent=True,
    )
Beispiel #5
0
def test_remove_docstrings():
    tree = ast.parse(many_strings)
    tree = ph.RemoveDocstrings().visit(tree)

    unparsed = unparse(tree, py_ver_consistent=True)
    assert unparsed == many_strings_no_docstrings