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')
示例#2
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')
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_no_matching_predicates_should_raise_error(mapping: PredicateMapping):
    mapping.add(equals_foo, 'foo value')
    mapping.add(equals_bar, 'bar value')

    with pytest.raises(ValueError,
                       match=r"No matching entries for 'baz' in registry"):
        mapping.find('baz')
示例#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')
def test_multiple_matching_predicates_should_raise_error(mapping: PredicateMapping):
    mapping.add(Equals('baz'), 'baz value')
    mapping.add(functools.partial(operator.eq, 'baz'), 'baz value')

    with pytest.raises(ValueError) as e:
        mapping.find('baz')

    e.match(r"Multiple matching entries for 'baz' in registry")
    e.match(r"<Equals \(== 'baz'\)>")
    e.match(r'functools\.partial')
示例#7
0
def test_multiple_matching_predicates_should_raise_error(
        mapping: PredicateMapping):
    mapping.add(Equals('baz'), 'baz value')
    mapping.add(functools.partial(operator.eq, 'baz'), 'baz value')

    with pytest.raises(ValueError) as e:
        mapping.find('baz')

    e.match(r"Multiple matching entries for 'baz' in registry")
    e.match(r"<Equals \(== 'baz'\)>")
    e.match(r'functools\.partial')
示例#8
0
def test_can_add_predicates_and_find_corresponding_values(
        mapping: PredicateMapping):
    mapping.add(equals_foo, 'foo value')
    mapping.add(equals_bar, 'bar value')

    assert mapping.find('foo') == 'foo value'
    assert mapping.find('bar') == 'bar value'
def test_no_matching_predicates_should_raise_error(mapping: PredicateMapping):
    mapping.add(equals_foo, 'foo value')
    mapping.add(equals_bar, 'bar value')

    with pytest.raises(ValueError, match=r"No matching entries for 'baz' in registry"):
        mapping.find('baz')
def test_can_add_predicates_and_find_corresponding_values(mapping: PredicateMapping):
    mapping.add(equals_foo, 'foo value')
    mapping.add(equals_bar, 'bar value')

    assert mapping.find('foo') == 'foo value'
    assert mapping.find('bar') == 'bar value'