Ejemplo n.º 1
0
    def test_get_component_list_packages(self, mock_config_with_repo):
        """Test listing packages added a to labbook"""
        lb = create_tmp_labbook(mock_config_with_repo[0])
        labbook_dir = lb.root_dir
        cm = ComponentManager(lb)

        # mock_config_with_repo is a ComponentManager Instance
        pkgs = [{
            "manager": "pip3",
            "package": "requests",
            "version": "2.18.2"
        }, {
            "manager": "pip3",
            "package": "gigantum",
            "version": "0.5"
        }]
        cm.add_packages('pip3', pkgs)

        packages = cm.get_component_list('package_manager')

        assert len(packages) == 2
        assert packages[1]['manager'] == 'pip3'
        assert packages[1]['package'] == 'requests'
        assert packages[1]['version'] == '2.18.2'
        assert packages[0]['manager'] == 'pip3'
        assert packages[0]['package'] == 'gigantum'
        assert packages[0]['version'] == '0.5'
Ejemplo n.º 2
0
    def test_get_component_list_base(self, mock_config_with_repo):
        """Test listing base images added a to labbook"""
        lb = create_tmp_labbook(mock_config_with_repo[0])
        labbook_dir = lb.root_dir
        cm = ComponentManager(lb)

        # mock_config_with_repo is a ComponentManager Instance
        cm.add_base(gtmcore.fixtures.ENV_UNIT_TEST_REPO,
                    gtmcore.fixtures.ENV_UNIT_TEST_BASE,
                    gtmcore.fixtures.ENV_UNIT_TEST_REV)

        bases = cm.get_component_list('base')

        assert len(bases) == 1
        assert bases[0]['id'] == gtmcore.fixtures.ENV_UNIT_TEST_BASE
        assert bases[0]['revision'] == gtmcore.fixtures.ENV_UNIT_TEST_REV
Ejemplo n.º 3
0
    def test_change_base(self, mock_labbook):
        """change_base is used both for updating versions and truly changing the base"""
        conf_file, root_dir, lb = mock_labbook

        # Initial configuration for the labbook - base config taken from `test_add_base` and package config from
        # `test_add_package` - so we don't test assertions (again) on this part
        cm = ComponentManager(lb)

        # We "misconfigure" a package that is not part of the base as if it was from a base
        # This shouldn't happen, but we address it just in case
        pkgs = [
            {
                "manager": "pip3",
                "package": "gigantum",
                "version": "0.5"
            },
            # pandas *is* part of the quickstart-juypter base, but we specify a different version here
            {
                "package": "pandas",
                "version": "0.21"
            }
        ]
        cm.add_packages('pip3', pkgs, force=True, from_base=True)
        packages = [p for p in cm.get_component_list('package_manager')]
        assert (len(packages) == 2)
        assert (all(p['from_base'] for p in packages))

        cm.add_base(gtmcore.fixtures.ENV_UNIT_TEST_REPO,
                    'quickstart-jupyterlab', 1)

        # After installing the base, we should have one version of matplotlib installed
        packages = [
            p for p in cm.get_component_list('package_manager')
            if p['package'] == 'matplotlib'
        ]
        assert (len(packages) == 1)
        assert (packages[0]['version'] == '2.1.1')

        # add_base() should have converted these to user-installed
        packages = [
            p for p in cm.get_component_list('package_manager')
            if p['package'] in ['gigantum', 'pandas']
        ]
        # If we had redundancy from fake base-installed pandas plus real base-installed pandas, this would be 3
        assert (len(packages) == 2)
        for p in packages:
            # Fake base-installed is converted to user ("not from_base") installed
            assert (not p['from_base'])
            if p['package'] == 'pandas':
                # we should still have the fake base-installed version
                assert (p['version'] == '0.21')

        pkgs = [
            {
                "manager": "pip3",
                "package": "requests",
                "version": "2.18.2"
            },
            # This will override an already installed package
            {
                "manager": "pip3",
                "package": "matplotlib",
                "version": "2.2"
            }
        ]
        cm.add_packages('pip3', pkgs, force=True)

        pkgs = [{
            "manager": "apt",
            "package": "ack",
            "version": "1.0"
        }, {
            "manager": "apt",
            "package": "docker",
            "version": "3.5"
        }]
        cm.add_packages('apt', pkgs)

        # Installing a customized version of matplotlib is a new package compared to other tests,
        # and is a critical piece of testing cm.change_base
        packages = [
            p for p in cm.get_component_list('package_manager')
            if p['package'] == 'matplotlib'
        ]
        assert (len(packages) == 1)
        assert (packages[0]['version'] == '2.2')

        # We upgrade our base
        cm.change_base(gtmcore.fixtures.ENV_UNIT_TEST_REPO,
                       'quickstart-jupyterlab', 2)

        # matplotlib still set up per "user" update?
        packages = [
            p for p in cm.get_component_list('package_manager')
            if p['package'] == 'matplotlib'
        ]
        assert (len(packages) == 1)
        assert (packages[0]['version'] == '2.2')

        # Base revision now 2?
        assert (cm.base_fields['revision'] == 2)