Exemple #1
0
def test_has_stderr(markers: list, expected: bool):
    assert deal.has(*markers).has_stderr is expected
Exemple #2
0
def test_has_import(markers: list, expected: bool):
    assert deal.has(*markers).has_import is expected
Exemple #3
0
def test_has_network(markers: list, expected: bool):
    assert deal.has(*markers).has_network is expected
Exemple #4
0
def test_has_write(markers: list, expected: bool):
    assert deal.has(*markers).has_write is expected
Exemple #5
0
def test_has_read(markers: list, expected: bool):
    assert deal.has(*markers).has_read is expected
Exemple #6
0
def test_has_global(markers: list, expected: bool):
    assert deal.has(*markers).has_global is expected
Exemple #7
0
    # element at this position matches item
    deal.ensure(
        lambda items, item, result: items[result] == item,
        message='invalid match',
    ),
    # element at this position is the first match
    deal.ensure(
        lambda items, item, result: not any(el == item
                                            for el in items[:result]),
        message='not the first match',
    ),
    # LookupError will be raised if no elements found
    deal.raises(LookupError),
    deal.reason(LookupError, lambda items, item: item not in items),
    # no side-effects
    deal.has(),
)


@contract_for_index_of
def index_of(items: List[int], item: int) -> int:
    for index, el in enumerate(items):
        if el == item:
            return index
    raise LookupError


@pytest.mark.parametrize('case', deal.cases(index_of))
def test_index_of(case):
    case()