Пример #1
0
def test_more_dynamic_multimethod_resolution():
    # we know the first one is the only one that can win.
    filtered = ph.canonical_source("[email protected]", source=more_dynamic_multimethods)
    assert "ONE" in filtered
    assert "TWO" not in filtered
    assert "THREE" not in filtered
    assert "FOUR" not in filtered
    assert "FIVE" in filtered

    # now we have to include ONE and TWO because ONE may win dynamically.
    filtered = ph.canonical_source("[email protected]", source=more_dynamic_multimethods)
    assert "ONE" in filtered
    assert "TWO" in filtered
    assert "THREE" not in filtered
    assert "FOUR" not in filtered
    assert "FIVE" in filtered

    # we know FOUR is true and TWO and THREE are false, but ONE may
    # still win dynamically.
    filtered = ph.canonical_source("[email protected]", source=more_dynamic_multimethods)
    assert "ONE" in filtered
    assert "TWO" not in filtered
    assert "THREE" not in filtered
    assert "FOUR" in filtered
    assert "FIVE" in filtered

    # TWO and FOUR can't be satisfied, but ONE or THREE could win
    filtered = ph.canonical_source("[email protected]", source=more_dynamic_multimethods)
    assert "ONE" in filtered
    assert "TWO" not in filtered
    assert "THREE" in filtered
    assert "FOUR" not in filtered
    assert "FIVE" in filtered
Пример #2
0
def test_multimethod_resolution():
    # all are false but the default
    filtered = ph.canonical_source("[email protected]", source=many_multimethods)
    assert "ONE" in filtered
    assert "TWO" not in filtered
    assert "THREE" not in filtered
    assert "FOUR" not in filtered
    assert "FIVE" in filtered

    # we know first @when overrides default and others are false
    filtered = ph.canonical_source("[email protected]", source=many_multimethods)
    assert "ONE" not in filtered
    assert "TWO" in filtered
    assert "THREE" not in filtered
    assert "FOUR" not in filtered
    assert "FIVE" in filtered

    # we know last @when overrides default and others are false
    filtered = ph.canonical_source("[email protected]", source=many_multimethods)
    assert "ONE" not in filtered
    assert "TWO" not in filtered
    assert "THREE" not in filtered
    assert "FOUR" in filtered
    assert "FIVE" in filtered

    # we don't know if default or THREE will win, include both
    filtered = ph.canonical_source("[email protected]", source=many_multimethods)
    assert "ONE" in filtered
    assert "TWO" not in filtered
    assert "THREE" in filtered
    assert "FOUR" not in filtered
    assert "FIVE" in filtered
Пример #3
0
def compare_sans_name(eq, spec1, spec2):
    content1 = ph.canonical_source(spec1)
    content1 = content1.replace(spec1.package.__class__.__name__, 'TestPackage')
    content2 = ph.canonical_source(spec2)
    content2 = content2.replace(spec2.package.__class__.__name__, 'TestPackage')
    if eq:
        assert content1 == content2
    else:
        assert content1 != content2
Пример #4
0
def compare_hash_sans_name(eq, spec1, spec2):
    content1 = ph.canonical_source(spec1)
    content1 = content1.replace(spec1.package.__class__.__name__, 'TestPackage')
    hash1 = spec1.package.content_hash(content=content1)

    content2 = ph.canonical_source(spec2)
    content2 = content2.replace(spec2.package.__class__.__name__, 'TestPackage')
    hash2 = spec2.package.content_hash(content=content2)

    if eq:
        assert hash1 == hash2
    else:
        assert hash1 != hash2
Пример #5
0
def compare_sans_name(eq, spec1, spec2):
    content1 = ph.canonical_source(spec1)
    content1 = content1.replace(
        spack.repo.path.get_pkg_class(spec1.name).__name__, 'TestPackage'
    )
    content2 = ph.canonical_source(spec2)
    content2 = content2.replace(
        spack.repo.path.get_pkg_class(spec2.name).__name__, 'TestPackage'
    )
    if eq:
        assert content1 == content2
    else:
        assert content1 != content2
Пример #6
0
def compare_hash_sans_name(eq, spec1, spec2):
    content1 = ph.canonical_source(spec1)
    pkg_cls1 = spack.repo.path.get_pkg_class(spec1.name)
    content1 = content1.replace(pkg_cls1.__name__, 'TestPackage')
    hash1 = pkg_cls1(spec1).content_hash(content=content1)

    content2 = ph.canonical_source(spec2)
    pkg_cls2 = spack.repo.path.get_pkg_class(spec2.name)
    content2 = content2.replace(pkg_cls2.__name__, 'TestPackage')
    hash2 = pkg_cls2(spec2).content_hash(content=content2)

    if eq:
        assert hash1 == hash2
    else:
        assert hash1 != hash2
Пример #7
0
def test_packages_are_unparseable():
    """Ensure that all packages can unparse and that unparsed code is valid Python."""
    failed_to_unparse = []
    failed_to_compile = []

    for name in spack.repo.all_package_names():
        try:
            source = ph.canonical_source(name, filter_multimethods=False)
        except Exception:
            failed_to_unparse.append(name)

        try:
            compile(source, "internal", "exec", ast.PyCF_ONLY_AST)
        except Exception:
            failed_to_compile.append(name)

    if failed_to_unparse:
        tty.msg('The following packages failed to unparse: ' +
                ', '.join(failed_to_unparse))
        assert False

    if failed_to_compile:
        tty.msg('The following unparsed packages failed to compile: ' +
                ', '.join(failed_to_compile))
        assert False
Пример #8
0
def pkg_source(args):
    """dump source code for a package"""
    specs = spack.cmd.parse_specs(args.spec, concretize=False)
    if len(specs) != 1:
        tty.die("spack pkg source requires exactly one spec")

    spec = specs[0]
    filename = spack.repo.path.filename_for_package_name(spec.name)

    # regular source dump -- just get the package and print its contents
    if args.canonical:
        message = "Canonical source for %s:" % filename
        content = ph.canonical_source(spec)
    else:
        message = "Source for %s:" % filename
        with open(filename) as f:
            content = f.read()

    if sys.stdout.isatty():
        tty.msg(message)
    sys.stdout.write(content)