Exemple #1
0
 def test_peek_returns_the_same_item_until_next_is_called(self):
   l = Latr([1, 2, 3])
   self.assertEqual(l.peek(), 1)
   self.assertEqual(l.peek(), 1)
   self.assertEqual(l.next(), 1)
   self.assertEqual(l.peek(), 2)
   self.assertEqual(l.next(), 2)
   self.assertEqual(l.peek(), 3)
   self.assertEqual(l.peek(), 3)
Exemple #2
0
  def test_it_provides_a_shorthand_syntax_for_composing_consumers(self):
    def consumer(iterable):
      for i in iterable:
        yield i * 2

    l = Latr(xrange(10)) >> consumer
    
    for i in xrange(10):
      self.assertEqual(l.next(), i * 2)
Exemple #3
0
 def test_values_are_handed_to_consumers_lazily(self):
   m = MagicMock('m')
   
   def supplier():
     for i in xrange(3):
       m()
       yield i
   
   def consumer(iterable):
     for i in iterable:
       yield i * 2
   
   l = Latr(supplier()) >> consumer
   
   self.assertFalse(m.called)
   self.assertEqual(l.next(), 0)
   self.assertTrue(m.called)
Exemple #4
0
 def test_has_next_does_not_move_the_iterator(self):
   l = Latr([1])
   l.has_next
   self.assertEqual(l.next(), 1)
Exemple #5
0
 def test_is_empty_does_not_move_the_item_iterator(self):
   l = Latr([1])
   l.is_empty
   self.assertEqual(l.next(), 1)
Exemple #6
0
 def test_it_wraps_an_iterable(self):
   l = Latr(xrange(10))
   for i in xrange(10):
     self.assertEqual(l.next(), i)