def __init__(self, repo_id='faker', arches=('amd64', 'x86', 'arm', 'arm64')): config = RepoConfig('nonexistent') object.__setattr__(config, 'raw_known_arches', frozenset(arches)) pkgs = [ FakePkg('app-arch/bzip2-1.0.1-r1', repo=self, data={'SLOT': '0'}, keywords=('x86', )), FakePkg('app-arch/bzip2-1.0.5-r2', repo=self, data={'SLOT': '0'}, keywords=('x86', )), FakePkg('sys-apps/coreutils-8.25', repo=self, data={'SLOT': '0'}), FakePkg('x11-libs/gtk+-2.24', repo=self, data={'SLOT': '2'}, keywords=('amd64', )), FakePkg('x11-libs/gtk+-3.22', repo=self, data={'SLOT': '3'}, keywords=('amd64', 'x86')), ] super().__init__(repo_id=repo_id, pkgs=pkgs, config=config)
def fake_repo(): pkgs = [ FakePkg('app-arch/bzip2-1.0.1-r1', slot='0'), FakePkg('app-arch/bzip2-1.0.5-r2', slot='0'), FakePkg('sys-apps/coreutils-8.25', slot='0'), FakePkg('x11-libs/gtk+-2.24', slot='2'), FakePkg('x11-libs/gtk+-3.22', slot='3'), ] repo = FakeRepo(repo_id='gentoo', pkgs=pkgs) return repo
def test_glob(self): self.assertRaises(errors.MalformedAtom, self.kls, "dev-util/diffball-1*") self.assertRaises(errors.MalformedAtom, self.kls, "dev-util/diffball-1.*") a = self.kls("=dev-util/diffball-1.2*") self.assertMatch(a, FakePkg("dev-util/diffball-1.2")) self.assertMatch(a, FakePkg("dev-util/diffball-1.2.0")) self.assertMatch(a, FakePkg("dev-util/diffball-1.2-r1")) self.assertMatch(a, FakePkg("dev-util/diffball-1.2_alpha")) self.assertNotMatch(a, FakePkg("dev-util/diffball-1"))
def mk_check(self, pkgs=(), **kwargs): # TODO: switch to using a repo fixture when available repo_dir = pjoin(self.dir, misc.random_str()) os.makedirs(pjoin(repo_dir, 'metadata')) with open(pjoin(repo_dir, 'metadata', 'layout.conf'), 'w') as f: f.write('masters =\n') os.makedirs(pjoin(repo_dir, 'profiles', 'updates')) with open(pjoin(repo_dir, 'profiles', 'repo_name'), 'w') as f: f.write('fake\n') for filename, updates in kwargs.items(): with open(pjoin(repo_dir, 'profiles', 'updates', filename), 'w') as f: f.write('\n'.join(updates)) for pkg in pkgs: pkg = FakePkg(pkg) pkg_path = pjoin(repo_dir, pkg.category, pkg.package, f'{pkg.package}-{pkg.fullver}.ebuild') os.makedirs(os.path.dirname(pkg_path), exist_ok=True) with open(pkg_path, 'w') as f: f.write('SLOT=0\n') options = misc.Options(target_repo=UnconfiguredTree(repo_dir)) return self.check_kls(options)
def mk_pkg(self, license='', iuse=''): return FakePkg('dev-util/diffball-2.7.1', data={ 'LICENSE': license, 'IUSE': iuse }, repo=self.repo)
def test_collision_slotted(self): pkgs = [ FakePkg('foo/bar-1.0.1', slot='0'), FakePkg('foo/bar-2.0.2', slot='2'), FakePkg('foon/bar-3.4.5', slot='0'), ] installed_pkgs = [ FakePkg('foo/bar-1.0.0', slot='0'), FakePkg('foo/bar-2.0.1', slot='2'), ] installed_repos = FakeRepo(pkgs=installed_pkgs) repo = FakeRepo(pkgs=pkgs) a = pmerge.parse_target(parse_match("bar:0"), repo, installed_repos) assert len(a) == 1 assert a[0].key == 'foo/bar' assert a[0].match(atom('foo/bar:0')) assert not a[0].match(atom('foo/bar:2'))
def mk_pkg(self, eapi="4", iuse="", required_use="", keywords="x86"): return FakePkg("dev-util/diffball-0.7.1", eapi=eapi, iuse=iuse.split(), data={ "REQUIRED_USE": required_use, "KEYWORDS": keywords })
def _setup(self): self.log_warning = profiles.ProfileWarning('profile warning') self.log_error = profiles.ProfileError('profile error') pkg = FakePkg('dev-libs/foo-0') self.commit_result = git.InvalidCommitMessage('no commit message', commit='8d86269bb4c7') self.category_result = metadata_xml.CatMissingMetadataXml('metadata.xml', pkg=pkg) self.package_result = pkgdir.InvalidPN(('bar', 'baz'), pkg=pkg) self.versioned_result = metadata.BadFilename(('0.tar.gz', 'foo.tar.gz'), pkg=pkg)
def check_it(self, sorter, vers, expected, iter_sort_target=False): pkgs = [FakePkg(f"d-b/a-{x}") for x in vers] if iter_sort_target: pkgs = [[x, []] for x in pkgs] pkgs = list(sorter(pkgs)) if iter_sort_target: pkgs = [x[0] for x in pkgs] self.assertEqual([int(x.fullver) for x in pkgs], expected)
def test_slot_operators_and_subslots(self): self.assertRaises(errors.MalformedAtom, self.kls, "sys-libs/db:*", eapi=4) self.kls("sys-libs/db:*", eapi=5) self.assertRaises(errors.MalformedAtom, self.kls, "sys-libs/db:=", eapi=4) self.kls("sys-libs/db:=", eapi=5) self.assertRaises(errors.MalformedAtom, self.kls, "sys-libs/db:==", eapi=5) self.assertRaises(errors.MalformedAtom, self.kls, "sys-libs/db:1=", eapi=4) self.assertRaises(errors.MalformedAtom, self.kls, "sys-libs/db:2/3.0=", eapi=4) self.assertRaises(errors.MalformedAtom, self.kls, "sys-libs/db:2/3.0", eapi=1) self.assertRaises(errors.MalformedAtom, self.kls, "sys-libs/db:/=", eapi=5) self.assertRaises(errors.MalformedAtom, self.kls, "sys-libs/db:/1=", eapi=5) self.assertRaises(errors.MalformedAtom, self.kls, "sys-libs/db:1/=", eapi=5) self.assertRaises(errors.MalformedAtom, self.kls, "sys-libs/db:*1/=", eapi=5) for subslot in ("/1.0", ""): self.assertRaises(errors.MalformedAtom, self.kls, "sys-libs/db:*4%s" % subslot, eapi=5) self.assertRaises(errors.MalformedAtom, self.kls, "sys-libs/db:4%s*" % subslot, eapi=5) self.assertRaises(errors.MalformedAtom, self.kls, "sys-libs/db:=4%s" % subslot, eapi=5) self.kls("sys-libs/db:4%s=" % subslot, eapi=5) self.kls("sys-libs/db:3.2%s=" % subslot, eapi=5) self.assertRaises(errors.MalformedAtom, self.kls, "sys-libs/db:4%s==" % subslot, eapi=5) def check_it(text, slot, subslot, operator): obj = self.kls("sys-libs/db%s" % text) self.assertEqual(obj.slot, slot) self.assertEqual(obj.subslot, subslot) self.assertEqual(obj.slot_operator, operator) check_it(":4", "4", None, None) check_it(":=", None, None, "=") check_it(":4=", "4", None, "=") check_it(":4/0.4=", "4", "0.4", "=") check_it(":*", None, None, "*") # Verify restrictions. self.assertMatch(self.kls("sys-libs/db:1="), FakePkg("sys-libs/db-1", slot="1")) self.assertMatch(self.kls("sys-libs/db:1/2="), FakePkg("sys-libs/db-1", slot="1", subslot="2")) self.assertNotMatch(self.kls("sys-libs/db:1/2.3="), FakePkg("sys-libs/db-1", slot="1", subslot="2")) self.assertNotMatch(self.kls("sys-libs/db:1/2.3="), FakePkg("sys-libs/db-1", slot="1")) self.assertMatch(self.kls("sys-libs/db:1a.2/2.3"), FakePkg("sys-libs/db-1", slot="1a.2", subslot="2.3"))
def test_repo_id(self): astr = "dev-util/bsdiff" c = FakePkg(f"{astr}-1", repo=FakeRepo(repo_id="gentoo-x86A_"), slot="0") self.assertMatch(self.kls(f"{astr}"), c) self.assertMatch(self.kls(f"{astr}::gentoo-x86A_"), c) self.assertMatch(self.kls(f"{astr}:0::gentoo-x86A_"), c) self.assertNotMatch(self.kls(f"{astr}::gentoo2"), c) self.assertRaises(errors.MalformedAtom, self.kls, "dev-util/foon:1:") self.assertRaises(errors.MalformedAtom, self.kls, "dev-util/foon::") self.assertRaises(errors.MalformedAtom, self.kls, "dev-util/foon::-gentoo-x86") self.assertRaises(errors.MalformedAtom, self.kls, "dev-util/foon:::") for x in range(0, 3): self.assertRaises(errors.MalformedAtom, self.kls, "dev-util/foon::gentoo-x86", eapi=str(x))
def test_repo_id(self): astr = "dev-util/bsdiff" c = FakePkg("%s-1" % astr, repo=FakeRepo(repo_id="gentoo-x86A_"), slot="0") self.assertMatch(self.kls("%s" % astr), c) self.assertMatch(self.kls("%s::gentoo-x86A_" % astr), c) self.assertMatch(self.kls("%s:0::gentoo-x86A_" % astr), c) self.assertNotMatch(self.kls("%s::gentoo2" % astr), c) self.assertRaises(errors.MalformedAtom, self.kls, "dev-util/foon:1:") self.assertRaises(errors.MalformedAtom, self.kls, "dev-util/foon::") self.assertRaises(errors.MalformedAtom, self.kls, "dev-util/foon::-gentoo-x86") self.assertRaises(errors.MalformedAtom, self.kls, "dev-util/foon:::") for x in xrange(0, 3): self.assertRaises(errors.MalformedAtom, self.kls, "dev-util/foon::gentoo-x86", eapi=x)
def test_slot(self): astr = "dev-util/confcache" c = FakePkg("%s-1" % astr, slot=1) self.assertNotMatch(self.kls("%s:0" % astr), c) self.assertMatch(self.kls("%s:1" % astr), c) self.assertNotMatch(self.kls("%s:2" % astr), c) # note the above isn't compliant with eapi2/3; thus this test self.assertRaises(errors.MalformedAtom, self.kls, "dev-util/foo:0", eapi=0) # shouldn't puke, but has, thus checking" self.kls("sys-libs/db:4.4") self.kls("%s:azAZ.-+_09" % astr) self.kls("%s:_bar" % astr) # According to PMS, underscore and plus-sign are self.kls("%s:+bar" % astr) # not invalid first chars in a slot dep self.assertRaises(errors.MalformedAtom, self.kls, "dev-util/foo:") self.assertRaises(errors.MalformedAtom, self.kls, "dev-util/foo:1,,0") self.assertRaises(errors.MalformedAtom, self.kls, "dev-util/foo:1:") self.assertRaises(errors.MalformedAtom, self.kls, "dev-util/foo:-1") self.assertRaises(errors.MalformedAtom, self.kls, "dev-util/foo:.1") self.assertRaises(errors.MalformedAtom, self.kls, "dev-util/foo:1@2")
def test_parser(self): if compatibility.is_py3k: self.assertError( 'the following arguments are required: <atom|ebuild>, phase') self.assertError('the following arguments are required: phase', 'dev-util/diffball') else: self.assertError('too few arguments') self.assertError('too few arguments', 'dev-util/diffball') self.assertError("no matches: 'foo/bar'", 'foo/bar', 'baz', 'spork', domain=domain_config) # select highest version of a package with multiple versions config = self.parse('app-arch/bzip2', 'baz', 'spork', domain=domain_config) self.assertEqual(config.pkg, FakePkg('app-arch/bzip2-1.0.5-r2')) # packages with multiple slots require a specific slot selection self.assertError("please refine your restriction to one match", 'x11-libs/gtk+', 'baz', 'spork', domain=domain_config) # working initialization config = self.parse('sys-apps/coreutils', 'bar', 'baz', domain=domain_config) self.assertEqual(config.phase, ['bar', 'baz'])
def mk_pkg(self, eapi="4", iuse="", required_use=""): return FakePkg("dev-util/diffball-0.7.1", eapi=eapi, iuse=iuse.split(), data={"REQUIRED_USE": required_use})
def test_combined(self): p = FakePkg('dev-util/diffball-0.7', repo=FakeRepo(repo_id='gentoo')) self.assertMatch(self.kls('=dev-util/diffball-0.7::gentoo'), p) self.assertMatch(self.kls('dev-util/diffball::gentoo'), p) self.assertNotMatch(self.kls('=dev-util/diffball-0.7:1::gentoo'), FakePkg('dev-util/diffball-0.7', slot='2'))
def test_compatibility(self): self.assertNotMatch(self.kls('=dev-util/diffball-0.7'), FakePkg('dev-util/diffball-0.7.0')) # see bug http://bugs.gentoo.org/152127 self.assertNotMatch(self.kls('>=sys-apps/portage-2.1.0_pre3-r5'), FakePkg('sys-apps/portage-2.1_pre3-r5'))
def check_use(self, eapi, defaults=False): astr = "dev-util/bsdiff" c = FakePkg("%s-1" % astr, use=("debug",), iuse=("debug", "foon"), slot=1) kls = partial(self.kls, eapi=eapi) # Valid chars: [a-zA-Z0-9_@+-] kls('%s[zZaA09]' % astr) kls('%s[x@y]' % astr) kls('%s[x+y]' % astr) kls('%s[x-y]' % astr) kls('%s[x_y]' % astr) kls('%s[-x_y]' % astr) kls('%s[x?]' % astr) kls('%s[!x?]' % astr) kls('%s[x=]' % astr) kls('%s[!x=]' % astr) if defaults: kls('%s[x(+)]' % astr) kls('%s[x(-)]' % astr) self.assertRaises(errors.MalformedAtom, kls, '%s[x(+-)]' % astr) self.assertRaises(errors.MalformedAtom, kls, '%s[x(@)]' % astr) self.assertMatch(kls("%s[debug(+)]" % astr), c) self.assertMatch(kls("%s[debug(-)]" % astr), c) self.assertMatch(kls("%s[missing(+)]" % astr), c) self.assertNotMatch(kls("%s[missing(-)]" % astr), c) self.assertMatch(kls("%s[missing(+)]" % astr), c) self.assertMatch(kls("%s[-missing(-)]" % astr), c) self.assertNotMatch(kls("%s[-missing(+)]" % astr), c) self.assertMatch(kls("%s[-missing(-),debug]" % astr), c) self.assertNotMatch(kls("%s[-missing(+),debug(+)]" % astr), c) self.assertMatch(kls("%s[missing(+),debug(+)]" % astr), c) else: self.assertRaises(errors.MalformedAtom, kls, '%s[x(+)]' % astr) self.assertRaises(errors.MalformedAtom, kls, '%s[x(-)]' % astr) # '.' not a valid char in use deps self.assertRaises(errors.MalformedAtom, kls, "%s[x.y]" % astr) # Use deps start with an alphanumeric char (non-transitive) self.assertRaises(errors.MalformedAtom, kls, "%s[@x]" % astr) self.assertRaises(errors.MalformedAtom, kls, "%s[_x]" % astr) self.assertRaises(errors.MalformedAtom, kls, "%s[+x]" % astr) self.assertRaises(errors.MalformedAtom, kls, "%s[-@x]" % astr) self.assertRaises(errors.MalformedAtom, kls, "%s[-_x]" % astr) self.assertRaises(errors.MalformedAtom, kls, "%s[-+x]" % astr) self.assertRaises(errors.MalformedAtom, kls, "%s[--x]" % astr) self.assertMatch(kls("%s[debug]" % astr), c) self.assertNotMatch(kls("%s[-debug]" % astr), c) self.assertMatch(kls("%s[debug,-not]" % astr), c) self.assertMatch(kls("%s:1[debug,-not]" % astr), c) self.assertRaises(errors.MalformedAtom, kls, "%s[]" % astr) self.assertRaises(errors.MalformedAtom, kls, "%s[-]" % astr) self.assertRaises(errors.MalformedAtom, kls, "dev-util/diffball[foon") self.assertRaises(errors.MalformedAtom, kls, "dev-util/diffball[[fo]") self.assertRaises(errors.MalformedAtom, kls, "dev-util/diffball[x][y]") self.assertRaises(errors.MalformedAtom, kls, "dev-util/diffball[x]:1") self.assertRaises(errors.MalformedAtom, kls, "dev-util/diffball[x]a") self.assertRaises(errors.MalformedAtom, kls, "dev-util/diffball[--]") self.assertRaises(errors.MalformedAtom, kls, "dev-util/diffball[x??]") self.assertRaises(errors.MalformedAtom, kls, "dev-util/diffball[x=?]") self.assertRaises(errors.MalformedAtom, kls, "dev-util/diffball[x?=]") self.assertRaises(errors.MalformedAtom, kls, "dev-util/diffball[x==]") self.assertRaises(errors.MalformedAtom, kls, "dev-util/diffball[x??]") self.assertRaises(errors.MalformedAtom, kls, "dev-util/diffball[!=]") self.assertRaises(errors.MalformedAtom, kls, "dev-util/diffball[!?]") self.assertRaises(errors.MalformedAtom, kls, "dev-util/diffball[!!x?]") self.assertRaises(errors.MalformedAtom, kls, "dev-util/diffball[!-x?]")