示例#1
0
    def test_stubs_constructors(self):
        with no_builtin_verification():
            user = object()

            allow(User).__new__.and_return(user)

            assert User('Alice', 25) is user
示例#2
0
    def test_restores_constructor_on_teardown(self):
        user = object()
        allow(User).__new__.and_return(user)

        teardown()

        result = User('Alice', 25)

        assert result is not user
        assert result.name == 'Alice'
示例#3
0
    def test_allows_stubs_on_existing_static_methods(self):
        User = ClassDouble('doubles.testing.User')

        allow(User).static_method

        assert User.static_method('arg') is None
示例#4
0
    def test_allows_stubs_on_existing_static_methods(self):
        User = ClassDouble('doubles.testing.User')

        allow(User).static_method

        assert User.static_method('arg') is None
示例#5
0
import re

from pytest import raises, mark

from doubles.exceptions import VerifyingDoubleArgumentError, VerifyingDoubleError
from doubles.object_double import ObjectDouble
from doubles.targets.allowance_target import allow
from doubles.testing import User, OldStyleUser

user = User('Alice', 25)
old_style_user = OldStyleUser('Alice', 25)


@mark.parametrize('test_object', [user, old_style_user])
class TestRepr(object):
    def test_displays_correct_class_name(self, test_object):
        subject = ObjectDouble(test_object)

        assert re.match(
            r"<ObjectDouble of <doubles.testing.(?:OldStyle)?User "
            r"(?:instance|object) at 0x[0-9a-f]+> object "
            r"at 0x[0-9a-f]+>", repr(subject))


@mark.parametrize('test_object', [user, old_style_user])
class TestObjectDouble(object):
    def test_allows_stubs_on_existing_methods(self, test_object):
        doubled_user = ObjectDouble(test_object)

        allow(doubled_user).get_name.and_return('Bob')