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

Method test_default_box

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

Source from the content-addressed store, hash-verified

665 bx._box_config
666
667 def test_default_box(self):
668 bx = Box(test_dict, default_box=True, default_box_attr={"hi": "there"})
669 assert bx.key_88 == {"hi": "there"}
670 assert bx["test"] == {"hi": "there"}
671
672 bx2 = Box(test_dict, default_box=True, default_box_attr=Box)
673 assert isinstance(bx2.key_77, Box)
674
675 bx3 = Box(default_box=True, default_box_attr=3)
676 assert bx3.hello == 3
677
678 bx4 = Box(default_box=True, default_box_attr=None)
679 assert bx4.who_is_there is None
680
681 bx5 = Box(default_box=True, default_box_attr=[], default_box_create_on_get=True)
682 assert isinstance(bx5.empty_list_please, list)
683 assert len(bx5.empty_list_please) == 0
684 bx5.empty_list_please.append(1)
685 assert bx5.empty_list_please[0] == 1
686
687 bx6 = Box(default_box=True, default_box_attr=[], default_box_create_on_get=True)
688 my_list = bx6.get("new_list")
689 my_list.append(5)
690 assert bx6.get("new_list")[0] == 5
691
692 bx7 = Box(default_box=True, default_box_attr=False)
693 assert bx7.nothing is False
694
695 bx8 = Box(default_box=True, default_box_attr=0)
696 assert bx8.nothing == 0
697
698 # Tests __get_default's `copy` clause
699 s = {1, 2, 3}
700 bx9 = Box(default_box=True, default_box_attr=s)
701 assert isinstance(bx9.test, set)
702 assert bx9.test == s
703 assert id(bx9.test) != id(s)
704
705 bx10 = Box({"from": "here"}, default_box=True)
706 assert bx10.xfrom == "here"
707 bx10.xfrom = 5
708 assert bx10.xfrom == 5
709 assert bx10 == {"from": 5}
710
711 # Issue#59 https://github.com/cdgriffith/Box/issues/59 "Treat None values as non existing keys for default_box"
712 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