def test_matching(self): strexact = values.StrExactMatch args = malleable_obj(category="foon", package="dar") self.assertMatches(self.kls("category", strexact("foon")), args) self.assertMatches(self.kls("package", strexact("dar")), args) self.assertNotMatches( self.kls("package", strexact("dar"), negate=True), args) self.assertNotMatches(self.kls("package", strexact("foon")), args) self.assertMatches(self.kls("package", strexact("foon"), negate=True), args) excepts = [] # no msg should be thrown, it wasn't an unexpected exception log.logging.root.addHandler(callback_logger(excepts.append)) self.assertNotMatches(self.kls("foon", AlwaysSelfIntersect), args) self.assertFalse(excepts) self.assertMatches(self.kls("foon", AlwaysSelfIntersect, negate=True), args) self.assertFalse(excepts) class foo: def __getattr__(self, attr): if attr.startswith("exc"): raise exceptions_d.get(attr[4:], None)() raise AttributeError("monkey lover") exceptions_d = { "KeyboardInterrupt": KeyboardInterrupt, "RuntimeError": RuntimeError, "SystemExit": SystemExit } for mode in ("match", "force_True", "force_False"): excepts[:] = [] self.assertRaises( AttributeError, getattr(self.kls("foon", AlwaysSelfIntersect), mode), foo()) self.assertEqual(len(excepts), 1, msg=f"expected one exception, got {excepts!r}") # ensure various exceptions are passed through for k in (KeyboardInterrupt, RuntimeError, SystemExit): self.assertRaises( k, getattr(self.kls(f"exc_{k.__name__}", AlwaysSelfIntersect), mode), foo()) # check that it only does string comparison in exception catching. class foo: def __cmp__(self, other): raise TypeError def __getattr__(self, attr): raise AttributeError(self, attr) self.assertFalse(self.kls("foon", AlwaysSelfIntersect).match(foo()))
def test_matching(self): strexact = values.StrExactMatch args = malleable_obj(category="foon", package="dar") self.assertMatches(self.kls("category", strexact("foon")), args) self.assertMatches(self.kls("package", strexact("dar")), args) self.assertNotMatches(self.kls("package", strexact("dar"), negate=True), args) self.assertNotMatches(self.kls("package", strexact("foon")), args) self.assertMatches(self.kls("package", strexact("foon"), negate=True), args) excepts = [] # no msg should be thrown, it wasn't an unexpected exception log.logging.root.addHandler(callback_logger(excepts.append)) self.assertNotMatches(self.kls("foon", AlwaysSelfIntersect), args) self.assertFalse(excepts) self.assertMatches(self.kls("foon", AlwaysSelfIntersect, negate=True), args) self.assertFalse(excepts) class foo: def __getattr__(self, attr): if attr.startswith("exc"): raise exceptions_d.get(attr[4:], None)() raise AttributeError("monkey lover") exceptions_d = {"KeyboardInterrupt":KeyboardInterrupt, "RuntimeError":RuntimeError, "SystemExit":SystemExit} for mode in ("match", "force_True", "force_False"): excepts[:] = [] self.assertRaises(AttributeError, getattr(self.kls("foon", AlwaysSelfIntersect), mode), foo()) self.assertEqual( len(excepts), 1, msg=f"expected one exception, got {excepts!r}") # ensure various exceptions are passed through for k in (KeyboardInterrupt, RuntimeError, SystemExit): self.assertRaises( k, getattr(self.kls(f"exc_{k.__name__}", AlwaysSelfIntersect), mode), foo()) # check that it only does string comparison in exception catching. class foo: def __cmp__(self, other): raise TypeError def __getattr__(self, attr): raise AttributeError(self, attr) self.assertFalse(self.kls("foon", AlwaysSelfIntersect).match(foo()))
def test_subset_awareness2(self): callbacks = [] log.logging.root.handlers = [callback_logger(callbacks.append)] s = self.gen_pkgset("@world\ndev-util/bsdiff") self.assertEqual([str(x) for x in s], ['dev-util/bsdiff']) self.assertIn("set item 'world'", str(callbacks[0]))
def test_subset_awareness(self): callbacks = [] log.logging.root.handlers = [callback_logger(callbacks.append)] s = self.gen_pkgset("@world\ndev-util/bsdiff") self.assertRaises(ValueError, sorted, s)