示例#1
0
        def test_allowing_with_args(self, test_class):
            TestClass = ClassDouble(test_class)

            allow_constructor(TestClass).with_args(
                *VALID_ARGS[test_class]).and_return('Bob Barker')

            assert TestClass(*VALID_ARGS[test_class]) == 'Bob Barker'
示例#2
0
        def test_called_with_wrong_args(self, test_class):
            TestClass = ClassDouble(test_class)

            allow_constructor(TestClass).with_args(*VALID_ARGS[test_class]).and_return('Bob Barker')

            with raises(UnallowedMethodCallError):
                TestClass('Bob', 101)
示例#3
0
    def test_using_the_patched_class(self):
        allow_constructor(patch_class('doubles.testing.User')).and_return('result_1')
        allow_constructor(patch_class('doubles.testing.OldStyleUser')).and_return('result_2')

        result_1, result_2 = doubles.testing.top_level_function_that_creates_an_instance()

        assert result_1 == 'result_1'
        assert result_2 == 'result_2'
示例#4
0
        def test_called_with_wrong_args(self, test_class):
            TestClass = ClassDouble(test_class)

            allow_constructor(TestClass).with_args(
                *VALID_ARGS[test_class]).and_return('Bob Barker')

            with raises(UnallowedMethodCallError):
                TestClass('Bob', 101)
示例#5
0
    def test_using_the_patched_class(self):
        allow_constructor(
            patch_class('doubles.testing.User')).and_return('result_1')
        allow_constructor(
            patch_class('doubles.testing.OldStyleUser')).and_return('result_2')

        result_1, result_2 = doubles.testing.top_level_function_that_creates_an_instance(
        )

        assert result_1 == 'result_1'
        assert result_2 == 'result_2'
示例#6
0
        def test_allowing_with_args(self, test_class):
            TestClass = ClassDouble(test_class)

            allow_constructor(TestClass).with_args(*VALID_ARGS[test_class]).and_return('Bob Barker')

            assert TestClass(*VALID_ARGS[test_class]) == 'Bob Barker'
示例#7
0
 def test_fails_with_positional_args_and_kwargs(self, type_):
     double = ClassDouble('doubles.testing.{}SubClass'.format(type_))
     with raises(VerifyingDoubleArgumentError):
         allow_constructor(double).with_args(1, 2, foo=1)
示例#8
0
 def test_fails_with_kwargs(self, type_):
     double = ClassDouble('doubles.testing.{}SubClass'.format(type_))
     with raises(VerifyingDoubleArgumentError):
         allow_constructor(double).with_args(bob='Barker')
示例#9
0
 def test_passes_with_positional_args(self, type_):
     double = ClassDouble('doubles.testing.{}SubClass'.format(type_))
     allow_constructor(double).with_args(1, 2)
示例#10
0
 def test_passes_with_kwargs(self, type_):
     double = ClassDouble('doubles.testing.{}SubClass'.format(type_))
     allow_constructor(double).with_args(bob='Barker')
示例#11
0
 def test_raises_if_you_allow_constructor(self, test_class):
     with raises(ConstructorDoubleError):
         allow_constructor(test_class)
示例#12
0
 def test_raises_if_you_allow_constructor(self, test_class):
     with raises(ConstructorDoubleError):
         allow_constructor(test_class)
示例#13
0
def gen_mock_service():
    class_name = 'bootcamp.handlers.title.TitleService'
    mock_service = TitleService()
    service_class = patch_class(class_name)
    allow_constructor(service_class).and_return(mock_service)
    return mock_service
示例#14
0
        def test_with_no_args(self, test_class):
            TestClass = ClassDouble(test_class)

            allow_constructor(TestClass)
            assert TestClass(*VALID_ARGS[test_class]) is None
示例#15
0
 def test_fails_with_positional_args_and_kwargs(self, type_):
     double = ClassDouble('doubles.testing.{}SubClass'.format(type_))
     with raises(VerifyingDoubleArgumentError):
         allow_constructor(double).with_args(1, 2, foo=1)
示例#16
0
 def test_fails_with_kwargs(self, type_):
     double = ClassDouble('doubles.testing.{}SubClass'.format(type_))
     with raises(VerifyingDoubleArgumentError):
         allow_constructor(double).with_args(bob='Barker')
示例#17
0
 def test_passes_with_positional_args(self, type_):
     double = ClassDouble('doubles.testing.{}SubClass'.format(type_))
     allow_constructor(double).with_args(1, 2)
示例#18
0
 def test_passes_with_kwargs(self, type_):
     double = ClassDouble('doubles.testing.{}SubClass'.format(type_))
     allow_constructor(double).with_args(bob='Barker')
示例#19
0
def git():
    repo = ClassDouble('accountable.accountable.Repo')
    git = InstanceDouble('accountable.accountable.Repo')
    git.git = support.MockRepo()
    allow_constructor(repo).and_return(git)
    accountable.Repo = repo
示例#20
0
        def test_with_invalid_args(self, test_class):
            TestClass = ClassDouble(test_class)

            with raises(VerifyingDoubleArgumentError):
                allow_constructor(TestClass).with_args(10)
示例#21
0
        def test_with_invalid_args(self, test_class):
            TestClass = ClassDouble(test_class)

            with raises(VerifyingDoubleArgumentError):
                allow_constructor(TestClass).with_args(10)
示例#22
0
def gen_mock_service():
    class_name = 'bootcamp.handlers.add_user.UserService'
    mock_service = UserService()
    service_class = patch_class(class_name)
    allow_constructor(service_class).and_return(mock_service)
    return mock_service
示例#23
0
        def test_with_no_args(self, test_class):
            TestClass = ClassDouble(test_class)

            allow_constructor(TestClass)
            assert TestClass(*VALID_ARGS[test_class]) is None