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

Class TestBoxListOperators

test/test_box_list.py:768–813  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

766
767
768class TestBoxListOperators:
769 def test_add_keeps_boxlist_and_converts(self):
770 bl = BoxList([{"a": 1}], box_dots=True)
771 result = bl + [{"b": 2}]
772 assert isinstance(result, BoxList)
773 assert isinstance(result[0], Box)
774 assert isinstance(result[1], Box)
775 assert result.box_options["box_dots"] is True
776
777 def test_add_two_boxlists(self):
778 result = BoxList([{"a": 1}]) + BoxList([{"b": 2}])
779 assert isinstance(result, BoxList)
780 assert result.to_list() == [{"a": 1}, {"b": 2}]
781
782 def test_add_non_list_raises(self):
783 with pytest.raises(BoxTypeError):
784 BoxList() + 5
785
786 def test_mul_keeps_boxlist(self):
787 bl = BoxList([{"a": 1}], box_dots=True)
788 result = bl * 3
789 assert isinstance(result, BoxList)
790 assert len(result) == 3
791 assert result.box_options["box_dots"] is True
792 assert result.to_list() == [{"a": 1}] * 3
793
794 def test_rmul_and_index_protocol(self):
795 class Two:
796 def __index__(self):
797 return 2
798
799 bl = BoxList([{"a": 1}])
800 for result in (2 * bl, bl * Two()):
801 assert isinstance(result, BoxList)
802 assert result.to_list() == [{"a": 1}] * 2
803
804 def test_mul_non_int_raises(self):
805 with pytest.raises(BoxTypeError):
806 BoxList() * "x"
807
808 def test_frozen_add_result_is_frozen(self):
809 frozen = BoxList([{"a": 1}], frozen_box=True)
810 result = frozen + [{"b": 2}]
811 assert isinstance(result, BoxList)
812 with pytest.raises(BoxError):
813 result.append({"c": 3})

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected