def test_ordattmap_deletion(hwy_dat_key, raw_hwy_dat, alter, check): """ Validate key deletion behavior of OrdAttMap. """ m = OrdAttMap(raw_hwy_dat) assert hwy_dat_key in m obs = alter(m, hwy_dat_key) assert hwy_dat_key not in m assert list(m.items()) == [(k, v) for k, v in raw_hwy_dat if k != hwy_dat_key] orig = [v for k, v in raw_hwy_dat if k == hwy_dat_key][0] assert check(orig, obs), "Expected {} but found {}".format(orig, obs)
def test_ordattmap_access(kvs, access): """ Verify dual value access modes. """ if sys.version_info.major < 3: kvs = [(k.encode("utf-8"), v) for k, v in kvs] m = OrdAttMap(kvs) bads = [] for k, exp in kvs: obs = access(m, k) if exp != obs: bads.append((k, exp, obs)) if bads: pytest.fail("{} mismatches: {}".format(len(bads), bads))
def test_ordattmap_contains(kvs): """ Verify key containment check. """ m = OrdAttMap(kvs) missing = [k for k, _ in kvs if k not in m] if missing: pytest.fail("{} missing keys: {}".format(len(missing), missing))
def test_ordattmap_size(kvs): """ Verify size determination. """ exp = len(kvs) assert exp > 0 assert exp == len(OrdAttMap(kvs))
def test_ordattmap_insertion_order(kvs): """ Verify order preservation. """ assert kvs == list(OrdAttMap(kvs).items())
def test_type_membership(cls, exp): """ Verify that an OrdAttMap instance passes type checks as expected. """ assert exp is isinstance(OrdAttMap(), cls)
def test_ordattmap_repr(raw_hwy_dat, that_type, exp): """ Test __repr__ of OrdAttMap. """ assert exp is (repr(OrdAttMap(raw_hwy_dat)) == repr( that_type(raw_hwy_dat)))
def test_ordattmap_eq(kvs, other_type, expected): """ Verify equality comparison behavior. """ obs = (OrdAttMap(kvs) == other_type(kvs)) assert obs == expected