Example #1
0
def test_has_stderr(markers: list, expected: bool):
    assert deal.has(*markers).has_stderr is expected
Example #2
0
def test_has_import(markers: list, expected: bool):
    assert deal.has(*markers).has_import is expected
Example #3
0
def test_has_network(markers: list, expected: bool):
    assert deal.has(*markers).has_network is expected
Example #4
0
def test_has_write(markers: list, expected: bool):
    assert deal.has(*markers).has_write is expected
Example #5
0
def test_has_read(markers: list, expected: bool):
    assert deal.has(*markers).has_read is expected
Example #6
0
def test_has_global(markers: list, expected: bool):
    assert deal.has(*markers).has_global is expected
Example #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()