def test_lazy_unmount(self): src_file = pjoin(self.source, 'file') bind_file = pjoin(self.target, 'file') touch(src_file) with open(src_file, 'w') as f: f.write('foo') try: with Namespace(user=True, mount=True): mount(self.source, self.target, None, MS_BIND) assert os.path.exists(bind_file) with open(bind_file) as f: # can't unmount the target due to the open file with pytest.raises(OSError) as cm: umount(self.target) assert cm.value.errno == errno.EBUSY # lazily unmount instead umount(self.target, MNT_DETACH) # confirm the file doesn't exist in the bind mount anymore assert not os.path.exists(bind_file) # but the file is still accessible to the process assert f.read() == 'foo' # trying to reopen causes IOError with pytest.raises(IOError) as cm: f = open(bind_file) assert cm.value.errno == errno.ENOENT except PermissionError: pytest.skip('No permission to use user and mount namespace')
def test_categories_packages(self): ensure_dirs(pjoin(self.dir, 'cat', 'pkg')) ensure_dirs(pjoin(self.dir, 'empty', 'empty')) ensure_dirs(pjoin(self.dir, 'scripts', 'pkg')) ensure_dirs(pjoin(self.dir, 'notcat', 'CVS')) touch(pjoin(self.dir, 'cat', 'pkg', 'pkg-3.ebuild')) repo = self.mk_tree(self.dir) self.assertEqual({ 'cat': (), 'notcat': (), 'empty': () }, dict(repo.categories)) self.assertEqual({ 'cat': ('pkg', ), 'empty': ('empty', ), 'notcat': () }, dict(repo.packages)) self.assertEqual({ ('cat', 'pkg'): ('3', ), ('empty', 'empty'): () }, dict(repo.versions)) for x in ("1-scm", "scm", "1-try", "1_beta-scm", "1_beta-try"): for rev in ("", "-r1"): fp = pjoin(self.dir, 'cat', 'pkg', 'pkg-%s%s.ebuild' % (x, rev)) open(fp, 'w').close() repo = self.mk_tree(self.dir) self.assertRaises(ebuild_errors.InvalidCPV, repo.match, atom('cat/pkg')) repo = self.mk_tree(self.dir, ignore_paludis_versioning=True) self.assertEqual( sorted(x.cpvstr for x in repo.itermatch(atom('cat/pkg'))), ['cat/pkg-3']) os.unlink(fp)
def test_updates_eapi8(self): # empty file updates_path = os.path.join(self.profiles_base, 'updates') updates_file_path = os.path.join(updates_path, '2021.1') os.makedirs(updates_path) touch(updates_file_path) with open(os.path.join(self.profiles_base, 'eapi'), 'w') as f: f.write('8\n') repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.updates == {} del repo_config # simple pkg move # TODO: move pkg_updates content tests to its own module with open(updates_file_path, 'w') as f: f.write('move cat1/pkg1 cat2/pkg1\n') repo_config = repo_objs.RepoConfig(self.repo_path) expected_updates = { 'cat1/pkg1': [('move', atom.atom('cat1/pkg1'), atom.atom('cat2/pkg1'))], } assert repo_config.updates == expected_updates del repo_config # extraneous file should be ignored extra_file_path = os.path.join(updates_path, '.frobnicate') with open(extra_file_path, 'w') as f: f.write('move cat1/pkg2 cat1/pkg3\n') repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.updates == expected_updates del repo_config
def test_raw_use_expand_desc(self): # nonexistent repo repo_config = repo_objs.RepoConfig('nonexistent') assert repo_config.raw_use_expand_desc == () del repo_config # empty file use_expand_desc_path = os.path.join(self.profiles_base, 'desc') os.makedirs(use_expand_desc_path) use_expand_desc_file = os.path.join(use_expand_desc_path, 'foo.desc') touch(use_expand_desc_file) repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.raw_use_expand_desc == () del repo_config # regular entries with open(use_expand_desc_file, 'w') as f: f.write( """ # copy # license foo - enable foo bar - add bar support baz - build using baz """) repo_config = repo_objs.RepoConfig(self.repo_path) assert 3 == len(repo_config.raw_use_expand_desc) del repo_config
def test_raw_known_arches(self): # nonexistent repo repo_config = repo_objs.RepoConfig('nonexistent') assert repo_config.raw_known_arches == frozenset() del repo_config # empty file os.mkdir(self.profiles_base) arches_path = os.path.join(self.profiles_base, 'arch.list') touch(arches_path) repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.raw_known_arches == frozenset() del repo_config # single entry with open(arches_path, 'w') as f: f.write('foo') repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.raw_known_arches == frozenset(['foo']) del repo_config # multiple entries with whitespaces and comments with open(arches_path, 'w') as f: f.write( """ amd64 x86 # prefix foo-bar """) repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.raw_known_arches == frozenset(['amd64', 'x86', 'foo-bar']) del repo_config
def test_raw_use_local_desc(self): # nonexistent repo repo_config = repo_objs.RepoConfig('nonexistent') assert repo_config.raw_use_local_desc == () del repo_config # empty file os.mkdir(self.profiles_base) use_local_desc_path = os.path.join(self.profiles_base, 'use.local.desc') touch(use_local_desc_path) repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.raw_use_local_desc == () del repo_config # regular entries with open(use_local_desc_path, 'w') as f: f.write( """ # copy # license cat/pkg1:foo1 - enable foo1 cat1/pkg2:foo2 - enable foo2 cat2/pkg3:bar3 - add bar3 support """) repo_config = repo_objs.RepoConfig(self.repo_path) assert 3 == len(repo_config.raw_use_local_desc) del repo_config
def test_licenses(self): licenses = ('GPL-2', 'GPL-3+', 'BSD') ensure_dirs(pjoin(self.dir, 'licenses')) for license in licenses: touch(pjoin(self.dir, 'licenses', license)) repo = self.mk_tree(self.dir) self.assertEqual(sorted(repo.licenses), sorted(licenses))
def test_single_invalid_ebuild(self): pkg = self.mk_pkg(category='sys-apps', package='invalid') touch(pjoin(os.path.dirname(pkg.path), 'invalid-0-foo.ebuild')) r = self.assertReport(self.mk_check(), [pkg]) assert isinstance(r, pkgdir.InvalidPN) assert r.ebuilds == ('invalid-0-foo',) assert 'invalid-0-foo' in str(r)
def add(self, file_path, msg='commit', commit=True, create=False, signoff=False): """Add a file and commit it to the repo.""" if create: touch(pjoin(self.path, file_path)) self.run(['git', 'add', file_path]) if commit: self.commit(msg, signoff)
def test_use_expand_desc(self): # nonexistent repo repo_config = repo_objs.RepoConfig('nonexistent') assert repo_config.use_expand_desc == {} del repo_config # empty file use_expand_desc_path = os.path.join(self.profiles_base, 'desc') os.makedirs(use_expand_desc_path) use_expand_desc_file = os.path.join(use_expand_desc_path, 'foo.desc') touch(use_expand_desc_file) repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.use_expand_desc == {'foo': ()} del repo_config # regular entries with open(use_expand_desc_file, 'w') as f: f.write(""" # copy # license bar - add bar support baz - build using baz """) repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.use_expand_desc == { 'foo': (('foo_bar', 'add bar support'), ('foo_baz', 'build using baz')) } del repo_config
def test_updates(self): # nonexistent repo repo_config = repo_objs.RepoConfig('nonexistent') assert repo_config.updates == {} del repo_config # empty file updates_path = os.path.join(self.profiles_base, 'updates') updates_file_path = os.path.join(updates_path, '1Q-2019') os.makedirs(updates_path) touch(updates_file_path) repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.updates == {} del repo_config # simple pkg move # TODO: move pkg_updates content tests to its own module with open(updates_file_path, 'w') as f: f.write('move cat1/pkg1 cat2/pkg1\n') repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.updates == { 'cat1/pkg1': [('move', atom.atom('cat1/pkg1'), atom.atom('cat2/pkg1'))], } del repo_config
def test_arches_desc(self): # nonexistent repo repo_config = repo_objs.RepoConfig('nonexistent') empty = {'stable': set(), 'transitional': set(), 'testing': set()} assert repo_config.arches_desc == ImmutableDict(empty) del repo_config # empty file os.mkdir(self.profiles_base) arches_desc_path = os.path.join(self.profiles_base, 'arches.desc') touch(arches_desc_path) repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.arches_desc == ImmutableDict(empty) del repo_config # regular entries with open(os.path.join(self.profiles_base, 'arch.list'), 'w') as f: f.write(""" amd64 alpha foo """) with open(arches_desc_path, 'w') as f: f.write(""" # arches.desc file amd64 stable alpha testing """) repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.arches_desc['stable'] == {'amd64'} assert repo_config.arches_desc['testing'] == {'alpha'} assert repo_config.arches_desc['transitional'] == set() del repo_config
def test_executable_ebuild(self): pkg = self.mk_pkg() touch(pkg.path, mode=0o777) r = self.assertReport(self.mk_check(), [pkg]) assert isinstance(r, pkgdir.ExecutableFile) assert r.filename == os.path.basename(pkg.path) assert os.path.basename(pkg.path) in str(r)
def test_raw_use_local_desc(self): # nonexistent repo repo_config = repo_objs.RepoConfig('nonexistent') assert repo_config.raw_use_local_desc == () del repo_config # empty file os.mkdir(self.profiles_base) use_local_desc_path = os.path.join(self.profiles_base, 'use.local.desc') touch(use_local_desc_path) repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.raw_use_local_desc == () del repo_config # regular entries with open(use_local_desc_path, 'w') as f: f.write(""" # copy # license cat/pkg1:foo1 - enable foo1 cat1/pkg2:foo2 - enable foo2 cat2/pkg3:bar3 - add bar3 support """) repo_config = repo_objs.RepoConfig(self.repo_path) assert 3 == len(repo_config.raw_use_local_desc) del repo_config
def test_single_mismatched_ebuild(self): pkg = self.mk_pkg() touch(pjoin(os.path.dirname(pkg.path), 'mismatched-0.ebuild')) r = self.assertReport(self.mk_check(), [pkg]) assert isinstance(r, pkgdir.MismatchedPN) assert r.ebuilds == ('mismatched-0',) assert 'mismatched-0' in str(r)
def test_raw_use_expand_desc(self): # nonexistent repo repo_config = repo_objs.RepoConfig('nonexistent') assert repo_config.raw_use_expand_desc == () del repo_config # empty file use_expand_desc_path = os.path.join(self.profiles_base, 'desc') os.makedirs(use_expand_desc_path) use_expand_desc_file = os.path.join(use_expand_desc_path, 'foo.desc') touch(use_expand_desc_file) repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.raw_use_expand_desc == () del repo_config # regular entries with open(use_expand_desc_file, 'w') as f: f.write(""" # copy # license foo - enable foo bar - add bar support baz - build using baz """) repo_config = repo_objs.RepoConfig(self.repo_path) assert 3 == len(repo_config.raw_use_expand_desc) del repo_config
def test_categories_packages(self): ensure_dirs(pjoin(self.dir, 'cat', 'pkg')) ensure_dirs(pjoin(self.dir, 'empty', 'empty')) ensure_dirs(pjoin(self.dir, 'scripts', 'pkg')) ensure_dirs(pjoin(self.dir, 'notcat', 'CVS')) touch(pjoin(self.dir, 'cat', 'pkg', 'pkg-3.ebuild')) repo = self.mk_tree(self.dir) self.assertEqual( {'cat': (), 'notcat': (), 'empty': ()}, dict(repo.categories)) self.assertEqual( {'cat': ('pkg',), 'empty': ('empty',), 'notcat': ()}, dict(repo.packages)) self.assertEqual( {('cat', 'pkg'): ('3',), ('empty', 'empty'): ()}, dict(repo.versions)) for x in ("1-scm", "scm", "1-try", "1_beta-scm", "1_beta-try"): for rev in ("", "-r1"): fp = pjoin(self.dir, 'cat', 'pkg', 'pkg-%s%s.ebuild' % (x, rev)) open(fp, 'w').close() repo = self.mk_tree(self.dir) self.assertRaises(ebuild_errors.InvalidCPV, repo.match, atom('cat/pkg')) repo = self.mk_tree(self.dir, ignore_paludis_versioning=True) self.assertEqual(sorted(x.cpvstr for x in repo.itermatch(atom('cat/pkg'))), ['cat/pkg-3']) os.unlink(fp)
def test_raw_known_arches(self): # nonexistent repo repo_config = repo_objs.RepoConfig('nonexistent') assert repo_config.raw_known_arches == frozenset() del repo_config # empty file os.mkdir(self.profiles_base) arches_path = os.path.join(self.profiles_base, 'arch.list') touch(arches_path) repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.raw_known_arches == frozenset() del repo_config # single entry with open(arches_path, 'w') as f: f.write('foo') repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.raw_known_arches == frozenset(['foo']) del repo_config # multiple entries with whitespaces and comments with open(arches_path, 'w') as f: f.write(""" amd64 x86 # prefix foo-bar """) repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.raw_known_arches == frozenset( ['amd64', 'x86', 'foo-bar']) del repo_config
def __init__(self, lockdir): self.gid = 250 self.lockfile = os.path.join(lockdir, '.catalyst_lock') ensure_dirs(lockdir) fileutils.touch(self.lockfile, mode=0o664) os.chown(self.lockfile, -1, self.gid) self.lock = osutils.FsLock(self.lockfile)
def test_not_executable(self): fp = os.path.join(self.dir, self.script) touch(fp) os.chmod(fp, 0o640) with pytest.raises(process.CommandNotFound): process.find_binary(self.script) with pytest.raises(process.CommandNotFound): process.find_binary(fp)
def test_set_times(self): fileutils.touch(self.path) orig_stat = os.stat(self.path) time.sleep(1) fileutils.touch(self.path) new_stat = os.stat(self.path) assert orig_stat.st_atime != new_stat.st_atime assert orig_stat.st_mtime != new_stat.st_mtime
def test_repo_name(self, caplog): # nonexistent file repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.repo_name is None del repo_config # empty file os.mkdir(os.path.dirname(self.metadata_path)) touch(self.metadata_path) repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.repo_name is None del repo_config # bad data formatting with open(self.metadata_path, 'w') as f: f.write('repo-name repo') repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.repo_name is None assert 'bash parse error' in caplog.text caplog.clear() del repo_config # bad data formatting + name with open(self.metadata_path, 'w') as f: f.write('foo bar\nrepo-name = repo0') repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.repo_name == 'repo0' assert 'bash parse error' in caplog.text caplog.clear() del repo_config # unset with open(self.metadata_path, 'w') as f: f.write('repo-name =') repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.repo_name == '' del repo_config # whitespace with open(self.metadata_path, 'w') as f: f.write('repo-name = \n') repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.repo_name == '' del repo_config # whitespace + name with open(self.metadata_path, 'w') as f: f.write('repo-name = repo \n') repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.repo_name == 'repo' del repo_config # regular name with open(self.metadata_path, 'w') as f: f.write('repo-name = repo1') repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.repo_name == 'repo1' del repo_config
def test_path_override(self): # check PATH override tempdir = tempfile.mkdtemp(dir=self.dir) fp = os.path.join(tempdir, self.script) touch(fp) os.chmod(fp, 0o750) with pytest.raises(process.CommandNotFound): process.find_binary(self.script) assert fp == process.find_binary(self.script, paths=[tempdir])
def _mk_ld_so_conf(self, fp): if not ensure_dirs(os.path.dirname(fp), mode=0o755, minimal=True): raise errors.BlockModification( self, f"failed creating/setting {fp} to 0755, root/root for uid/gid") try: touch(fp) except EnvironmentError as e: raise errors.BlockModification(self, e) from e
def test_file_creation(self): orig_um = os.umask(0o000) try: fileutils.touch(self.path) finally: exiting_umask = os.umask(orig_um) assert exiting_umask == 0o000 assert os.path.exists(self.path) assert os.stat(self.path).st_mode & 0o4777 == 0o644
def test_set_times(self): fp = pjoin(self.dir, 'file') fileutils.touch(fp) orig_stat = os.stat(fp) time.sleep(1) fileutils.touch(fp) new_stat = os.stat(fp) self.assertNotEqual(orig_stat.st_atime, new_stat.st_atime) self.assertNotEqual(orig_stat.st_mtime, new_stat.st_mtime)
def test_set_custom_times(self): fileutils.touch(self.path) orig_stat = os.stat(self.path) times = (1, 1) fileutils.touch(self.path, times=times) new_stat = os.stat(self.path) assert orig_stat != new_stat assert 1 == new_stat.st_atime assert 1 == new_stat.st_mtime
def test_set_times(self): fp = pjoin(self.dir, "file") fileutils.touch(fp) orig_stat = os.stat(fp) time.sleep(1) fileutils.touch(fp) new_stat = os.stat(fp) self.assertNotEqual(orig_stat.st_atime, new_stat.st_atime) self.assertNotEqual(orig_stat.st_mtime, new_stat.st_mtime)
def test_pms_repo_name(self): os.mkdir(self.profiles_base) repo_name_path = os.path.join(self.profiles_base, 'repo_name') # nonexistent file repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.pms_repo_name is None del repo_config # empty file touch(repo_name_path) repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.pms_repo_name == '' del repo_config # whitespace with open(repo_name_path, 'w') as f: f.write(' \n') repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.pms_repo_name == '' del repo_config # whitespace + name with open(repo_name_path, 'w') as f: f.write(' repo \n') repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.pms_repo_name == 'repo' del repo_config # regular name with open(repo_name_path, 'w') as f: f.write('newrepo') repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.pms_repo_name == 'newrepo' del repo_config # regular name EOLed with open(repo_name_path, 'w') as f: f.write('newrepo2\n') repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.pms_repo_name == 'newrepo2' del repo_config # multi-line with open(repo_name_path, 'w') as f: f.write('newrepo3\nfoobar') repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.pms_repo_name == 'newrepo3' del repo_config # binary data with open(repo_name_path, 'wb') as f: f.write(b'\x6e\x65\x77\x72\x65\x70\x6f\x34') repo_config = repo_objs.RepoConfig(self.repo_path) assert repo_config.pms_repo_name == 'newrepo4' del repo_config
def test_fallback(self): fp = pjoin(self.dir, 'file') # create the file touch(fp) os.chmod(fp, 000) assert not self.func(fp, os.X_OK) assert self.func(fp, os.W_OK) assert self.func(fp, os.R_OK) assert self.func(fp, os.W_OK | os.R_OK) assert not self.func(fp, os.W_OK | os.R_OK | os.X_OK)
def test_set_custom_times(self): fp = pjoin(self.dir, "file") fileutils.touch(fp) orig_stat = os.stat(fp) times = (1, 1) fileutils.touch(fp, times=times) new_stat = os.stat(fp) self.assertNotEqual(orig_stat, new_stat) self.assertEqual(1, new_stat.st_atime) self.assertEqual(1, new_stat.st_mtime)
def test_file_creation(self): fp = pjoin(self.dir, "file") orig_um = os.umask(0o000) try: fileutils.touch(fp) finally: exiting_umask = os.umask(orig_um) self.assertEqual(exiting_umask, 0o000) self.assertEqual(os.path.exists(fp), True) self.assertEqual(os.stat(fp).st_mode & 0o4777, 0o644)
def test_set_custom_times(self): fp = pjoin(self.dir, 'file') fileutils.touch(fp) orig_stat = os.stat(fp) times = (1, 1) fileutils.touch(fp, times=times) new_stat = os.stat(fp) self.assertNotEqual(orig_stat, new_stat) self.assertEqual(1, new_stat.st_atime) self.assertEqual(1, new_stat.st_mtime)
def test_file_creation(self): fp = pjoin(self.dir, 'file') orig_um = os.umask(0o000) try: fileutils.touch(fp) finally: exiting_umask = os.umask(orig_um) self.assertEqual(exiting_umask, 0o000) self.assertEqual(os.path.exists(fp), True) self.assertEqual(os.stat(fp).st_mode & 0o4777, 0o644)
def test_categories_packages(self): ensure_dirs(pjoin(self.dir, 'cat', 'pkg')) ensure_dirs(pjoin(self.dir, 'empty', 'empty')) touch(pjoin(self.dir, 'cat', 'pkg', 'pkg-3.ebuild')) repo = self.mk_tree(self.dir) assert {'cat': (), 'empty': ()} == dict(repo.categories) assert {'cat': ('pkg', ), 'empty': ('empty', )} == dict(repo.packages) assert { ('cat', 'pkg'): ('3', ), ('empty', 'empty'): () } == dict(repo.versions)
def test_licenses(self): master_licenses = ('GPL-2', 'GPL-3+', 'BSD') slave_licenses = ('BSD-2', 'MIT') ensure_dirs(pjoin(self.dir_slave, 'licenses')) ensure_dirs(pjoin(self.dir_master, 'licenses')) for license in master_licenses: touch(pjoin(self.dir_master, 'licenses', license)) for license in slave_licenses: touch(pjoin(self.dir_slave, 'licenses', license)) repo = self.mk_tree(self.dir) self.assertEqual(sorted(repo.licenses), sorted(master_licenses + slave_licenses))
def test_eapi(self, caplog): os.mkdir(self.profiles_base) eapi_path = os.path.join(self.profiles_base, 'eapi') # default EAPI repo_config = repo_objs.RepoConfig(self.repo_path) assert str(repo_config.eapi) == '0' del repo_config # empty file touch(eapi_path) repo_config = repo_objs.RepoConfig(self.repo_path) assert str(repo_config.eapi) == '0' del repo_config # whitespace content with open(eapi_path, 'w+') as f: f.write(' \n') repo_config = repo_objs.RepoConfig(self.repo_path) assert str(repo_config.eapi) == '0' del repo_config # unknown EAPI with open(eapi_path, 'w+') as f: f.write('unknown_eapi') with pytest.raises(repo_errors.UnsupportedRepo) as excinfo: repo_objs.RepoConfig(self.repo_path) assert isinstance(excinfo.value.repo, repo_objs.RepoConfig) # known EAPI with open(eapi_path, 'w+') as f: f.write('6') repo_config = repo_objs.RepoConfig(self.repo_path) assert str(repo_config.eapi) == '6' del repo_config # bad data, good EAPI with open(eapi_path, 'w+') as f: f.write('4\nfoo\nbar') repo_config = repo_objs.RepoConfig(self.repo_path) assert str(repo_config.eapi) == '4' assert 'multiple EAPI lines detected:' in caplog.text caplog.clear() del repo_config # bad data, unknown EAPI with open(eapi_path, 'w+') as f: f.write('eapi\nfoo\nbar') with pytest.raises(repo_errors.UnsupportedRepo) as excinfo: repo_objs.RepoConfig(self.repo_path) assert isinstance(excinfo.value.repo, repo_objs.RepoConfig) assert 'multiple EAPI lines detected:' in caplog.text caplog.clear()
def test_set_custom_nstimes(self): if not compatibility.is_py3k: raise SkipTest("requires py33 and up") fp = pjoin(self.dir, "file") fileutils.touch(fp) orig_stat = os.stat(fp) ns = (1, 1) fileutils.touch(fp, ns=ns) new_stat = os.stat(fp) self.assertNotEqual(orig_stat, new_stat) self.assertEqual(1, new_stat.st_atime_ns) self.assertEqual(1, new_stat.st_mtime_ns)
def base_dirs(self): if os.uname()[0] == "FreeBSD": # baselayout no longer creates the .keep files in proc and dev for FreeBSD as it # would create them too late...we need them earlier before bind mounting filesystems # since proc and dev are not writeable, so...create them here ensure_dirs(self.settings["stage_path"]+"/proc") ensure_dirs(self.settings["stage_path"]+"/dev") for f in ('/proc', '/dev'): f = self.settings['stage_path'] + f + '/.keep' if not os.path.isfile(f): try: fileutils.touch(f) except IOError: log.error('Failed to create %s', f)
def test_bind_mount(self): src_file = pjoin(self.source, 'file') bind_file = pjoin(self.target, 'file') touch(src_file) try: with Namespace(user=True, mount=True): assert not os.path.exists(bind_file) mount(self.source, self.target, None, MS_BIND) assert os.path.exists(bind_file) umount(self.target) assert not os.path.exists(bind_file) except PermissionError: pytest.skip('No permission to use user and mount namespace')
def test_categories_packages(self): ensure_dirs(pjoin(self.dir, 'cat', 'pkg')) ensure_dirs(pjoin(self.dir, 'empty', 'empty')) ensure_dirs(pjoin(self.dir, 'scripts', 'pkg')) ensure_dirs(pjoin(self.dir, 'notcat', 'CVS')) touch(pjoin(self.dir, 'cat', 'pkg', 'pkg-3.ebuild')) repo = self.mk_tree(self.dir) self.assertEqual( {'cat': (), 'notcat': (), 'empty': ()}, dict(repo.categories)) self.assertEqual( {'cat': ('pkg',), 'empty': ('empty',), 'notcat': ()}, dict(repo.packages)) self.assertEqual( {('cat', 'pkg'): ('3',), ('empty', 'empty'): ()}, dict(repo.versions))
def test_find_binary(self): script_name = "pkgcore-findpath-test.sh" self.assertRaises(process.CommandNotFound, process.find_binary, script_name) fp = os.path.join(self.dir, script_name) touch(fp) os.chmod(fp, 0o640) self.assertRaises(process.CommandNotFound, process.find_binary, script_name) self.assertRaises(process.CommandNotFound, process.find_binary, fp) os.chmod(fp, 0o750) self.assertIn(self.dir, process.find_binary(script_name)) self.assertIn(self.dir, process.find_binary(fp)) os.unlink(fp) # make sure dirs aren't returned as binaries self.assertRaises( process.CommandNotFound, process.find_binary, os.path.basename(self.dir), os.path.dirname(self.dir) ) self.assertRaises(process.CommandNotFound, process.find_binary, self.dir)
def enable(self, point, data=None): '''Sets the resume point 'ON' @param point: string. name of the resume point to enable @param data: string of information to store, or None @return boolean ''' if point in self._points and not data: return True fname = pjoin(self.basedir, point) if data: with open(fname,"w") as myf: myf.write(data) else: try: fileutils.touch(fname) self._points[point] = fname except Exception as e: log.error('AutoResumeError: %s', e) return False return True
def get_writable_fsobj(self, fsobj, prefer_reuse=True, empty=False): path = source = None if fsobj: source = fsobj.data if source.mutable: return fsobj if self.allow_reuse and prefer_reuse: path = source.path # XXX: this should be doing abspath fs intersection probably, # although the paths generated are from triggers/engine- still. if path is not None and not path.startswith(self.tempdir): # the fsobj pathway isn't in temp space; force a transfer. path = None if path: # ok, it's tempspace, and reusable. obj = data_source.local_source(path, True, encoding=source.encoding) if empty: obj.bytes_fileobj(True).truncate(0) return obj # clone it into tempspace; it's required we control the tempspace, # so this function is safe in our usage. fd, path = tempfile.mkstemp(prefix='merge-engine-', dir=self.tempdir) # XXX: annoying quirk of python, we don't want append mode, so 'a+' # isn't viable; wr will truncate the file, so data_source uses r+. # this however doesn't allow us to state "create if missing" # so we create it ourselves. Annoying, but so it goes. # just touch the filepath. touch(path) new_source = data_source.local_source( path, True, encoding=getattr(fsobj, 'encoding', None)) if source and not empty: data_source.transfer(source.bytes_fsobj(), new_source.bytes_fsobj(True)) return new_source
def test_path_is_a_file(self): # fail if passed a path to an existing file path = pjoin(self.dir, 'file') touch(path) assert os.path.isfile(path) assert not osutils.ensure_dirs(path, mode=0o700)
def test_non_dir_in_path(self): # fail if one of the parts of the path isn't a dir path = pjoin(self.dir, 'file', 'dir') touch(pjoin(self.dir, 'file')) assert not osutils.ensure_dirs(path, mode=0o700)
def setup(self): self.subdir = pjoin(self.dir, 'dir') os.mkdir(self.subdir) touch(pjoin(self.dir, 'file')) os.mkfifo(pjoin(self.dir, 'fifo'))
def test_path_restrict(self): repo_dir = pjoin(self.dir, 'repo') ensure_dirs(pjoin(repo_dir, 'profiles')) with open(pjoin(repo_dir, 'profiles', 'repo_name'), 'w') as f: f.write('testrepo\n') repo = self.mk_tree(repo_dir) ensure_dirs(pjoin(repo_dir, 'cat', 'foo')) ensure_dirs(pjoin(repo_dir, 'cat', 'bar')) ensure_dirs(pjoin(repo_dir, 'tac', 'oof')) touch(pjoin(repo_dir, 'skel.ebuild')) touch(pjoin(repo_dir, 'cat', 'foo', 'foo-1.ebuild')) touch(pjoin(repo_dir, 'cat', 'foo', 'foo-2.ebuild')) touch(pjoin(repo_dir, 'cat', 'foo', 'Manifest')) touch(pjoin(repo_dir, 'cat', 'bar', 'bar-1.ebuild')) touch(pjoin(repo_dir, 'tac', 'oof', 'oof-1.ebuild')) # specify repo category dirs with open(pjoin(repo_dir, 'profiles', 'categories'), 'w') as f: f.write('cat\n') f.write('tac\n') for path in (self.dir, # path not in repo pjoin(repo_dir, 'a'), # nonexistent category dir pjoin(repo_dir, 'profiles'), # non-category dir pjoin(repo_dir, 'skel.ebuild'), # not in the correct cat/PN dir layout pjoin(repo_dir, 'cat', 'a'), # nonexistent package dir pjoin(repo_dir, 'cat', 'foo', 'foo-0.ebuild'), # nonexistent ebuild file pjoin(repo_dir, 'cat', 'foo', 'Manifest')): # non-ebuild file self.assertRaises(ValueError, repo.path_restrict, path) # repo dir restriction = repo.path_restrict(repo_dir) self.assertEqual(len(restriction), 1) self.assertInstance(restriction[0], restricts.RepositoryDep) # matches all 4 ebuilds in the repo self.assertEqual(len(repo.match(restriction)), 4) # category dir restriction = repo.path_restrict(pjoin(repo_dir, 'cat')) self.assertEqual(len(restriction), 2) self.assertInstance(restriction[1], restricts.CategoryDep) # matches all 3 ebuilds in the category self.assertEqual(len(repo.match(restriction)), 3) # package dir restriction = repo.path_restrict(pjoin(repo_dir, 'cat', 'foo')) self.assertEqual(len(restriction), 3) self.assertInstance(restriction[2], restricts.PackageDep) # matches both ebuilds in the package dir self.assertEqual(len(repo.match(restriction)), 2) # ebuild file restriction = repo.path_restrict(pjoin(repo_dir, 'cat', 'foo', 'foo-1.ebuild')) self.assertEqual(len(restriction), 4) self.assertInstance(restriction[3], restricts.VersionMatch) # specific ebuild version match self.assertEqual(len(repo.match(restriction)), 1)
def test_found(self): fp = os.path.join(self.dir, self.script) touch(fp) os.chmod(fp, 0o750) assert fp == process.find_binary(self.script)