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)) self.assertIn('/foons-rule', ' '.join(info)) self.assertIn('/mango', ' '.join(info))
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(orig.files(), run(post_curry(isinstance, fs.fsDir)).dirs(True)) # check noisyness. info = [] engine = fake_engine(observer=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)) self.assertIn('/foons-rule', ' '.join(info)) self.assertIn('/mango', ' '.join(info))
def test_register(self): engine = fake_engine(mode=1) self.assertRaises(TypeError, self.mk_trigger(mode=1).register, engine) self.assertRaises(TypeError, self.mk_trigger(mode=1, _hooks=2).register, engine) self.assertFalse(engine._triggers) # shouldn't puke. o = self.mk_trigger(mode=1, _hooks=("2")) o.register(engine) self.assertEqual(engine._triggers, [('2', o, None)]) engine._triggers = [] # verify it's treating "all csets" differently from "no csets" o = self.mk_trigger(mode=1, _hooks=("2"), required_csets=()) o.register(engine) self.assertEqual(engine._triggers, [('2', o, ())]) # should handle keyerror thrown from the engine for missing hooks. engine = fake_engine(mode=1, blocked_hooks=("foon", "dar")) self.mk_trigger(mode=1, _hooks="foon").register(engine) self.mk_trigger(mode=1, _hooks=("foon", "dar")).register(engine) self.assertFalse(engine._triggers) o = self.mk_trigger(mode=1, _hooks=("foon", "bar"), required_csets=(3,)) o.register(engine) self.assertEqual(engine._triggers, [('bar', o, (3,))]) engine._triggers = [] o = self.mk_trigger(mode=1, _hooks="bar", required_csets=None) o.register(engine) self.assertEqual(engine._triggers, [('bar', o, None)])
def test_register(self): engine = fake_engine(mode=1) self.assertRaises(TypeError, self.mk_trigger(mode=1).register, engine) self.assertRaises(TypeError, self.mk_trigger(mode=1, _hooks=2).register, engine) self.assertFalse(engine._triggers) # shouldn't puke. o = self.mk_trigger(mode=1, _hooks=("2")) o.register(engine) self.assertEqual(engine._triggers, [('2', o, None)]) engine._triggers = [] # verify it's treating "all csets" differently from "no csets" o = self.mk_trigger(mode=1, _hooks=("2"), required_csets=()) o.register(engine) self.assertEqual(engine._triggers, [('2', o, ())]) # should handle keyerror thrown from the engine for missing hooks. engine = fake_engine(mode=1, blocked_hooks=("foon", "dar")) self.mk_trigger(mode=1, _hooks="foon").register(engine) self.mk_trigger(mode=1, _hooks=("foon", "dar")).register(engine) self.assertFalse(engine._triggers) o = self.mk_trigger(mode=1, _hooks=("foon", "bar"), required_csets=(3, )) o.register(engine) self.assertEqual(engine._triggers, [('bar', o, (3, ))]) engine._triggers = [] o = self.mk_trigger(mode=1, _hooks="bar", required_csets=None) o.register(engine) self.assertEqual(engine._triggers, [('bar', o, None)])
def test_lazyness(self): # ensure it doesn't even look if it won't make noise, and no reporter # cset is intentionally *not* a contentset; it'll explode it it tries # to access it. self.kls().trigger(fake_engine(), None) # now verify that the explosion would occur if either settings are on. self.assertRaises((AttributeError, TypeError), self.kls().trigger, fake_engine(observer=object()), None) self.assertRaises((AttributeError, TypeError), self.kls(fix_perms=True).trigger, fake_engine(), None)
def test_get_replace_cset(self): files = contentsSet(self.simple_cset.iterfiles(invert=True)) engine = fake_engine(csets={ 'install': files, 'old_cset': self.simple_cset }) self.assertCsetEqual(files, self.run_cset('get_replace_cset', engine))
def get_csets(required_csets, csets, fallback=None): o = self.mk_trigger(required_csets={1:required_csets, 2:fallback}, mode=(1,)) engine = fake_engine(csets=csets, mode=1) o(engine, csets) self.assertEqual([x[0] for x in o._called], [engine]*len(o._called)) return [list(x[1:]) for x in o._called]
def test_observer_warn(self): warnings = [] engine = fake_engine(observer=make_fake_reporter(warn=warnings.append)) self._trigger_override = self.kls() def run(fs_objs, fix_perms=False): self.kls(fix_perms=fix_perms).trigger(engine, contentsSet(fs_objs)) run([fs.fsFile('/foon', mode=0770, strict=False)])
def test_observer_warn(self): warnings = [] engine = fake_engine(observer=fake_reporter(warn=warnings.append)) self._trigger_override = self.kls() def run(fs_objs, fix_perms=False): self.kls(fix_perms=fix_perms).trigger(engine, contentsSet(fs_objs)) run([fs.fsFile('/foon', mode=0770, strict=False)])
def test_generate_offset_cset(self): engine = fake_engine(csets={"new_cset":self.simple_cset}, offset='/') def run(engine, cset): return self.run_cset('generate_offset_cset', engine, lambda e, c:c[cset]) self.assertCsetEqual(self.simple_cset, run(engine, 'new_cset')) engine.offset = '/foon/' run(engine, 'new_cset') self.assertCsetEqual(self.simple_cset.insert_offset(engine.offset), run(engine, 'new_cset'))
def test__get_livefs_intersect_cset(self): old_cset = self.simple_cset.insert_offset(self.dir) # have to add it; scan adds the root node old_cset.add(fsDir(self.dir)) os.mkdir(pjoin(self.dir, "usr")) open(pjoin(self.dir, "usr", "dar"), 'w').close() open(pjoin(self.dir, 'foon'), 'w').close() # note that this *is* a sym in the cset; adding this specific # check so that if the code differs, the test breaks, and the tests # get updated (additionally, folks may not be aware of the potential) open(pjoin(self.dir, 'broken-symlink'), 'w').close() engine = fake_engine(csets={'test': old_cset}) existent = livefs.scan(self.dir) generated = self.run_cset('_get_livefs_intersect_cset', engine, 'test') self.assertEqual(generated, existent)
def test__get_livefs_intersect_cset(self): old_cset = self.simple_cset.insert_offset(self.dir) # have to add it; scan adds the root node old_cset.add(fsDir(self.dir)) os.mkdir(pjoin(self.dir, "usr")) open(pjoin(self.dir, "usr", "dar"), 'w').close() open(pjoin(self.dir, 'foon'), 'w').close() # note that this *is* a sym in the cset; adding this specific # check so that if the code differs, the test breaks, and the tests # get updated (additionally, folks may not be aware of the potential) open(pjoin(self.dir, 'broken-symlink'), 'w').close() engine = fake_engine(csets={'test':old_cset}) existent = livefs.scan(self.dir) generated = self.run_cset('_get_livefs_intersect_cset', engine, 'test') self.assertEqual(generated, existent)
def assertContents(self, cset=()): orig = sorted(cset) new = contentsSet(orig) self.trigger(fake_engine(mode=const.INSTALL_MODE), {'new_cset': new}) new = sorted(new) self.assertEqual(len(orig), len(new)) for x, y in izip(orig, new): self.assertEqual(orig.__class__, new.__class__) for attr in x.__attrs__: if self.attr == attr: val = getattr(x, attr) if self.bad_val is not None and val == self.bad_val: self.assertEqual(self.good_val(val), getattr(y, attr)) else: self.assertEqual(self.good_val(val), getattr(y, attr)) elif attr != 'chksums': # abuse self as unique singleton. self.assertEqual(getattr(x, attr, self), getattr(y, attr, self))
def assertContents(self, cset=()): orig = sorted(cset) new = contentsSet(orig) self.trigger(fake_engine(mode=const.INSTALL_MODE), {'new_cset':new}) new = sorted(new) self.assertEqual(len(orig), len(new)) for x, y in izip(orig, new): self.assertEqual(orig.__class__, new.__class__) for attr in x.__attrs__: if self.attr == attr: val = getattr(x, attr) if self.bad_val is not None and val == self.bad_val: self.assertEqual(self.good_val(val), getattr(y, attr)) else: self.assertEqual(self.good_val(val), getattr(y, attr)) elif attr != 'chksums': # abuse self as unique singleton. self.assertEqual(getattr(x, attr, self), getattr(y, attr, self))
def reset_objects(self, mode=const.INSTALL_MODE): self.engine = fake_engine(offset=self.dir, mode=mode) self.trigger = self.kls()
def test_get_replace_cset(self): files = contentsSet(self.simple_cset.iterfiles(invert=True)) engine = fake_engine(csets={'install':files, 'old_cset':self.simple_cset}) self.assertCsetEqual(files, self.run_cset('get_replace_cset', engine))