def test_iteritems_args_kw(arg0_pairs, kw_pairs): """:func:`bidict._iteritems_args_kw` should work correctly.""" assert list(_iteritems_args_kw(arg0_pairs)) == list(arg0_pairs) assert list(_iteritems_args_kw(OrderedDict(kw_pairs))) == list(kw_pairs) kwdict = dict(kw_pairs) # Create an iterator over both arg0_pairs and kw_pairs. arg0_kw_items = _iteritems_args_kw(arg0_pairs, **kwdict) # Consume the initial (arg0) pairs of the iterator, checking they match arg0. assert all(check == expect for (check, expect) in izip(arg0_kw_items, arg0_pairs)) # Consume the remaining (kw) pairs of the iterator, checking they match kw. assert all(kwdict[k] == v for (k, v) in arg0_kw_items) with pytest.raises(StopIteration): next(arg0_kw_items)
def test_iteritems_args_kw(arg0, kw): """:func:`bidict._iteritems_args_kw` should work correctly.""" arg0_1, arg0_2 = tee(arg0) it = _iteritems_args_kw(arg0_1, **kw) # Consume the first `len(arg0)` pairs, checking that they match `arg0`. assert all(check == expect for (check, expect) in zip(it, arg0_2)) with pytest.raises(StopIteration): next(arg0_1) # Iterating `it` should have consumed all of `arg0_1`. # Consume the remaining pairs, checking that they match `kw`. # Once min PY version required is higher, can check that the order matches `kw` too. assert all(kw[k] == v for (k, v) in it) with pytest.raises(StopIteration): next(it)
def test_iteritems_args_kw_raises_on_too_many_args(): """:func:`bidict._iteritems_args_kw` should raise if given too many arguments.""" with pytest.raises(TypeError): _iteritems_args_kw('too', 'many', 'args')