MCPcopy Create free account
hub / github.com/cdgriffith/Box / test_default_box

Method test_default_box

test/test_box.py:460–502  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

458 bx._box_config
459
460 def test_default_box(self):
461 bx = Box(test_dict, default_box=True, default_box_attr={"hi": "there"})
462 assert bx.key_88 == {"hi": "there"}
463 assert bx["test"] == {"hi": "there"}
464
465 bx2 = Box(test_dict, default_box=True, default_box_attr=Box)
466 assert isinstance(bx2.key_77, Box)
467
468 bx3 = Box(default_box=True, default_box_attr=3)
469 assert bx3.hello == 3
470
471 bx4 = Box(default_box=True, default_box_attr=None)
472 assert bx4.who_is_there is None
473
474 bx5 = Box(default_box=True, default_box_attr=[])
475 assert isinstance(bx5.empty_list_please, list)
476 assert len(bx5.empty_list_please) == 0
477 bx5.empty_list_please.append(1)
478 assert bx5.empty_list_please[0] == 1
479
480 bx6 = Box(default_box=True, default_box_attr=[])
481 my_list = bx6.get("new_list")
482 my_list.append(5)
483 assert bx6.get("new_list")[0] == 5
484
485 bx7 = Box(default_box=True, default_box_attr=False)
486 assert bx7.nothing is False
487
488 bx8 = Box(default_box=True, default_box_attr=0)
489 assert bx8.nothing == 0
490
491 # Tests __get_default's `copy` clause
492 s = {1, 2, 3}
493 bx9 = Box(default_box=True, default_box_attr=s)
494 assert isinstance(bx9.test, set)
495 assert bx9.test == s
496 assert id(bx9.test) != id(s)
497
498 bx10 = Box({"from": "here"}, default_box=True)
499 assert bx10.xfrom == "here"
500 bx10.xfrom = 5
501 assert bx10.xfrom == 5
502 assert bx10 == {"from": 5}
503
504 # Issue#59 https://github.com/cdgriffith/Box/issues/59 "Treat None values as non existing keys for default_box"
505 def test_default_box_none_transforms(self):

Callers

nothing calls this directly

Calls 3

getMethod · 0.95
BoxClass · 0.90
appendMethod · 0.80

Tested by

no test coverage detected