Пример #1
0
def test_changed_files_all_files(flake8_package):
    # it's hard to guarantee "all files", so do some sanity checks.
    files = set([
        os.path.join(spack.paths.prefix, path)
        for path in changed_files(all_files=True)
    ])

    # spack has a lot of files -- check that we're in the right ballpark
    assert len(files) > 6000

    # a builtin package
    zlib = spack.repo.path.get_pkg_class("zlib")
    assert zlib.module.__file__ in files

    # a core spack file
    assert os.path.join(spack.paths.module_path, "spec.py") in files

    # a mock package
    assert flake8_package in files

    # this test
    assert __file__ in files

    # ensure externals are excluded
    assert not any(f.startswith(spack.paths.external_path) for f in files)
Пример #2
0
def test_changed_no_base(tmpdir, capfd):
    """Ensure that we fail gracefully with no base branch."""
    tmpdir.join("bin").ensure("spack")
    git = which("git", required=True)
    with tmpdir.as_cwd():
        git("init")
        git("config", "user.name", "test user")
        git("config", "user.email", "*****@*****.**")
        git("add", ".")
        git("commit", "-m", "initial commit")

        with pytest.raises(SystemExit):
            changed_files(base="foobar")

        out, err = capfd.readouterr()
        assert "This repository does not have a 'foobar' branch." in err
Пример #3
0
def test_prs_update_old_api():
    """Ensures that every package modified in a PR doesn't contain
    deprecated calls to any method.
    """
    ref = os.getenv("GITHUB_BASE_REF")
    if not ref:
        pytest.skip("No base ref found")

    changed_package_files = [
        x for x in style.changed_files(base=ref) if style.is_package(x)
    ]
    failing = []
    for file in changed_package_files:
        if 'builtin.mock' not in file:  # don't restrict packages for tests
            name = os.path.basename(os.path.dirname(file))
            pkg = spack.repo.get(name)

            failed = (hasattr(pkg, 'setup_environment')
                      or hasattr(pkg, 'setup_dependent_environment'))
            if failed:
                failing.append(name)

    msg = ('there are {0} packages using the old API to set build '
           'and run environment [{1}], for further information see '
           'https://github.com/spack/spack/pull/11115')
    assert not failing, msg.format(len(failing), ','.join(failing))
Пример #4
0
def test_changed_files(flake8_package):
    # changed_files returns file paths relative to the root
    # directory of Spack. Convert to absolute file paths.
    files = [os.path.join(spack.paths.prefix, path) for path in changed_files()]

    # There will likely be other files that have changed
    # when these tests are run
    assert flake8_package in files
Пример #5
0
def test_changed_files_from_git_rev_base(tmpdir, capfd):
    """Test arbitrary git ref as base."""
    git = which("git", required=True)
    with tmpdir.as_cwd():
        git("init")
        git("checkout", "-b", "main")
        git("config", "user.name", "test user")
        git("config", "user.email", "*****@*****.**")
        git("commit", "--allow-empty", "-m", "initial commit")

        tmpdir.ensure('bin/spack')
        assert changed_files(base="HEAD") == ['bin/spack']
        assert changed_files(base="main") == ['bin/spack']

        git("add", 'bin/spack')
        git("commit", "-m", "v1")
        assert changed_files(base="HEAD") == []
        assert changed_files(base="HEAD~") == ["bin/spack"]