Пример #1
0
 def test_repeated(self):
     """ Once the CountingStream has stopped iterating, the index should not
     increase anymore (the internal state should not be allowed to change)
     """
     s = misc.CountingStream(iter([]))
     self.assertIsNone(next(s, None))
     self.assertEqual(s.index, 0)
     self.assertIsNone(next(s, None))
     self.assertEqual(s.index, 0)
Пример #2
0
 def test_single(self):
     s = misc.CountingStream(range(1))
     self.assertEqual(s.index, -1)
     self.assertEqual(next(s, None), 0)
     self.assertIsNone(next(s, None))
     self.assertEqual(s.index, 1)
Пример #3
0
 def test_full(self):
     s = misc.CountingStream(range(42))
     for _ in s:
         pass
     self.assertEqual(s.index, 42)
Пример #4
0
 def test_empty_stream(self):
     s = misc.CountingStream(iter([]))
     self.assertEqual(s.index, -1)
     self.assertIsNone(next(s, None))
     self.assertEqual(s.index, 0)