Ejemplo n.º 1
0
def test_pkg_canonical_source(mock_packages):
    source = pkg("source", "multimethod")
    assert "@when('@2.0')" in source
    assert "Check that multimethods work with boolean values" in source

    canonical_1 = pkg("source", "--canonical", "[email protected]")
    assert "@when" not in canonical_1
    assert "should_not_be_reached by diamond inheritance test" not in canonical_1
    assert "return '[email protected]'" in canonical_1
    assert "return '[email protected]'" not in canonical_1
    assert "return 'first_parent'" not in canonical_1
    assert "'should_not_be_reached by diamond inheritance test'" not in canonical_1

    canonical_2 = pkg("source", "--canonical", "[email protected]")
    assert "@when" not in canonical_2
    assert "return '[email protected]'" not in canonical_2
    assert "return '[email protected]'" in canonical_2
    assert "return 'first_parent'" in canonical_2
    assert "'should_not_be_reached by diamond inheritance test'" not in canonical_2

    canonical_3 = pkg("source", "--canonical", "[email protected]")
    assert "@when" not in canonical_3
    assert "return '[email protected]'" not in canonical_3
    assert "return '[email protected]'" not in canonical_3
    assert "return 'first_parent'" not in canonical_3
    assert "'should_not_be_reached by diamond inheritance test'" not in canonical_3

    canonical_4 = pkg("source", "--canonical", "[email protected]")
    assert "@when" not in canonical_4
    assert "return '[email protected]'" not in canonical_4
    assert "return '[email protected]'" not in canonical_4
    assert "return 'first_parent'" not in canonical_4
    assert "'should_not_be_reached by diamond inheritance test'" in canonical_4
Ejemplo n.º 2
0
def test_pkg_removed(mock_pkg_git_repo):
    out = split(pkg('removed', 'HEAD^^', 'HEAD^'))
    assert out == []

    out = split(pkg('removed', 'HEAD^^', 'HEAD'))
    assert out == []

    out = split(pkg('removed', 'HEAD^', 'HEAD'))
    assert out == ['pkg-c']
Ejemplo n.º 3
0
def test_pkg_diff(mock_pkg_git_repo, mock_pkg_names):
    out = split(pkg('diff', 'HEAD^^', 'HEAD^'))
    assert out == ['HEAD^:', 'pkg-a', 'pkg-b', 'pkg-c']

    out = split(pkg('diff', 'HEAD^^', 'HEAD'))
    assert out == ['HEAD:', 'pkg-a', 'pkg-b', 'pkg-d']

    out = split(pkg('diff', 'HEAD^', 'HEAD'))
    assert out == ['HEAD^:', 'pkg-c', 'HEAD:', 'pkg-d']
Ejemplo n.º 4
0
def test_pkg_added(mock_pkg_git_repo):
    out = split(pkg('added', 'HEAD^^', 'HEAD^'))
    assert out == ['pkg-a', 'pkg-b', 'pkg-c']

    out = split(pkg('added', 'HEAD^^', 'HEAD'))
    assert out == ['pkg-a', 'pkg-b', 'pkg-d']

    out = split(pkg('added', 'HEAD^', 'HEAD'))
    assert out == ['pkg-d']

    out = split(pkg('added', 'HEAD', 'HEAD'))
    assert out == []
Ejemplo n.º 5
0
def test_pkg_list(mock_pkg_git_repo, mock_pkg_names):
    out = split(pkg('list', 'HEAD^^'))
    assert sorted(mock_pkg_names) == sorted(out)

    out = split(pkg('list', 'HEAD^'))
    assert sorted(mock_pkg_names.union(['pkg-a', 'pkg-b',
                                        'pkg-c'])) == sorted(out)

    out = split(pkg('list', 'HEAD'))
    assert sorted(mock_pkg_names.union(['pkg-a', 'pkg-b',
                                        'pkg-d'])) == sorted(out)

    # test with three dots to make sure pkg calls `git merge-base`
    out = split(pkg('list', 'HEAD^^...'))
    assert sorted(mock_pkg_names) == sorted(out)
Ejemplo n.º 6
0
def test_pkg_source(mock_packages):
    fake_source = pkg("source", "fake")

    fake_file = spack.repo.path.filename_for_package_name("fake")
    with open(fake_file) as f:
        contents = f.read()
        assert fake_source == contents
