def test_50_set_orig_error_handler(self): # Set the error handler back to the default handler. # The error message is now visible (but we cannot test that). self.__class__.handler["previous"] = LG_Error.set_handler(self.__class__.handler["default"]) self.assertIsNone(self.__class__.handler["previous"]) for _ in range(0, 1+self.testleaks): self.__class__.handler["previous"] = LG_Error.set_handler(self.__class__.handler["default"]) self.assertEqual(self.__class__.handler["previous"].__name__, "_default_handler") self.errinfo = "dummy" self.assertRaises(LG_Error, Dictionary, "a visible dummy dict name (default handler test)") self.assertEqual(self.errinfo, "dummy")
def test_10_set_error_handler(self): # Set the error handler and validate that it # gets the error info and the data. self.__class__.handler["default"] = \ LG_Error.set_handler(self.error_handler_test, self) self.assertEqual(self.__class__.handler["default"].__name__, "_default_handler") self.gotit = None self.assertRaises(LG_Error, Dictionary, "seh_dummy1") self.assertEqual((self.errinfo.severity, self.errinfo.severity_label), (clg.lg_Error, "Error")) self.assertEqual(self.gotit, "testit") self.assertRegexpMatches(self.errinfo.text, "Could not open dictionary.*seh_dummy1")
def test_20_set_error_handler_None(self): # Set the error handler to None and validate that printall() # gets the error info and the data and returns the number of errors. self.__class__.handler["previous"] = LG_Error.set_handler(None) self.assertEqual(self.__class__.handler["previous"].__name__, "error_handler_test") self.assertRaises(LG_Error, Dictionary, "seh_dummy2") self.gotit = None for i in range(0, 2+self.testleaks): self.numerr = LG_Error.printall(self.error_handler_test, self) if 0 == i: self.assertEqual(self.numerr, 1) if 1 == i: self.assertEqual(self.numerr, 0) self.assertEqual((self.errinfo.severity, self.errinfo.severity_label), (clg.lg_Error, "Error")) self.assertEqual(self.gotit, "testit") self.assertRegexpMatches(self.errinfo.text, ".*seh_dummy2")