コード例 #1
0
    def test_build_with_specific_python(self):
        class Options:
            conda_packages = ["pkg1", "pkg2"]
            conda_python_version = "3.7"

        plugin = conda.CondaPlugin("test-part", Options(), self.project)

        # Fake _conda_home
        conda_cmd = os.path.join(plugin._conda_home, "bin", "conda")
        os.makedirs(os.path.dirname(conda_cmd))
        open(conda_cmd, "w").close()

        plugin.build()

        self.fake_check_call.mock.assert_called_once_with(
            [
                os.path.join(plugin._conda_home, "bin", "conda"),
                "create",
                "--prefix",
                plugin.installdir,
                "--yes",
                "python=3.7",
                "pkg1",
                "pkg2",
            ],
            env=dict(CONDA_TARGET_PREFIX_OVERRIDE="/snap/conda-snap/current"),
        )
コード例 #2
0
    def test_build_with_defaults_but_no_conda_home(self):
        class Options:
            conda_packages = ["pkg1", "pkg2"]
            conda_python_version = ""

        plugin = conda.CondaPlugin("test-part", Options(), self.project)

        plugin.build()

        self.fake_check_call.mock.assert_has_calls(
            [
                mock.call(
                    [
                        os.path.join(plugin.partdir, "miniconda.sh"),
                        "-bfp",
                        plugin._conda_home,
                    ]
                ),
                mock.call(
                    [
                        os.path.join(plugin._conda_home, "bin", "conda"),
                        "create",
                        "--prefix",
                        plugin.installdir,
                        "--yes",
                        "pkg1",
                        "pkg2",
                    ],
                    env=dict(CONDA_TARGET_PREFIX_OVERRIDE="/snap/conda-snap/current"),
                ),
            ]
        )
コード例 #3
0
    def test_specific_known_version(self):
        class Options:
            conda_miniconda_version = self.miniconda_version

        plugin = conda.CondaPlugin("test-part", Options(), self.project)
        source_script = plugin._get_miniconda_script()

        self.assertThat(source_script.source, Equals(self.expected_url))
        self.assertThat(source_script.source_checksum, Equals(self.expected_checksum))
コード例 #4
0
def test_get_miniconda_source(project, miniconda_version, expected_url,
                              expected_checksum):
    class Options:
        conda_miniconda_version = miniconda_version

    plugin = conda.CondaPlugin("test-part", Options(), project)
    source_script = plugin._get_miniconda_script()

    assert source_script.source == expected_url
    assert source_script.source_checksum == expected_checksum
コード例 #5
0
    def test_clean_pull(self):
        class Options:
            pass

        plugin = conda.CondaPlugin("test-part", Options(), self.project)

        os.makedirs(plugin._conda_home)

        plugin.clean_pull()

        self.assertThat(plugin._conda_home, Not(DirExists()))
コード例 #6
0
    def test_clean_build(self):
        class Options:
            pass

        plugin = conda.CondaPlugin("test-part", Options(), self.project)

        os.makedirs(plugin._conda_home)

        plugin.clean_build()

        # Make sure that _conda_home is still there after clean_build
        self.assertThat(plugin._conda_home, DirExists())
コード例 #7
0
    def test_pull(self):
        class Options:
            conda_miniconda_version = "latest"

        fake_source_script = fixtures.MockPatch("snapcraft.internal.sources.Script")
        self.useFixture(fake_source_script)

        plugin = conda.CondaPlugin("test-part", Options(), self.project)

        def download(filepath):
            self.assertThat(
                filepath, Equals(os.path.join(plugin.partdir, "miniconda.sh"))
            )
            os.makedirs(plugin.partdir)
            open(filepath, "w").close()

        fake_source_script.mock().download.side_effect = download

        plugin.pull()

        fake_source_script.mock().download.assert_called_once_with(filepath=mock.ANY)
        self.fake_check_call.mock.assert_not_called()