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

Class TestBoxListOperators

test/test_box_list.py:807–852  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

805
806
807class TestBoxListOperators:
808 def test_add_keeps_boxlist_and_converts(self):
809 bl = BoxList([{"a": 1}], box_dots=True)
810 result = bl + [{"b": 2}]
811 assert isinstance(result, BoxList)
812 assert isinstance(result[0], Box)
813 assert isinstance(result[1], Box)
814 assert result.box_options["box_dots"] is True
815
816 def test_add_two_boxlists(self):
817 result = BoxList([{"a": 1}]) + BoxList([{"b": 2}])
818 assert isinstance(result, BoxList)
819 assert result.to_list() == [{"a": 1}, {"b": 2}]
820
821 def test_add_non_list_raises(self):
822 with pytest.raises(BoxTypeError):
823 BoxList() + 5
824
825 def test_mul_keeps_boxlist(self):
826 bl = BoxList([{"a": 1}], box_dots=True)
827 result = bl * 3
828 assert isinstance(result, BoxList)
829 assert len(result) == 3
830 assert result.box_options["box_dots"] is True
831 assert result.to_list() == [{"a": 1}] * 3
832
833 def test_rmul_and_index_protocol(self):
834 class Two:
835 def __index__(self):
836 return 2
837
838 bl = BoxList([{"a": 1}])
839 for result in (2 * bl, bl * Two()):
840 assert isinstance(result, BoxList)
841 assert result.to_list() == [{"a": 1}] * 2
842
843 def test_mul_non_int_raises(self):
844 with pytest.raises(BoxTypeError):
845 BoxList() * "x"
846
847 def test_frozen_add_result_is_frozen(self):
848 frozen = BoxList([{"a": 1}], frozen_box=True)
849 result = frozen + [{"b": 2}]
850 assert isinstance(result, BoxList)
851 with pytest.raises(BoxError):
852 result.append({"c": 3})
853
854
855def test_reinitialize_replaces_contents():

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected