示例#1
0
    def test_allows_stubs_on_existing_class_methods(self):
        with no_builtin_verification():
            date = InstanceDouble('datetime.date')

            allow(date).today.with_args()

            assert date.today() is None
示例#2
0
    def test_allows_stubs_on_existing_methods(self):
        with no_builtin_verification():
            date = InstanceDouble('datetime.date')

            allow(date).ctime

            assert date.ctime() is None
示例#3
0
    def test_allows_stubs_on_existing_class_methods(self):
        with no_builtin_verification():
            date = InstanceDouble('datetime.date')

            allow(date).today.with_args()

            assert date.today() is None
示例#4
0
    def test_allows_stubs_on_existing_methods(self):
        with no_builtin_verification():
            date = InstanceDouble('datetime.date')

            allow(date).ctime

            assert date.ctime() is None
示例#5
0
def test_get_vehicles():
    owner = 'owner'
    owners_vehicles = 'owners_vehicles'
    vehicles_repo = InstanceDouble(
        'app.sample.repositories.vehicles_repository.VehiclesRepository')
    allow(vehicles_repo).get_vehicles.with_args(owner).and_return(
        owners_vehicles)

    assert vehicles_repo.get_vehicles(owner) == owners_vehicles
示例#6
0
def test_get_user():
    username = '******'
    password = '******'
    user = '******'
    users_repo = InstanceDouble(
        'app.sample.repositories.users_repository.UsersRepository')
    allow(users_repo).get_user.with_args(username, password).and_return(user)

    assert users_repo.get_user(username, password) == user
示例#7
0
    def test_mocking__enter__and__exit__works(self):
        user = InstanceDouble('doubles.testing.User')
        allow(user).__enter__.and_return('bob barker')
        allow(user).__exit__

        with user as u:
            assert u == 'bob barker'
示例#8
0
def test_dictionary_read_error():
    some_rw = InstanceDouble('tchannel.rw.ReadWriter')
    allow(some_rw).read.and_raise(ReadError('great sadness'))

    dict_rw = rw.dictionary(('foo', some_rw))
    with pytest.raises(ReadError):
        dict_rw.read(BytesIO())
示例#9
0
def test_instance_exception():
    some_rw = InstanceDouble('tchannel.rw.ReadWriter')
    c_rw = rw.instance(ClassWithArgs, ('x', some_rw), ('y', rw.number(4)))
    allow(some_rw).read.and_raise(ReadError("great sadness"))

    with pytest.raises(ReadError):
        c_rw.read(bio([1, 2, 3, 4]))
示例#10
0
    def test_read(self):
        some_rw = InstanceDouble('tchannel.rw.ReadWriter')
        delegated_rw = self._mk_rw(some_rw)

        stream = BytesIO()

        expect(some_rw).read.with_args(stream)
        delegated_rw.read(stream)
示例#11
0
    def test_write(self):
        some_rw = InstanceDouble('tchannel.rw.ReadWriter')
        delegated_rw = self._mk_rw(some_rw)

        stream = BytesIO()

        expect(some_rw).write.with_args("foo", stream)
        delegated_rw.write("foo", stream)
示例#12
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
示例#13
0
def vcr_client():
    return InstanceDouble('tchannel.testing.vcr.config.VCRProxyClient')
示例#14
0
    def test_raises_when_stubbing_noncallable_attributes(self):
        date = InstanceDouble('datetime.date')

        with raises(VerifyingDoubleError):
            allow(date).year
示例#15
0
def cassette():
    cass = InstanceDouble('tchannel.testing.vcr.cassette.Cassette')
    cass.write_protected = False
    return cass
示例#16
0
    def test_width(self):
        some_rw = InstanceDouble('tchannel.rw.ReadWriter')
        delegated_rw = self._mk_rw(some_rw)

        expect(some_rw).width.with_no_args()
        delegated_rw.width()
示例#17
0
    def test_raises_when_stubbing_nonexistent_methods(self):
        date = InstanceDouble('datetime.date')

        with raises(VerifyingDoubleError):
            allow(date).nonexistent_method
示例#18
0
 def test_mocking__call__works(self):
     user = InstanceDouble('doubles.testing.User')
     allow(user).__call__.and_return('bob barker')
     assert user() == 'bob barker'
示例#19
0
    def test_raises_when_class_does_not_exist_in_module(self):
        with raises(VerifyingDoubleImportError) as e:
            InstanceDouble('unittest.foo')

        assert str(e.value) == 'No object at path: unittest.foo.'
示例#20
0
    def test_raises_when_importing_a_non_class_object(self):
        with raises(VerifyingDoubleImportError) as e:
            InstanceDouble('unittest.signals')

        assert str(
            e.value) == 'Path does not point to a class: unittest.signals.'
示例#21
0
    def test_raises_on_import_error(self):
        with raises(VerifyingDoubleImportError) as e:
            InstanceDouble('foo.bar')

        assert str(e.value) == 'Cannot import object from path: foo.bar.'
示例#22
0
    def test_raises_when_target_is_a_top_level_module(self):
        with raises(VerifyingDoubleImportError) as e:
            InstanceDouble('foo')

        assert str(e.value) == 'Invalid import path: foo.'
示例#23
0
    def test_passing_kwargs_assings_them_as_attrs(self):
        user = InstanceDouble('doubles.testing.User', name='Bob Barker')

        assert user.name == 'Bob Barker'
示例#24
0
 def test_class_with__getattr__(self):
     test_obj = InstanceDouble('doubles.testing.ClassWithGetAttr')
     allow(test_obj).method.and_return('bob barker')
     assert test_obj.method() == 'bob barker'
示例#25
0
    def test_creating_instance_double_after_patching(self):
        patch('doubles.testing.User', InstanceDouble('doubles.testing.User'))

        assert InstanceDouble('doubles.testing.User')
示例#26
0
 def test_class_with__getattr__(self):
     test_obj = InstanceDouble('doubles.testing.ClassWithGetAttr')
     allow(test_obj).method.and_return('bob barker')
     assert test_obj.method() == 'bob barker'
示例#27
0
def cassette():
    cass = InstanceDouble('tchannel.testing.vcr.cassette.Cassette')
    cass.write_protected = False
    return cass
示例#28
0
    def test_raises_when_argspec_does_not_match(self):
        date = InstanceDouble('datetime.date')

        with raises(VerifyingDoubleArgumentError):
            allow(date).ctime.with_args('foo')