示例#1
0
    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))
示例#2
0
    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()
示例#3
0
文件: runners.py 项目: jeffh/describe
 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
示例#4
0
 def test_it_returns_False_when_non_function(self):
     self.assertFalse(accepts_arg(None))
示例#5
0
    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))
示例#6
0
    def test_it_returns_True_for_function_with_one_arg(self):
        def foo(a):
            pass

        self.assertTrue(accepts_arg(foo))