Exemplo n.º 1
0
 def test_list_versions_badpackage(self, build_lb_image_for_env):
     """Test list_versions command"""
     mrg = PipPackageManager()
     lb = build_lb_image_for_env[0]
     username = build_lb_image_for_env[1]
     with pytest.raises(ValueError):
         mrg.list_versions("gigantumasdfasdfasdf", lb, username)
Exemplo n.º 2
0
    def test_latest_versions(self, build_lb_image_for_env):
        """Test latest_version command"""
        mrg = PipPackageManager()
        lb = build_lb_image_for_env[0]
        username = build_lb_image_for_env[1]
        gtm1, gtm2, gtm3 = mrg.latest_versions(
            ["gtmunit1", "gtmunit2", "gtmunit3"], lb, username)

        assert gtm1 == "0.12.4"
        assert gtm2 == "12.2"
        assert gtm3 == "5.0"
Exemplo n.º 3
0
    def test_latest_version(self, build_lb_image_for_env):
        """Test latest_version command"""
        mrg = PipPackageManager()
        lb = build_lb_image_for_env[0]
        username = build_lb_image_for_env[1]
        result = mrg.latest_version("gtmunit1", lb, username)

        assert result == "0.12.4"

        result = mrg.latest_version("gtmunit2", lb, username)

        assert result == "12.2"
Exemplo n.º 4
0
    def test_search(self, mock_config_with_repo, build_lb_image_for_env):
        """Test search command"""
        mrg = PipPackageManager()
        lb = build_lb_image_for_env[0]
        username = build_lb_image_for_env[1]
        result = mrg.search("peppercorn", lb, username)
        assert len(result) == 2

        result = mrg.search("gigantum", lb, username)
        assert len(result) == 4
        assert result[0] == "gigantum"
        assert result[3] == "gtmunit3"
Exemplo n.º 5
0
    def test_list_versions(self, build_lb_image_for_env):
        """Test list_versions command"""
        mrg = PipPackageManager()
        lb = build_lb_image_for_env[0]
        username = build_lb_image_for_env[1]
        result = mrg.list_versions("gtmunit1", lb, username)

        assert len(result) == 5
        assert result[0] == '0.12.4'
        assert result[1] == '0.2.4'
        assert result[2] == '0.2.1'
        assert result[3] == '0.2.0'
        assert result[4] == '0.1.0'
Exemplo n.º 6
0
    def test_generate_docker_install_snippet_single(self):
        """Test generate_docker_install_snippet command
        """
        mrg = PipPackageManager()

        packages = [{'name': 'mypackage', 'version': '3.1.4'}]

        result = mrg.generate_docker_install_snippet(packages)
        assert result == ['RUN pip install mypackage==3.1.4']

        result = mrg.generate_docker_install_snippet(packages,
                                                     single_line=True)
        assert result == ['RUN pip install mypackage==3.1.4']
Exemplo n.º 7
0
    def test_list_installed_packages(self, build_lb_image_for_env):
        """Test list_installed_packages command

        Note, if the contents of the container change, this test will break and need to be updated. Because of this,
        only limited asserts are made to make sure things are coming back in a reasonable format
        """
        mrg = PipPackageManager()
        lb = build_lb_image_for_env[0]
        username = build_lb_image_for_env[1]
        result = mrg.list_installed_packages(lb, username)

        assert type(result) == list
        assert len(result) > 50
        assert type(result[0]) == dict
        assert type(result[0]['name']) == str
        assert type(result[0]['version']) == str
    def test_list_versions_from_fallback(self, mock_config_with_repo):
        """Test list_versions command"""
        username = "******"
        im = InventoryManager(mock_config_with_repo[0])
        lb = im.create_labbook(
            'unittest',
            'unittest',
            'labbook-unittest-01',
            description="From mock_config_from_repo fixture")

        # Create Component Manager
        cm = ComponentManager(lb)
        # Add a component
        cm.add_base(ENV_UNIT_TEST_REPO, ENV_UNIT_TEST_BASE, ENV_UNIT_TEST_REV)

        ib = ImageBuilder(lb)
        ib.assemble_dockerfile(write=True)
        client = get_docker_client()

        try:
            lb, docker_image_id = ContainerOperations.build_image(
                labbook=lb, username=username)

            # Test lookup
            mrg = PipPackageManager()
            result = mrg.search("peppercorn", lb, username)
            assert len(result) == 2

            result = mrg.search("gigantum", lb, username)
            assert len(result) == 4
            assert result[0] == "gigantum"

            # Delete image
            client.images.remove(docker_image_id, force=True, noprune=False)

            # Test lookup still works
            mrg = PipPackageManager()
            result = mrg.search("peppercorn", lb, username)
            assert len(result) == 2

            result = mrg.search("gigantum", lb, username)
            assert len(result) == 4
            assert result[0] == "gigantum"

        finally:
            shutil.rmtree(lb.root_dir)

            # Remove image if it's still there
            try:
                client.images.remove(docker_image_id,
                                     force=True,
                                     noprune=False)
            except:
                pass
Exemplo n.º 9
0
def get_package_manager(manager: str) -> PackageManager:
    """Helper class to instantiate a package manager based on manager string"""
    if manager in ["pip2", "pip3", "pip"]:
        return PipPackageManager()
    elif manager == "conda2":
        return Conda2PackageManager()
    elif manager == "conda3":
        return Conda3PackageManager()
    elif manager in ["apt", "apt-get"]:
        return AptPackageManager()
    else:
        raise ValueError(f"Unsupported package manager `{manager}`")
Exemplo n.º 10
0
    def test_is_valid_errors(self, build_lb_image_for_env):
        """Test list_versions command"""
        pkgs = [{
            "manager": "pip",
            "package": "gtmunit1",
            "version": '0.2.4'
        }, {
            "manager": "pip",
            "package": "gtmunit2",
            "version": "100.00"
        }, {
            "manager": "pip",
            "package": "gtmunit3",
            "version": ""
        }, {
            "manager": "pip",
            "package": "asdfasdfasdf",
            "version": ""
        }]

        mrg = PipPackageManager()
        lb = build_lb_image_for_env[0]
        username = build_lb_image_for_env[1]
        result = mrg.validate_packages(pkgs, lb, username)

        assert result[0].package == "gtmunit1"
        assert result[0].version == "0.2.4"
        assert result[0].error is False

        assert result[1].package == "gtmunit2"
        assert result[1].version == "100.00"
        assert result[1].error is True

        assert result[2].package == "gtmunit3"
        assert result[2].version == "5.0"
        assert result[2].error is False

        assert result[3].package == "asdfasdfasdf"
        assert result[3].version == ""
        assert result[3].error is True
Exemplo n.º 11
0
    def test_is_valid_good(self, build_lb_image_for_env):
        """Test valid packages command"""
        pkgs = [{
            "manager": "pip",
            "package": "gtmunit3",
            "version": "4.15"
        }, {
            "manager": "pip",
            "package": "gtmunit2",
            "version": ""
        }]

        mrg = PipPackageManager()
        lb = build_lb_image_for_env[0]
        username = build_lb_image_for_env[1]
        result = mrg.validate_packages(pkgs, lb, username)

        assert result[0].package == "gtmunit3"
        assert result[0].version == "4.15"
        assert result[0].error is False

        assert result[1].package == "gtmunit2"
        assert result[1].version == "12.2"
        assert result[1].error is False