Пример #1
0
    def scope_mocks():
        with zest.mock(pretend_unit_under_test.foo) as m_foo:
            pretend_unit_under_test.foo()
            # Had the real foo been called it would have
            # raised NotImplementedError

        assert m_foo.called_once()
Пример #2
0
 def it_exceptions_serially():
     with zest.mock(pretend_unit_under_test.foo) as m_foo:
         m_foo.exceptions_serially([ValueError, TypeError])
         with zest.raises(ValueError):
             pretend_unit_under_test.foo()
         with zest.raises(TypeError):
             pretend_unit_under_test.foo()
Пример #3
0
    def it_normalizes_calls_into_kwargs():
        # normalized_call() is a handy when you want to just know
        # what was passed to the mock but you don't care if
        # it was passed as args or kwargs.

        with zest.mock(pretend_unit_under_test.foo) as m_foo:
            pretend_unit_under_test.foo("arg1", arg2="arg2")

        kwargs = m_foo.normalized_call()
        assert kwargs == dict(arg1="arg1", arg2="arg2")
Пример #4
0
    def it_hooks():
        with zest.mock(pretend_unit_under_test.foo) as m_foo:
            got_callback = False

            def _callback():
                nonlocal got_callback
                got_callback = True

            m_foo.hook(_callback)
            pretend_unit_under_test.foo()
            assert got_callback is True
Пример #5
0
    def it_checks_against_normalized_call():
        with zest.mock(pretend_unit_under_test.foo) as m_foo:
            pretend_unit_under_test.foo("arg1", arg2="arg2")

        assert m_foo.called_once_with_kws(arg1="arg1", arg2="arg2")
Пример #6
0
 def it_exceptions():
     with zest.mock(pretend_unit_under_test.foo) as m_foo:
         m_foo.exceptions(ValueError)
         with zest.raises(ValueError):
             pretend_unit_under_test.foo()
Пример #7
0
 def it_returns_serial_values():
     with zest.mock(pretend_unit_under_test.foo) as m_foo:
         m_foo.returns_serially([1, 2])
         assert pretend_unit_under_test.foo() == 1
         assert pretend_unit_under_test.foo() == 2
Пример #8
0
 def it_returns_value():
     with zest.mock(pretend_unit_under_test.foo) as m_foo:
         m_foo.returns(1)
         assert pretend_unit_under_test.foo() == 1
Пример #9
0
 def it_resets():
     with zest.mock(pretend_unit_under_test.foo) as m_foo:
         pretend_unit_under_test.foo()
         m_foo.reset()
         pretend_unit_under_test.foo()
     assert m_foo.n_calls == 1
Пример #10
0
 def it_counts_n_calls():
     with zest.mock(pretend_unit_under_test.foo) as m_foo:
         pretend_unit_under_test.foo()
         pretend_unit_under_test.foo()
     assert m_foo.n_calls == 2
Пример #11
0
 def test_1():
     pretend_unit_under_test.foo()
     assert m_foo.called_once()