示例#1
0
    def test_popping_unpopulated_override_errors(self):
        manager = OverrideManager()

        with pytest.raises(RuntimeError) as excinfo:
            manager.pop()

        assert "popped wrong override context" in str(excinfo.value)
示例#2
0
    def test_override_context_manager(self):
        manager = OverrideManager()
        o = Override()

        with manager.override(o):
            assert _override_ctx_stack.top[1] is o

        assert _override_ctx_stack.top is None
示例#3
0
    def test_manager_throws_if_different_context_popped(self):
        manager = OverrideManager()
        manager.push(Override())
        manager2 = OverrideManager()

        with pytest.raises(RuntimeError) as excinfo:
            manager2.pop()

        assert "popped wrong override context" in str(excinfo.value)
示例#4
0
    def test_override_with_use_parent_combines_both(self):
        manager = OverrideManager()

        def parent_requirement(user):
            return True

        def child_requirement(user):
            return True

        parent = Override(parent_requirement)
        child = Override(child_requirement)

        expected = Override(parent_requirement, child_requirement)

        with manager.override(parent):
            with manager.override(child, use_parent=True):
                assert expected == manager.current
示例#5
0
    def test_current_overrides_points_towards_temporary_context(
            self, never, always):
        manager = OverrideManager()
        manager.push(Override(never))

        o = Override(always)

        with manager.override(o):
            assert o == current_overrides

        manager.pop()
示例#6
0
    def test_current_overrides_returns_active_context(self, never):
        manager = OverrideManager()
        o = Override(never)

        manager.push(o)

        assert o == current_overrides

        manager.pop()
示例#7
0
def test_conditional_skips_overridden_requirements(member, never, always, request):
    manager = OverrideManager()
    manager.push(Override(never))

    reqs = And(never, always)

    assert reqs.fulfill(member, request)

    manager.pop()
def test_conditional_skips_overridden_requirements_even_if_nested(
    member, always, never, request
):
    manager = OverrideManager()
    manager.push(Override(never))

    reqs = And(And(And(always), Or(never)))

    assert reqs.fulfill(member)

    manager.pop()
示例#9
0
 def test_override_manager_populates_overrides_local(self):
     manager = OverrideManager()
     override = Override(some_requirement)
     manager.push(override)
     assert some_requirement in current_overrides