def predicate(self, *args, **kwargs): """the default predicate for Support Classifiers invokes any derivied _predicate function, trapping any exceptions raised in the process. We are obligated to catch these exceptions to give subsequent rules the opportunity act. An error during the predicate application is a failure of the rule, not a failure of the classification system itself """ try: return self._predicate(*args, **kwargs) except Exception, x: if not self.config: if 'processor' in kwargs: self.config = kwargs['processor'].config else: raise self.config.logger.debug( 'skunk_classifier: %s predicicate failed because of "%s"', arbitrary_object_to_string(self.__class__), arbitrary_object_to_string(x), exc_info=True) return False
def test_arbitrary_object_to_string(self): function = converters.py_obj_to_str self.assertEqual(function(None), '') self.assertEqual(function('hello'), 'hello') config = DotDict() config.a = 17 config.b = 23 a = Alpha(config) self.assertEqual(converters.arbitrary_object_to_string(a), "I am an instance of an Alpha object") a = AlphaBad1(config) self.assertEqual(converters.arbitrary_object_to_string(a), "int") a = AlphaBad2(config) self.assertEqual(converters.arbitrary_object_to_string(a), "int") a = AlphaBad3(config) self.assertEqual(converters.arbitrary_object_to_string(a), "int") self.assertEqual(converters.arbitrary_object_to_string(IndexError), "IndexError") self.assertEqual(converters.arbitrary_object_to_string(Beta), "configman.tests.test_converters.Beta") from configman import tests as tests_module self.assertEqual(function(tests_module), 'configman.tests')
def predicate(self, *args, **kwargs): """the default predicate for Support Classifiers invokes any derivied _predicate function, trapping any exceptions raised in the process. We are obligated to catch these exceptions to give subsequent rules the opportunity act. An error during the predicate application is a failure of the rule, not a failure of the classification system itself """ try: return self._predicate(*args, **kwargs) except Exception as x: if not self.config: if 'processor' in kwargs: self.config = kwargs['processor'].config else: raise self.config.logger.debug( 'skunk_classifier: %s predicicate failed because of "%s"', arbitrary_object_to_string(self.__class__), arbitrary_object_to_string(x), exc_info=True ) return False
def test_arbitrary_object_to_string(self): function = converters.py_obj_to_str self.assertEqual(function(None), '') self.assertEqual(function('hello'), 'hello') config = DotDict() config.a = 17 config.b = 23 a = Alpha(config) self.assertEqual( converters.arbitrary_object_to_string(a), "I am an instance of an Alpha object" ) a = AlphaBad1(config) self.assertEqual( converters.arbitrary_object_to_string(a), "int" ) a = AlphaBad2(config) self.assertEqual( converters.arbitrary_object_to_string(a), "int" ) a = AlphaBad3(config) self.assertEqual( converters.arbitrary_object_to_string(a), "int" ) self.assertEqual( converters.arbitrary_object_to_string(IndexError), "IndexError" ) self.assertEqual( converters.arbitrary_object_to_string(Beta), "configman.tests.test_converters.Beta" ) from configman import tests as tests_module self.assertEqual(function(tests_module), 'configman.tests')