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

Method test_default_box

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

Source from the content-addressed store, hash-verified

616 bx._box_config
617
618 def test_default_box(self):
619 bx = Box(test_dict, default_box=True, default_box_attr={"hi": "there"})
620 assert bx.key_88 == {"hi": "there"}
621 assert bx["test"] == {"hi": "there"}
622
623 bx2 = Box(test_dict, default_box=True, default_box_attr=Box)
624 assert isinstance(bx2.key_77, Box)
625
626 bx3 = Box(default_box=True, default_box_attr=3)
627 assert bx3.hello == 3
628
629 bx4 = Box(default_box=True, default_box_attr=None)
630 assert bx4.who_is_there is None
631
632 bx5 = Box(default_box=True, default_box_attr=[], default_box_create_on_get=True)
633 assert isinstance(bx5.empty_list_please, list)
634 assert len(bx5.empty_list_please) == 0
635 bx5.empty_list_please.append(1)
636 assert bx5.empty_list_please[0] == 1
637
638 bx6 = Box(default_box=True, default_box_attr=[], default_box_create_on_get=True)
639 my_list = bx6.get("new_list")
640 my_list.append(5)
641 assert bx6.get("new_list")[0] == 5
642
643 bx7 = Box(default_box=True, default_box_attr=False)
644 assert bx7.nothing is False
645
646 bx8 = Box(default_box=True, default_box_attr=0)
647 assert bx8.nothing == 0
648
649 # Tests __get_default's `copy` clause
650 s = {1, 2, 3}
651 bx9 = Box(default_box=True, default_box_attr=s)
652 assert isinstance(bx9.test, set)
653 assert bx9.test == s
654 assert id(bx9.test) != id(s)
655
656 bx10 = Box({"from": "here"}, default_box=True)
657 assert bx10.xfrom == "here"
658 bx10.xfrom = 5
659 assert bx10.xfrom == 5
660 assert bx10 == {"from": 5}
661
662 # Issue#59 https://github.com/cdgriffith/Box/issues/59 "Treat None values as non existing keys for default_box"
663 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