Ejemplo n.º 7
0
Archivo: pkg.py Proyecto: lorak41/spack
def test_pkg_add(mock_pkg_git_repo):
    with working_dir(mock_pkg_git_repo):
        mkdirp('pkg-e')
        with open('pkg-e/package.py', 'w') as f:
            f.write(pkg_template.format(name='PkgE'))

    pkg('add', 'pkg-e')

    git = which('git', required=True)
    with working_dir(mock_pkg_git_repo):
        try:
            assert ('A  pkg-e/package.py' in
                    git('status', '--short', output=str))
        finally:
            shutil.rmtree('pkg-e')

    with pytest.raises(spack.main.SpackCommandError):
        pkg('add', 'does-not-exist')
Ejemplo n.º 8
0
def test_pkg_add(mock_pkg_git_repo):
    with working_dir(mock_pkg_git_repo):
        mkdirp('pkg-e')
        with open('pkg-e/package.py', 'w') as f:
            f.write(pkg_template.format(name='PkgE'))

    pkg('add', 'pkg-e')

    git = which('git', required=True)
    with working_dir(mock_pkg_git_repo):
        try:
            assert ('A  pkg-e/package.py' in
                    git('status', '--short', output=str))
        finally:
            shutil.rmtree('pkg-e')
            # Removing a package mid-run disrupts Spack's caching
            spack.repo.path.repos[0]._fast_package_checker.invalidate()

    with pytest.raises(spack.main.SpackCommandError):
        pkg('add', 'does-not-exist')
Ejemplo n.º 9
0
def test_pkg_hash(mock_packages):
    output = pkg("hash", "a", "b").strip().split()
    assert len(output) == 2 and all(len(elt) == 32 for elt in output)

    output = pkg("hash", "multimethod").strip().split()
    assert len(output) == 1 and all(len(elt) == 32 for elt in output)
Ejemplo n.º 10
0
def test_pkg_source_requires_one_arg(mock_packages):
    with pytest.raises(spack.main.SpackCommandError):
        pkg("source", "a", "b")

    with pytest.raises(spack.main.SpackCommandError):
        pkg("source", "--canonical", "a", "b")
Ejemplo n.º 11
0
def test_pkg_fails_when_not_git_repo(monkeypatch):
    monkeypatch.setattr(spack.cmd, 'spack_is_git_repo', lambda: False)
    with pytest.raises(spack.main.SpackCommandError):
        pkg('added')
Ejemplo n.º 12
0
def test_pkg_changed(mock_pkg_git_repo):
    out = split(pkg('changed', 'HEAD^^', 'HEAD^'))
    assert out == []

    out = split(pkg('changed', '--type', 'c', 'HEAD^^', 'HEAD^'))
    assert out == []

    out = split(pkg('changed', '--type', 'a', 'HEAD^^', 'HEAD^'))
    assert out == ['pkg-a', 'pkg-b', 'pkg-c']

    out = split(pkg('changed', '--type', 'r', 'HEAD^^', 'HEAD^'))
    assert out == []

    out = split(pkg('changed', '--type', 'ar', 'HEAD^^', 'HEAD^'))
    assert out == ['pkg-a', 'pkg-b', 'pkg-c']

    out = split(pkg('changed', '--type', 'arc', 'HEAD^^', 'HEAD^'))
    assert out == ['pkg-a', 'pkg-b', 'pkg-c']

    out = split(pkg('changed', 'HEAD^', 'HEAD'))
    assert out == ['pkg-b']

    out = split(pkg('changed', '--type', 'c', 'HEAD^', 'HEAD'))
    assert out == ['pkg-b']

    out = split(pkg('changed', '--type', 'a', 'HEAD^', 'HEAD'))
    assert out == ['pkg-d']

    out = split(pkg('changed', '--type', 'r', 'HEAD^', 'HEAD'))
    assert out == ['pkg-c']

    out = split(pkg('changed', '--type', 'ar', 'HEAD^', 'HEAD'))
    assert out == ['pkg-c', 'pkg-d']

    out = split(pkg('changed', '--type', 'arc', 'HEAD^', 'HEAD'))
    assert out == ['pkg-b', 'pkg-c', 'pkg-d']

    # invalid type argument
    with pytest.raises(spack.main.SpackCommandError):
        pkg('changed', '--type', 'foo')