示例#1
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()
示例#2
0
def test_req_not_called_when_both_added_and_overridden(member, never):
    allows = Allows(identity_loader=lambda: member)

    allows.additional.push(Additional(never))
    allows.overrides.push(Override(never))

    assert allows.fulfill([])
示例#3
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
示例#4
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
示例#5
0
def test_fulfills_skips_overridden_requirements(member, never):
    allows = Allows(identity_loader=lambda: member)
    allows.overrides.push(Override(never))

    assert allows.fulfill([never])

    # be a good test denizen and cleanup
    allows.overrides.pop()
示例#6
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)
示例#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()
示例#8
0
    def test_current_overrides_returns_active_context(self, never):
        manager = OverrideManager()
        o = Override(never)

        manager.push(o)

        assert o == current_overrides

        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()
示例#10
0
 def test_can_remove_a_requirement_from_override(self):
     override = Override(some_requirement)
     override.remove(some_requirement)
     assert some_requirement not in override
示例#11
0
 def test_can_take_the_difference_of_two_overrides_in_place(self):
     override_1 = Override(some_other_requirement, some_requirement)
     override_1 -= Override(some_other_requirement)
     assert some_requirement in override_1
     assert some_other_requirement not in override_1
示例#12
0
 def test_can_add_single_requirement_to_override(self):
     override = Override()
     override.add(some_requirement)
     assert some_requirement in override
示例#13
0
 def test_can_take_the_difference_of_two_overrides(self):
     override_1 = Override(some_requirement, some_other_requirement)
     override_2 = Override(some_other_requirement)
     subbed_override = override_1 - override_2
     assert some_requirement in subbed_override
     assert some_other_requirement not in subbed_override
示例#14
0
 def test_can_inplace_add_two_overrides(self):
     override_1 = Override(some_requirement)
     override_1 += Override(some_other_requirement)
     assert some_requirement in override_1
     assert some_other_requirement in override_1
示例#15
0
 def test_can_add_two_overrides_together(self):
     override_1 = Override(some_requirement)
     override_2 = Override(some_other_requirement)
     added_override = override_1 + override_2
     assert some_requirement in added_override
     assert some_other_requirement in added_override
示例#16
0
 def test_shows_if_requirement_is_overridden(self):
     override = Override(some_requirement)
     assert override.is_overridden(some_requirement)
     assert some_requirement in override
示例#17
0
 def test_override_manager_populates_overrides_local(self):
     manager = OverrideManager()
     override = Override(some_requirement)
     manager.push(override)
     assert some_requirement in current_overrides