MCPcopy Create free account
hub / github.com/grantjenks/python-sortedcontainers / test_keysview

Function test_keysview

tests/test_coverage_sorteddict.py:360–398  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

358 assert all(temp.bisect_key_left(val) == (val % 10) * 10 for val in range(10))
359
360def test_keysview():
361 mapping = [(val, pos) for pos, val in enumerate(string.ascii_lowercase)]
362 temp = SortedDict(mapping[:13])
363 keys = temp.keys()
364
365 assert len(keys) == 13
366 assert 'a' in keys
367 assert list(keys) == [val for val, pos in mapping[:13]]
368 assert keys[0] == 'a'
369 assert list(reversed(keys)) == list(reversed(string.ascii_lowercase[:13]))
370 assert keys.index('f') == 5
371 assert keys.count('m') == 1
372 assert keys.count('0') == 0
373 assert keys.isdisjoint(['1', '2', '3'])
374
375 temp.update(mapping[13:])
376
377 assert len(keys) == 26
378 assert 'z' in keys
379 assert list(keys) == [val for val, pos in mapping]
380
381 that = dict(mapping)
382
383 that_keys = get_keysview(that)
384
385 assert keys == that_keys
386 assert not (keys != that_keys)
387 assert not (keys < that_keys)
388 assert not (keys > that_keys)
389 assert keys <= that_keys
390 assert keys >= that_keys
391
392 assert list(keys & that_keys) == [val for val, pos in mapping]
393 assert list(keys | that_keys) == [val for val, pos in mapping]
394 assert list(keys - that_keys) == []
395 assert list(keys ^ that_keys) == []
396
397 keys = SortedDict(mapping[:2]).keys()
398 assert repr(keys) == "SortedKeysView(SortedDict({'a': 0, 'b': 1}))"
399
400def test_valuesview():
401 mapping = [(val, pos) for pos, val in enumerate(string.ascii_lowercase)]

Callers

nothing calls this directly

Calls 6

keysMethod · 0.95
updateMethod · 0.95
SortedDictClass · 0.90
get_keysviewFunction · 0.85
indexMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected