MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / test_iterator

Method test_iterator

test/test_grid_file.py:584–624  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

582 self.assertEqual(b"Bye", g.readline())
583
584 def test_iterator(self):
585 f = GridIn(self.db.fs)
586 f.close()
587 g = GridOut(self.db.fs, f._id)
588 if _IS_SYNC:
589 self.assertEqual([], list(g))
590 else:
591 self.assertEqual([], g.to_list())
592
593 f = GridIn(self.db.fs)
594 f.write(b"hello world\nhere are\nsome lines.")
595 f.close()
596 g = GridOut(self.db.fs, f._id)
597 if _IS_SYNC:
598 self.assertEqual([b"hello world\n", b"here are\n", b"some lines."], list(g))
599 else:
600 self.assertEqual([b"hello world\n", b"here are\n", b"some lines."], g.to_list())
601
602 self.assertEqual(b"", g.read(5))
603 if _IS_SYNC:
604 self.assertEqual([], list(g))
605 else:
606 self.assertEqual([], g.to_list())
607
608 g = GridOut(self.db.fs, f._id)
609 self.assertEqual(b"hello world\n", next(iter(g)))
610 self.assertEqual(b"here", g.read(4))
611 self.assertEqual(b" are\n", next(iter(g)))
612 self.assertEqual(b"some lines", g.read(10))
613 self.assertEqual(b".", next(iter(g)))
614 with self.assertRaises(StopIteration):
615 iter(g).__next__()
616
617 f = GridIn(self.db.fs, chunk_size=2)
618 f.write(b"hello world")
619 f.close()
620 g = GridOut(self.db.fs, f._id)
621 if _IS_SYNC:
622 self.assertEqual([b"hello world"], list(g))
623 else:
624 self.assertEqual([b"hello world"], g.to_list())
625
626 def test_read_unaligned_buffer_size(self):
627 in_data = b"This is a text that doesn't quite fit in a single 16-byte chunk."

Callers

nothing calls this directly

Calls 9

closeMethod · 0.95
to_listMethod · 0.95
writeMethod · 0.95
readMethod · 0.95
GridInClass · 0.90
GridOutClass · 0.90
nextFunction · 0.90
iterFunction · 0.90
__next__Method · 0.45

Tested by

no test coverage detected