Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_init(self):
self.assertEqual(len(self.all), len(contents.contentsSet(self.all)))
self.assertRaises(TypeError, contents.contentsSet, self.all + [1])
contents.contentsSet(self.all)
contents.contentsSet(self.all, mutable=True)
# test to ensure no one screwed up the optional initials
# making it mandatory
self.assertEqual(len(contents.contentsSet()), 0)
def test_prepend_inherit(self):
manager = central.ConfigManager([{
'sect': basics.HardCodedConfigSection({
'inherit.prepend': ['self']})}])
self.check_error(
"Collapsing section named 'sect':\n"
'Prepending or appending to the inherit list makes no sense',
manager.collapse_named_section, 'sect')
def test_init(self):
with pytest.raises(base.UriError):
base.GenericSyncer('/', 'seriouslynotaprotocol://blah/')
syncer = base.GenericSyncer('/', f'tar+https://blah.tar.gz')
assert tar.tar_syncer is syncer.__class__
def test_init(self):
base.test_init(self)
mkobj = self.make_obj
self.assertRaises(TypeError, mkobj, major=-1, strict=True)
self.assertRaises(TypeError, mkobj, minor=-1, strict=True)
self.assertEqual(mkobj(major=1).major, 1)
self.assertEqual(mkobj(minor=1).minor, 1)
class Test_fsFifo(TestCase, base):
kls = fs.fsFifo
class Test_fsDir(TestCase, base):
kls = fs.fsDir
class Test_Modules_Funcs(TestCase):
def test_is_funcs(self):
# verify it intercepts the missing attr
self.assertFalse(fs.isdir(object()))
self.assertFalse(fs.isreg(object()))
self.assertFalse(fs.isfifo(object()))
self.assertTrue(fs.isdir(fs.fsDir('/tmp', strict=False)))
self.assertFalse(fs.isreg(fs.fsDir('/tmp', strict=False)))
self.assertTrue(fs.isreg(fs.fsFile('/tmp', strict=False)))
def test_it(self):
orig = contentsSet([
fs.fsFile('/cheddar', strict=False),
fs.fsFile('/sporks-suck', strict=False),
fs.fsDir('/foons-rule', strict=False),
fs.fsDir('/mango', strict=False)
])
engine = fake_engine(mode=const.INSTALL_MODE)
def run(func):
new = contentsSet(orig)
self.kls(func)(engine, {'new_cset':new})
return new
self.assertEqual(orig, run(lambda s:False))
self.assertEqual([], run(post_curry(isinstance, fs.fsDir)).dirs())
self.assertEqual(sorted(orig.files()),
sorted(run(post_curry(isinstance, fs.fsDir)).dirs(True)))
# check noisyness.
info = []
engine = fake_engine(observer=make_fake_reporter(info=info.append),
def test_it(self):
orig = contentsSet([
fs.fsFile('/cheddar', strict=False),
fs.fsFile('/sporks-suck', strict=False),
fs.fsDir('/foons-rule', strict=False),
fs.fsDir('/mango', strict=False)
])
engine = fake_engine(mode=const.INSTALL_MODE)
def run(func):
new = contentsSet(orig)
self.kls(func)(engine, {'new_cset':new})
return new
self.assertEqual(orig, run(lambda s:False))
self.assertEqual([], run(post_curry(isinstance, fs.fsDir)).dirs())
self.assertEqual(sorted(orig.files()),
sorted(run(post_curry(isinstance, fs.fsDir)).dirs(True)))
# check noisyness.
info = []
engine = fake_engine(observer=make_fake_reporter(info=info.append),
mode=const.REPLACE_MODE)
run(lambda s:False)
self.assertFalse(info)
run(post_curry(isinstance, fs.fsDir))
self.assertEqual(len(info), 2)
# ensure only the relevant files show.
self.assertNotIn('/cheddar', ' '.join(info))
self.assertNotIn('/sporks-suck', ' '.join(info))
def test_it(self):
o = fs.fsDir(pjoin(self.dir, "mkdir_test"), strict=False)
self.assertTrue(ops.default_mkdir(o))
old_umask = os.umask(0)
try:
self.assertEqual((os.stat(o.location).st_mode & 0o4777), 0o777 & ~old_umask)
finally:
os.umask(old_umask)
os.rmdir(o.location)
o = fs.fsDir(pjoin(self.dir, "mkdir_test2"), strict=False, mode=0o750)
self.assertTrue(ops.default_mkdir(o))
self.assertEqual(os.stat(o.location).st_mode & 0o4777, 0o750)
self.assertRaises(profiles.ProfileError, getattr, self.klass(path),
attr)
# verify collapsing optimizations
self.write_file(filename, "dev-util/foo X\ndev-util/foo X")
self.assertEqualChunks(getattr(self.klass(path), attr),
{"dev-util/foo":(chunked_data(atom("dev-util/foo"), (), ('X',)),)})
self.write_file(filename, "d-u/a X\n=d-u/a-1 X")
self.assertEqualChunks(getattr(self.klass(path), attr),
{"d-u/a":(chunked_data(atom("d-u/a"), (), ('X',)),)})
self.write_file(filename, "d-u/a X\n=d-u/a-1 -X")
self.assertEqualChunks(getattr(self.klass(path), attr),
{"d-u/a":(chunked_data(atom("d-u/a"), (), ('X',)),
chunked_data(atom("=d-u/a-1"), ('X',), ()),)})
self.write_file(filename, "=d-u/a-1 X\nd-u/a X")
self.assertEqualChunks(getattr(self.klass(path), attr),
{"d-u/a":(chunked_data(atom("d-u/a"), (), ('X',)),)})
self.write_file(filename, "dev-util/bar -X\ndev-util/foo X")
self.assertEqualChunks(getattr(self.klass(path), attr),
{"dev-util/bar":(chunked_data(atom("dev-util/bar"), ('X',), ()),),
"dev-util/foo":(chunked_data(atom("dev-util/foo"), (), ('X',)),)})
self.wipe_path(pjoin(path, filename))
a2 = atom("dev-util/diffball")
self.assertEqual(
sorted(vrepo.itermatch(a)), sorted(repo.itermatch(a)))
self.assertEqual(sorted(vrepo.itermatch(a2)), sorted([]))
repo, vrepo = self.setup_repos(atom("=dev-util/diffball-1.0"))
self.assertEqual(
sorted(vrepo.itermatch(a)), sorted(repo.itermatch(a)))
self.assertEqual(
sorted(vrepo.itermatch(a2)),
sorted([VersionedCPV("dev-util/diffball-0.7")]))
repo, vrepo = self.setup_repos(packages.PackageRestriction(
"package", values.OrRestriction(
*[values.StrExactMatch(x) for x in ("diffball", "fake")])))
self.assertEqual(
sorted(vrepo.itermatch(packages.AlwaysTrue)),
sorted(repo.itermatch(atom("dev-util/bsdiff"))))
# check sentinel value handling.
vrepo = filtered.tree(repo, a2, sentinel_val=True)
self.assertEqual(
sorted(x.cpvstr for x in vrepo),
sorted(['dev-util/diffball-0.7', 'dev-util/diffball-1.0']))
self.write_file(filename, "dev-util/foo X\ndev-util/foo X")
self.assertEqualChunks(getattr(self.klass(path), attr),
{"dev-util/foo":(chunked_data(atom("dev-util/foo"), (), ('X',)),)})
self.write_file(filename, "d-u/a X\n=d-u/a-1 X")
self.assertEqualChunks(getattr(self.klass(path), attr),
{"d-u/a":(chunked_data(atom("d-u/a"), (), ('X',)),)})
self.write_file(filename, "d-u/a X\n=d-u/a-1 -X")
self.assertEqualChunks(getattr(self.klass(path), attr),
{"d-u/a":(chunked_data(atom("d-u/a"), (), ('X',)),
chunked_data(atom("=d-u/a-1"), ('X',), ()),)})
self.write_file(filename, "=d-u/a-1 X\nd-u/a X")
self.assertEqualChunks(getattr(self.klass(path), attr),
{"d-u/a":(chunked_data(atom("d-u/a"), (), ('X',)),)})
self.write_file(filename, "dev-util/bar -X\ndev-util/foo X")
self.assertEqualChunks(getattr(self.klass(path), attr),
{"dev-util/bar":(chunked_data(atom("dev-util/bar"), ('X',), ()),),
"dev-util/foo":(chunked_data(atom("dev-util/foo"), (), ('X',)),)})
self.wipe_path(pjoin(path, filename))