def test_autokeep(self): self.fake_apt_cache = fixture_setup.FakeAptCache() self.useFixture(self.fake_apt_cache) self.test_packages = ( "main-package", "dependency", "sub-dependency", "conflicting-dependency", ) self.fake_apt_cache.add_packages(self.test_packages) self.fake_apt_cache.cache["main-package"].dependencies = [ [ fixture_setup.FakeAptBaseDependency( "dependency", [self.fake_apt_cache.cache["dependency"]] ), fixture_setup.FakeAptBaseDependency( "conflicting-dependency", [self.fake_apt_cache.cache["conflicting-dependency"]], ), ] ] self.fake_apt_cache.cache["dependency"].dependencies = [ [ fixture_setup.FakeAptBaseDependency( "sub-dependency", [self.fake_apt_cache.cache["sub-dependency"]] ) ] ] self.fake_apt_cache.cache["conflicting-dependency"].conflicts = [ self.fake_apt_cache.cache["dependency"] ] project_options = snapcraft.ProjectOptions() ubuntu = repo.Ubuntu(self.tempdir, project_options=project_options) ubuntu.get(["main-package", "conflicting-dependency"]) # Verify that the package was actually fetched and copied into the # requested location. self.assertThat( os.path.join(self.tempdir, "download", "main-package.deb"), FileExists() ) self.assertThat( os.path.join(self.tempdir, "download", "conflicting-dependency.deb"), FileExists(), ) self.assertThat( os.path.join(self.tempdir, "download", "dependency.deb"), Not(FileExists()), "Dependency should not have been fetched", ) self.assertThat( os.path.join(self.tempdir, "download", "sub-dependency.deb"), Not(FileExists()), "Sub-dependency should not have been fetched", )
def setUp(self): super().setUp() self.fake_apt_cache = fixture_setup.FakeAptCache() self.useFixture(self.fake_apt_cache) self.test_packages = ('package-not-installed', 'package-installed', 'another-uninstalled', 'another-installed', 'repeated-package', 'repeated-package', 'versioned-package=0.2', 'versioned-package') self.fake_apt_cache.add_packages(self.test_packages) self.fake_apt_cache.cache['package-installed'].installed = True self.fake_apt_cache.cache['another-installed'].installed = True self.fake_apt_cache.cache['versioned-package'].version = '0.1'
def setUp(self): super().setUp() patcher = mock.patch("snapcraft._get_version", return_value="3.0") patcher.start() self.addCleanup(patcher.stop) patcher = mock.patch( "snapcraft.project.Project._get_start_time", return_value=datetime.strptime( "2019-05-07T19:25:53.939041", "%Y-%m-%dT%H:%M:%S.%f" ), ) patcher.start() self.addCleanup(patcher.stop) original_check_output = subprocess.check_output def fake_uname(cmd, *args, **kwargs): if "uname" in cmd: return b"Linux test uname 4.10 x86_64" else: return original_check_output(cmd, *args, **kwargs) check_output_patcher = mock.patch( "subprocess.check_output", side_effect=fake_uname ) check_output_patcher.start() self.addCleanup(check_output_patcher.stop) self.useFixture( fixtures.MockPatch( "snapcraft.internal.repo._deb.Ubuntu._extract_deb_name_version", return_value="test-1.0", ) ) self.useFixture( fixtures.MockPatch("snapcraft.internal.repo._deb.Ubuntu._extract_deb") ) self.fake_apt_cache = fixture_setup.FakeAptCache() self.useFixture(self.fake_apt_cache) self.fake_apt_cache.add_package( fixture_setup.FakeAptCachePackage("patchelf", "0.9", installed=True) ) self.fake_snapd.snaps_result = [ dict(name="core18", channel="stable", revision="10") ] self.useFixture(FakeOsRelease())
def setUp(self): super().setUp() self.fake_apt_cache = fixture_setup.FakeAptCache() self.useFixture(self.fake_apt_cache) self.test_packages = ( "package-not-installed", "package-installed", "another-uninstalled", "another-installed", "repeated-package", "repeated-package", "versioned-package=0.2", "versioned-package", ) self.fake_apt_cache.add_packages(self.test_packages) self.fake_apt_cache.cache["package-installed"].installed = True self.fake_apt_cache.cache["another-installed"].installed = True self.fake_apt_cache.cache["versioned-package"].version = "0.1"
def setUp(self): super().setUp() patcher = mock.patch("snapcraft._get_version", return_value="3.0") patcher.start() self.addCleanup(patcher.stop) original_check_output = subprocess.check_output def fake_uname(cmd, *args, **kwargs): if "uname" in cmd: return b"Linux test uname 4.10 x86_64" else: return original_check_output(cmd, *args, **kwargs) check_output_patcher = mock.patch( "subprocess.check_output", side_effect=fake_uname ) check_output_patcher.start() self.addCleanup(check_output_patcher.stop) original_check_call = subprocess.check_call def _fake_dpkg_deb(command, *args, **kwargs): if "dpkg-deb" not in command: return original_check_call(command, *args, **kwargs) check_call_patcher = mock.patch( "subprocess.check_call", side_effect=_fake_dpkg_deb ) check_call_patcher.start() self.addCleanup(check_call_patcher.stop) self.fake_apt_cache = fixture_setup.FakeAptCache() self.useFixture(self.fake_apt_cache) self.fake_apt_cache.add_package( fixture_setup.FakeAptCachePackage("patchelf", "0.9", installed=True) ) self.fake_snapd = fixture_setup.FakeSnapd() self.useFixture(self.fake_snapd) self.fake_snapd.snaps_result = [] self.useFixture(FakeOsRelease())
def test_autokeep(self): self.fake_apt_cache = fixture_setup.FakeAptCache() self.useFixture(self.fake_apt_cache) self.test_packages = ('main-package', 'dependency', 'sub-dependency', 'conflicting-dependency') self.fake_apt_cache.add_packages(self.test_packages) self.fake_apt_cache.cache['main-package'].dependencies = [[ fixture_setup.FakeAptBaseDependency( 'dependency', [self.fake_apt_cache.cache['dependency']]), fixture_setup.FakeAptBaseDependency( 'conflicting-dependency', [self.fake_apt_cache.cache['conflicting-dependency']]), ]] self.fake_apt_cache.cache['dependency'].dependencies = [[ fixture_setup.FakeAptBaseDependency( 'sub-dependency', [self.fake_apt_cache.cache['sub-dependency']]), ]] self.fake_apt_cache.cache['conflicting-dependency'].conflicts = [ self.fake_apt_cache.cache['dependency'] ] project_options = snapcraft.ProjectOptions() ubuntu = repo.Ubuntu(self.tempdir, project_options=project_options) ubuntu.get(['main-package', 'conflicting-dependency']) # Verify that the package was actually fetched and copied into the # requested location. self.assertThat( os.path.join(self.tempdir, 'download', 'main-package.deb'), FileExists()) self.assertThat( os.path.join(self.tempdir, 'download', 'conflicting-dependency.deb'), FileExists()) self.assertThat( os.path.join(self.tempdir, 'download', 'dependency.deb'), Not(FileExists()), 'Dependency should not have been fetched') self.assertThat( os.path.join(self.tempdir, 'download', 'sub-dependency.deb'), Not(FileExists()), 'Sub-dependency should not have been fetched')
def setUp(self): super().setUp() self.fake_apt_cache = fixture_setup.FakeAptCache() self.useFixture(self.fake_apt_cache)