Ejemplo n.º 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))
Ejemplo n.º 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()
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 def test_it_returns_False_when_non_function(self):
     self.assertFalse(accepts_arg(None))
Ejemplo n.º 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))
Ejemplo n.º 6
0
    def test_it_returns_True_for_function_with_one_arg(self):
        def foo(a):
            pass

        self.assertTrue(accepts_arg(foo))