@@ -598,3 +598,62 @@ def test_mbp_1_to_json_with_all_options_writes_expected_file_to_disk(self) -> No
598598
599599 # Cleanup
600600 os .remove (path )
601+
602+ def test_bento_iterable (self ) -> None :
603+ """
604+ Tests the Bento iterable implementation to ensure records
605+ can be accessed by iteration.
606+ """
607+ # Arrange
608+ stub_data = get_test_data (schema = Schema .MBO )
609+ bento = Bento .from_bytes (data = stub_data )
610+
611+ record_list = list (bento )
612+ assert (
613+ str (record_list [0 ])
614+ == "(14, 160, 1, 5482, 1609160400000429831, 647784973705, "
615+ "3722750000000, 1, -128, 0, b'C', b'A', 1609160400000704060, "
616+ "22993, 1170352)"
617+ )
618+ assert (
619+ str (record_list [1 ])
620+ == "(14, 160, 1, 5482, 1609160400000429831, 647784973705, "
621+ "3722750000000, 1, -128, 0, b'C', b'A', 1609160400000704060, "
622+ "22993, 1170352)"
623+ )
624+
625+ def test_bento_iterable_parallel (self ) -> None :
626+ """
627+ Tests the Bento iterable implementation to ensure iterators are
628+ not stateful. For example, calling next() on one iterator does
629+ not affect another.
630+ """
631+ # Arrange
632+ stub_data = get_test_data (schema = Schema .MBO )
633+ bento = Bento .from_bytes (data = stub_data )
634+
635+ first = iter (bento )
636+ second = iter (bento )
637+
638+ assert (
639+ str (next (first )) == "(14, 160, 1, 5482, 1609160400000429831, 647784973705, "
640+ "3722750000000, 1, -128, 0, b'C', b'A', 1609160400000704060, "
641+ "22993, 1170352)"
642+ )
643+ assert (
644+ str (next (second ))
645+ == "(14, 160, 1, 5482, 1609160400000429831, 647784973705, "
646+ "3722750000000, 1, -128, 0, b'C', b'A', 1609160400000704060, "
647+ "22993, 1170352)"
648+ )
649+ assert (
650+ str (next (second ))
651+ == "(14, 160, 1, 5482, 1609160400000429831, 647784973705, "
652+ "3722750000000, 1, -128, 0, b'C', b'A', 1609160400000704060, "
653+ "22993, 1170352)"
654+ )
655+ assert (
656+ str (next (first )) == "(14, 160, 1, 5482, 1609160400000429831, 647784973705, "
657+ "3722750000000, 1, -128, 0, b'C', b'A', 1609160400000704060, "
658+ "22993, 1170352)"
659+ )
0 commit comments