예제 #1
0
파일: flex_test.py 프로젝트: has207/flex
 def test_flex_respects_at_most_when_called_requested_number(self):
     class Foo:
         def method_foo(self): pass
     foo = Foo()
     flex(foo).method_foo.returns('value_bar').times(0, 1)
     foo.method_foo()
     verify()
예제 #2
0
파일: flex_test.py 프로젝트: has207/flex
 def test_flex_respects_at_most_when_called_less_than_requested(self):
     class Foo:
         def method_foo(self): pass
     foo = Foo()
     flex(foo).method_foo.returns('bar').times(0, 2)
     foo.method_foo()
     verify()
예제 #3
0
파일: flex_test.py 프로젝트: has207/flex
 def test_flex_respects_at_least_when_called_more_than_requested(self):
     class Foo:
         def method_foo(self): pass
     foo = Foo()
     flex(foo).method_foo.returns('value_bar').times(1, None)
     foo.method_foo()
     foo.method_foo()
     verify()
예제 #4
0
파일: flex_test.py 프로젝트: has207/flex
 def test_should_properly_restore_undecorated_static_methods(self):
     class User:
         def get_stuff(): return 'ok!'
         get_stuff = staticmethod(get_stuff)
     assertEqual('ok!', User.get_stuff())
     flex(User).get_stuff
     assert User.get_stuff() is None
     verify()
     assertEqual('ok!', User.get_stuff())
예제 #5
0
파일: flex_test.py 프로젝트: has207/flex
 def test_flex_should_properly_restore_module_level_functions(self):
     if 'flex_test' in sys.modules:
         mod = sys.modules['flex_test']
     else:
         mod = sys.modules['__main__']
     flex(mod).module_level_function
     assertEqual(None, module_level_function(1, 2))
     verify()
     assertEqual('1, 2', module_level_function(1, 2))
예제 #6
0
파일: flex_test.py 프로젝트: has207/flex
 def test_flex_preserves_stubbed_class_methods_between_tests(self):
     class User:
         def get_name(self):
             return 'mike'
     user = User()
     flex(User).get_name.returns('john')
     assertEqual('john', user.get_name())
     verify()
     assertEqual('mike', user.get_name())
예제 #7
0
파일: flex_test.py 프로젝트: has207/flex
 def test_flex_should_properly_restore_static_methods(self):
     class User:
         @staticmethod
         def get_stuff(): return 'ok!'
     assertEqual('ok!', User.get_stuff())
     flex(User).get_stuff
     assert User.get_stuff() is None
     verify()
     assertEqual('ok!', User.get_stuff())
예제 #8
0
파일: flex_test.py 프로젝트: has207/flex
 def test_flex_should_revert_new_instances_on_teardown(self):
     class User(object): pass
     class Group(object): pass
     user = User()
     group = Group()
     flex(Group).__new__.returns(user)
     assert user is Group()
     verify()
     assertEqual(group.__class__, Group().__class__)
예제 #9
0
파일: flex_test.py 프로젝트: has207/flex
 def test_flex_should_properly_restore_class_methods(self):
     class User:
         @classmethod
         def get_stuff(cls):
             return cls.__name__
     assertEqual('User', User.get_stuff())
     flex(User).get_stuff.returns('foo')
     assertEqual('foo', User.get_stuff())
     verify()
     assertEqual('User', User.get_stuff())
예제 #10
0
파일: flex_test.py 프로젝트: has207/flex
 def test_calls_works_for_same_method_with_different_args(self):
     class Foo:
         def method(self, arg):
             pass
     foo = Foo()
     flex(foo).method('foo').runs().times(1)
     flex(foo).method('bar').runs().times(1)
     foo.method('foo')
     foo.method('bar')
     verify()
예제 #11
0
파일: flex_test.py 프로젝트: has207/flex
 def test_flex_removes_new_stubs_from_classes_after_tests(self):
     class User:
         def get_name(self): pass
     user = User()
     saved = user.get_name
     flex(User).get_name.returns('john')
     assert saved != user.get_name
     assertEqual('john', user.get_name())
     verify()
     assertEqual(saved, user.get_name)
예제 #12
0
파일: flex_test.py 프로젝트: has207/flex
 def test_flex_default_calls_respects_matched_expectations(self):
     class Group(object):
         def method1(self, arg1, arg2='b'):
             return '%s:%s' % (arg1, arg2)
         def method2(self, arg):
             return arg
     group = Group()
     flex(group).method1.runs().times(2)
     assertEqual('a:c', group.method1('a', arg2='c'))
     assertEqual('a:b', group.method1('a'))
     flex(group).method2('c').runs().times(1)
     assertEqual('c', group.method2('c'))
     verify()
예제 #13
0
파일: flex_test.py 프로젝트: has207/flex
    def test_support_at_least_and_at_most_together_inside_range(self):
        class Foo:
            def bar(self): pass

        foo = Foo()
        flex(foo).bar.runs().times(1, 2)
        foo.bar()
        verify()

        flex(foo).bar.runs().times(1, 2)
        foo.bar()
        foo.bar()
        verify()
예제 #14
0
파일: flex_test.py 프로젝트: has207/flex
 def test_flex_should_match_keyword_arguments(self):
     class Foo:
         def method1(self): pass
     foo = Foo()
     flex(foo).method1(1, arg3=3, arg2=2).times(2)
     foo.method1(1, arg2=2, arg3=3)
     foo.method1(1, arg3=3, arg2=2)
     verify()
     flex(foo).method1(1, arg3=3, arg2=2)
     assertRaises(MethodSignatureError, foo.method1, arg2=2, arg3=3)
     flex(foo).method1(1, arg3=3, arg2=2)
     assertRaises(MethodSignatureError, foo.method1, 1, arg2=2, arg3=4)
     flex(foo).method1(1, arg3=3, arg2=2)
     assertRaises(MethodSignatureError, foo.method1, 1)
예제 #15
0
파일: flex_test.py 프로젝트: has207/flex
 def test_flex_removes_stubs_from_multiple_classes_on_teardown(self):
     class User:
         def get_name(self): pass
     class Group:
         def get_name(self): pass
     user = User()
     group = User()
     saved1 = user.get_name
     saved2 = group.get_name
     flex(User).get_name.returns('john')
     flex(Group).get_name.returns('john')
     assert saved1 != user.get_name
     assert saved2 != group.get_name
     assertEqual('john', user.get_name())
     assertEqual('john', group.get_name())
     verify()
     assertEqual(saved1, user.get_name)
     assertEqual(saved2, group.get_name)
예제 #16
0
파일: flex_test.py 프로젝트: has207/flex
 def _tear_down(self):
     return verify()
예제 #17
0
파일: flex_test.py 프로젝트: has207/flex
 def test_new_instances_should_be_a_method(self):
     class Foo(object): pass
     flex(Foo).__new__.returns('bar')
     assertEqual('bar', Foo())
     verify()
     assert 'bar' != Foo()
예제 #18
0
파일: flex_test.py 프로젝트: has207/flex
 def test_flex_works_with_never_when_true(self):
     class Foo:
         def method_foo(self): pass
     foo = Foo()
     flex(foo).method_foo.returns('value_bar').times(0)
     verify()
예제 #19
0
파일: flex_test.py 프로젝트: has207/flex
 def test_flex_teardown_does_not_verify_stubs(self):
     class Foo:
         def uncalled_method(self): pass
     flex(Foo).uncalled_method()
     verify()