def testGetArgSpecIgnoresDecoratorsThatDontProvideArgspec(self): argspec = tf_inspect.ArgSpec(args=['a', 'b', 'c'], varargs=None, keywords=None, defaults=(1, 'hello')) inner_decorator = tf_decorator.TFDecorator('', test_undecorated_function, '', argspec) outer_decorator = tf_decorator.TFDecorator('', inner_decorator) self.assertEqual(argspec, tf_inspect.getargspec(outer_decorator))
def testGetArgSpecReturnsOutermostDecoratorThatChangesArgspec(self): outer_argspec = tf_inspect.ArgSpec( args=['a'], varargs=None, keywords=None, defaults=None) inner_argspec = tf_inspect.ArgSpec( args=['b'], varargs=None, keywords=None, defaults=None) inner_decorator = tf_decorator.TFDecorator('', test_undecorated_function, '', inner_argspec) outer_decorator = tf_decorator.TFDecorator('', inner_decorator, '', outer_argspec) self.assertEqual(outer_argspec, tf_inspect.getargspec(outer_decorator))
def testGetFullArgSpecIgnoresDecoratorsThatDontProvideFullArgSpec(self): argspec = tf_inspect.FullArgSpec(args=['a', 'b', 'c'], varargs=None, varkw=None, defaults=(1, 'hello'), kwonlyargs=[], kwonlydefaults=None, annotations={}) inner_decorator = tf_decorator.TFDecorator('', test_undecorated_function, '', argspec) outer_decorator = tf_decorator.TFDecorator('', inner_decorator) self.assertEqual(argspec, tf_inspect.getfullargspec(outer_decorator))
def testInitCapturesNonNoneArgspec(self): argspec = tf_inspect.ArgSpec(args=['a', 'b', 'c'], varargs=None, keywords=None, defaults=(1, 'hello')) self.assertIs( argspec, tf_decorator.TFDecorator('', test_function, '', argspec).decorator_argspec)
def testGetArgSpecOnDecoratorThatChangesArgspec(self): argspec = tf_inspect.ArgSpec(args=['a', 'b', 'c'], varargs=None, keywords=None, defaults=(1, 'hello')) decorator = tf_decorator.TFDecorator('', test_undecorated_function, '', argspec) self.assertEqual(argspec, tf_inspect.getargspec(decorator))
def testGetFullArgSpecOnDecoratorThatChangesFullArgSpec(self): argspec = tf_inspect.FullArgSpec(args=['a', 'b', 'c'], varargs=None, varkw=None, defaults=(1, 'hello'), kwonlyargs=[], kwonlydefaults=None, annotations={}) decorator = tf_decorator.TFDecorator('', test_undecorated_function, '', argspec) self.assertEqual(argspec, tf_inspect.getfullargspec(decorator))
def testGetFullArgSpecReturnsOutermostDecoratorThatChangesFullArgSpec(self): outer_argspec = tf_inspect.FullArgSpec( args=['a'], varargs=None, varkw=None, defaults=None, kwonlyargs=[], kwonlydefaults=None, annotations={}) inner_argspec = tf_inspect.FullArgSpec( args=['b'], varargs=None, varkw=None, defaults=None, kwonlyargs=[], kwonlydefaults=None, annotations={}) inner_decorator = tf_decorator.TFDecorator('', test_undecorated_function, '', inner_argspec) outer_decorator = tf_decorator.TFDecorator('', inner_decorator, '', outer_argspec) self.assertEqual(outer_argspec, tf_inspect.getfullargspec(outer_decorator))
def testGetArgSpecOnPartialWithDecoratorThatChangesArgspec(self): """Tests getargspec on partial function with decorated argspec.""" argspec = tf_inspect.ArgSpec(args=['a', 'b', 'c'], varargs=None, keywords=None, defaults=(1, 'hello')) decorator = tf_decorator.TFDecorator('', test_undecorated_function, '', argspec) partial_argspec = tf_inspect.ArgSpec(args=['a', 'b', 'c'], varargs=None, keywords=None, defaults=(2, 1, 'hello')) partial_with_decorator = functools.partial(decorator, a=2) self.assertEqual(argspec, tf_inspect.getargspec(decorator)) self.assertEqual(partial_argspec, tf_inspect.getargspec(partial_with_decorator))
def testInitCapturesTarget(self): self.assertIs( test_function, tf_decorator.TFDecorator('', test_function).decorated_target)
def make_tf_decorator(target): return tf_decorator.TFDecorator(decorator_name, target, decorator_doc)
def testCallingATFDecoratorCallsTheTarget(self): self.assertEqual(124, tf_decorator.TFDecorator('', test_function)(123))
def testInitSetsDecoratorDocToTargetDoc(self): self.assertEqual('Test Function Docstring.', tf_decorator.TFDecorator('', test_function).__doc__)
def testInitSetsDecoratorNameToTargetName(self): self.assertEqual('test_function', tf_decorator.TFDecorator('', test_function).__name__)
class Foo(object): foo = tf_decorator.TFDecorator('Descr', Descr())
def testInitCapturesDecoratorName(self): self.assertEqual( 'decorator name', tf_decorator.TFDecorator('decorator name', test_function).decorator_name)
def testInitCapturesDecoratorDoc(self): self.assertEqual( 'decorator doc', tf_decorator.TFDecorator('', test_function, 'decorator doc').decorator_doc)
def testInitSetsDecoratorQualNameToTargetQualName(self): if hasattr(tf_decorator.TFDecorator('', test_function), '__qualname__'): self.assertEqual( 'test_function', tf_decorator.TFDecorator('', test_function).__qualname__)