Exemple #1
0
def test_required_by(tmp_path):
    home_dir = create_pearl_home(tmp_path)

    packages_info = {
        "repo-test": {
            "pkg-test": {
                "repo_name": "repo-test",
                "name": "pkg-test",
                "url": "/blah",
                "depends": ["repo-test/pkg-test2"]
            },
            "pkg-test2": {
                "repo_name": "repo-test",
                "name": "pkg-test2",
                "url": "/blah",
                "depends": []
            }
        }
    }
    builder = PackageBuilder(home_dir)
    packages = builder.build_packages(packages_info)
    pearl_env = PearlEnvironment(home_dir, env_initialized=False)
    pearl_env._packages = packages
    requires = pearl_env.required_by(
        Package(home_dir, "repo-test", "pkg-test2", "/blah"))
    assert requires[0].full_name == 'repo-test/pkg-test'
Exemple #2
0
def test_package_builder(tmp_path, packages_info):
    builder = PackageBuilder(tmp_path)
    actual_packages = builder.build_packages(packages_info)
    for repo_name in packages_info.keys():
        for pkg_name in packages_info[repo_name].keys():
            actual_package = actual_packages[repo_name][pkg_name]
            package_info = packages_info[repo_name][pkg_name]
            assert package_info['name'] == actual_package.name
            assert package_info['repo_name'] == actual_package.repo_name
            assert '{}/{}'.format(
                package_info['repo_name'],
                package_info['name']) == actual_package.full_name
            assert package_info['url'] == actual_package.url
            assert package_info['description'] == actual_package.description
            assert package_info['homepage'] == actual_package.homepage
            assert package_info['author'] == actual_package.author
            assert package_info['license'] == actual_package.license
            assert package_info['os'] == tuple(
                [o.name.lower() for o in actual_package.os])
            assert package_info['keywords'] == actual_package.keywords
            for pkg_dep_name in package_info['depends']:
                assert pkg_dep_name in [
                    dep.full_name for dep in actual_package.depends
                ]

            assert str(actual_package.dir) == str(
                tmp_path / 'packages/{}'.format(actual_package.full_name))
            assert str(actual_package.vardir) == str(
                tmp_path / 'var/{}'.format(actual_package.full_name))
Exemple #3
0
def test_lookup_package(tmp_path):
    home_dir = create_pearl_home(tmp_path)

    packages_info = {
        "repo-test": {
            "pkg-test": {
                "repo_name": "repo-test",
                "name": "pkg-test",
                "url": "/blah",
                "depends": ["repo-test/pkg-test2"]
            },
            "pkg-test2": {
                "repo_name": "repo-test",
                "name": "pkg-test2",
                "url": "/blah",
                "depends": []
            }
        }
    }
    builder = PackageBuilder(home_dir)
    packages = builder.build_packages(packages_info)
    pearl_env = PearlEnvironment(home_dir, env_initialized=False)
    pearl_env._packages = packages
    actual_package = pearl_env.lookup_package('repo-test/pkg-test')
    assert actual_package.full_name == 'repo-test/pkg-test'

    actual_package = pearl_env.lookup_package('pkg-test')
    assert actual_package.full_name == 'repo-test/pkg-test'
Exemple #4
0
def test_lookup_package_not_in_repo(tmp_path):
    home_dir = create_pearl_home(tmp_path)
    packages_info = {
        "repo-test": {
            "pkg-test": {
                "repo_name": "repo-test",
                "name": "pkg-test",
                "url": "/blah",
            },
        }
    }
    builder = PackageBuilder(home_dir)
    packages = builder.build_packages(packages_info)

    pearl_env = PearlEnvironment(home_dir, env_initialized=False)
    pearl_env._packages = packages
    with pytest.raises(PackageNotInRepoError):
        pearl_env.lookup_package('repo-test/pkg-a-test')

    with pytest.raises(PackageNotInRepoError):
        pearl_env.lookup_package('pkg-a-test')
Exemple #5
0
def test_update_packages(tmp_path):
    home_dir = create_pearl_home(tmp_path)

    packages_info = {
        "repo-test": {
            "pkg1": {
                "repo_name": "repo-test",
                "name": "pkg1",
                "url": "/blah",
                "depends": ["repo-test/deppkg1"]
            },
            "pkg2": {
                "repo_name": "repo-test",
                "name": "pkg2",
                "url": "/blah",
                "depends": []
            },
            "deppkg1": {
                "repo_name": "repo-test",
                "name": "deppkg1",
                "url": "/blah",
                "depends": []
            }
        }
    }
    builder = PackageBuilder(home_dir)
    packages = builder.build_packages(packages_info)
    pearl_env = PearlEnvironment(
        home_dir, env_initialized=False
    )
    pearl_env._packages = packages

    with mock.patch(_MODULE_UNDER_TEST + '.update_package') as update_mock, \
            mock.patch(_MODULE_UNDER_TEST + '.emerge_package') as emerge_mock:
        args = PackageArgs(packages=[packages['repo-test']['pkg1'], packages['repo-test']['pkg2']])
        update_packages(pearl_env, args)

        emerge_mock.assert_has_calls([mock.call(mock.ANY, packages['repo-test']['deppkg1'], args)])
        update_mock.assert_has_calls([mock.call(mock.ANY, packages['repo-test']['pkg1'], args), mock.call(mock.ANY, packages['repo-test']['pkg2'], args)])
Exemple #6
0
def test_remove_packages_required_installed_packages_raise(tmp_path, required_package_installed, expected_remove_calls):
    home_dir = create_pearl_home(tmp_path)
    if required_package_installed:
        (home_dir / 'packages/repo-test/pkg1').mkdir(parents=True)

    packages_info = {
        "repo-test": {
            "pkg1": {
                "repo_name": "repo-test",
                "name": "pkg1",
                "url": "/blah",
                "depends": ["repo-test/deppkg1"]
            },
            "deppkg1": {
                "repo_name": "repo-test",
                "name": "deppkg1",
                "url": "/blah",
                "depends": []
            }
        }
    }
    builder = PackageBuilder(home_dir)
    packages = builder.build_packages(packages_info)
    pearl_env = PearlEnvironment(
        home_dir, env_initialized=False
    )
    pearl_env._packages = packages
    with mock.patch(_MODULE_UNDER_TEST + '.remove_package') as remove_mock:
        args = PackageArgs(packages=[packages['repo-test']['deppkg1']])
        if required_package_installed:
            with pytest.raises(PackageRequiredByOtherError):
                remove_packages(pearl_env, args)
        else:
            remove_packages(pearl_env, args)

        assert remove_mock.call_count == expected_remove_calls
Exemple #7
0
def test_closure_dependency_tree(
        tmp_path,
        initial_package_list, package_deps,
        expected_result
):
    home_dir = create_pearl_home(tmp_path)

    packages_info = {
        'repo-test': {
        }
    }
    for package_name, depends in package_deps.items():
        packages_info['repo-test'][package_name] = {
            'repo_name': 'repo-test',
            'name': package_name,
            'url': '/sdaf',
            'depends': ['repo-test/' + dep for dep in depends]
        }
    builder = PackageBuilder(home_dir)
    packages = builder.build_packages(packages_info)
    init_packages = [packages['repo-test'][name] for name in initial_package_list]
    assert closure_dependency_tree(
        init_packages,
    ) == [packages['repo-test'][name] for name in expected_result]