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"), )
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"), ), ])
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))
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()))
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())
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()