MCPcopy
hub / github.com/pydantic/pydantic / test_limited_dict

Function test_limited_dict

tests/test_generics.py:2404–2441  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2402
2403
2404def test_limited_dict():
2405 d = LimitedDict(10)
2406 d[1] = '1'
2407 d[2] = '2'
2408 assert list(d.items()) == [(1, '1'), (2, '2')]
2409 for no in '34567890':
2410 d[int(no)] = no
2411 assert list(d.items()) == [
2412 (1, '1'),
2413 (2, '2'),
2414 (3, '3'),
2415 (4, '4'),
2416 (5, '5'),
2417 (6, '6'),
2418 (7, '7'),
2419 (8, '8'),
2420 (9, '9'),
2421 (0, '0'),
2422 ]
2423 d[11] = '11'
2424
2425 # reduce size to 9 after setting 11
2426 assert len(d) == 9
2427 assert list(d.items()) == [
2428 (3, '3'),
2429 (4, '4'),
2430 (5, '5'),
2431 (6, '6'),
2432 (7, '7'),
2433 (8, '8'),
2434 (9, '9'),
2435 (0, '0'),
2436 (11, '11'),
2437 ]
2438 d[12] = '12'
2439 assert len(d) == 10
2440 d[13] = '13'
2441 assert len(d) == 9
2442
2443
2444def test_construct_generic_model_with_validation():

Callers

nothing calls this directly

Calls 2

LimitedDictClass · 0.90
itemsMethod · 0.45

Tested by

no test coverage detected