コード例 #1
0
ファイル: test_utils.py プロジェクト: depop/python-automock
 def test_context_manager_false(self):
     """
     Check that conditional manager does not enter DummyContext
     when condition is False
     """
     with conditional(False, DummyContext()) as context:
         assert context is None
コード例 #2
0
ファイル: test_utils.py プロジェクト: depop/python-automock
 def test_context_manager_true(self):
     """
     Check that conditional manager enters and exits DummyContext
     when condition is True
     """
     with conditional(True, DummyContext()) as context:
         assert isinstance(context, DummyContext)
         assert context.enabled
     assert not context.enabled
コード例 #3
0
ファイル: test_utils.py プロジェクト: depop/python-automock
    def test_decorator_basic_false(self):
        """
        Check that conditional manager decorates test_func
        when condition is False
        """
        decorator = conditional(False, DummyContext())

        assert not decorator.context_object.enabled

        @decorator
        def test_func(val):
            assert not decorator.context_object.enabled
            return val + 1

        assert not decorator.context_object.enabled

        result = test_func(1)
        assert result == 2
        assert not decorator.context_object.enabled
コード例 #4
0
ファイル: test_utils.py プロジェクト: depop/python-automock
    def test_decorator_callable_false(self):
        """
        Check that conditional manager does not decorate test_func
        when condition is a callable returning False
        """
        condition = True
        decorator = conditional(lambda: condition, DummyContext())

        assert not decorator.context_object.enabled

        @decorator
        def test_func(val):
            assert not decorator.context_object.enabled
            return val + 1

        assert not decorator.context_object.enabled

        condition = False
        result = test_func(1)
        assert result == 2
        assert not decorator.context_object.enabled