def test_removing_labeled_predicate_by_reference_also_removes_label(mapping: PredicateMapping):
    mapping.add(equals_foo, 'foo value', 'foo label')
    mapping.remove(equals_foo)

    # Just a bit of white-box testing here
    assert len(mapping._values) == 0
    assert len(mapping._labeled_predicates) == 0
def test_can_remove_predicates_by_label_if_label_was_given(mapping: PredicateMapping):
    mapping.add(equals_foo, 'foo value', 'foo label')
    assert mapping.find('foo') == 'foo value'

    mapping.remove('foo label')
    with pytest.raises(ValueError, match=r'No matching'):
        mapping.find('foo')
def test_can_remove_predicates_by_reference(mapping: PredicateMapping):
    mapping.add(equals_foo, 'foo value')
    assert mapping.find('foo') == 'foo value'

    mapping.remove(equals_foo)
    with pytest.raises(ValueError, match=r'No matching'):
        mapping.find('foo')
Пример #4
0
def test_can_remove_predicates_by_reference(mapping: PredicateMapping):
    mapping.add(equals_foo, 'foo value')
    assert mapping.find('foo') == 'foo value'

    mapping.remove(equals_foo)
    with pytest.raises(ValueError, match=r'No matching'):
        mapping.find('foo')
Пример #5
0
def test_can_remove_predicates_by_label_if_label_was_given(
        mapping: PredicateMapping):
    mapping.add(equals_foo, 'foo value', 'foo label')
    assert mapping.find('foo') == 'foo value'

    mapping.remove('foo label')
    with pytest.raises(ValueError, match=r'No matching'):
        mapping.find('foo')
Пример #6
0
def test_removing_labeled_predicate_by_reference_also_removes_label(
        mapping: PredicateMapping):
    mapping.add(equals_foo, 'foo value', 'foo label')
    mapping.remove(equals_foo)

    # Just a bit of white-box testing here
    assert len(mapping._values) == 0
    assert len(mapping._labeled_predicates) == 0
def test_removing_non_existent_label_raises_error(mapping: PredicateMapping):
    with pytest.raises(KeyError, match=r"Label 'asdf' not found in registry"):
        mapping.remove('asdf')
def test_removing_non_existent_predicate_raises_error(mapping: PredicateMapping):
    with pytest.raises(KeyError, match=r'Matcher .* not found in registry'):
        mapping.remove(equals_foo)
def test_removing_unsupported_type_raises_error(mapping: PredicateMapping):
    with pytest.raises(TypeError, match=r'must be callable or string.*got <class \'bool\'>'):
        mapping.remove(True)
Пример #10
0
def test_removing_non_existent_predicate_raises_error(
        mapping: PredicateMapping):
    with pytest.raises(KeyError, match=r'Matcher .* not found in registry'):
        mapping.remove(equals_foo)
Пример #11
0
def test_removing_unsupported_type_raises_error(mapping: PredicateMapping):
    with pytest.raises(
            TypeError,
            match=r'must be callable or string.*got <class \'bool\'>'):
        mapping.remove(True)
Пример #12
0
def test_removing_non_existent_label_raises_error(mapping: PredicateMapping):
    with pytest.raises(KeyError, match=r"Label 'asdf' not found in registry"):
        mapping.remove('asdf')