def test_it_returns_False_otherwise(self): class Foobar(object): def foo(self): pass def foo(): pass self.assertFalse(accepts_arg(Foobar().foo)) self.assertFalse(accepts_arg(foo))
def _invoke(self, funcs, context): assert context, "Context needs to be provided for Example to run." for fn in funcs: if accepts_arg(fn): fn(context) else: context.inject_into_self(fn) fn()
def _execute_example(self): "Handles the execution of the Example" test_benchmark = Benchmark() try: with Registry(), test_benchmark: if accepts_arg(self.example.testfn): self.example.testfn(self.context) else: self.context.inject_into_self(self.example.testfn) self.example.testfn() self.num_successes += 1 except KeyboardInterrupt: # bubble interrupt for canceling spec execution raise except: raise self.num_failures += 1 finally: self.example.user_time = test_benchmark.total_time
def test_it_returns_False_when_non_function(self): self.assertFalse(accepts_arg(None))
def test_it_returns_True_for_class_method_with_one_arg(self): class Foobar(object): def foo(self, a): pass self.assertTrue(accepts_arg(Foobar().foo))
def test_it_returns_True_for_function_with_one_arg(self): def foo(a): pass self.assertTrue(accepts_arg(foo))