Exemplo n.º 1
0
 def test_count_emitter(self):
     ce = CountEmitter(every=10, outfile=self.output, format="%s records\n")
     data = ce.attach([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22])
     for _ in data:
         pass
     self.assertEquals(self.output.getvalue(), '10 records\n20 records\n')
     ce.done()
     self.assertEquals(self.output.getvalue(), '10 records\n20 records\n22 records\n')
Exemplo n.º 2
0
 def test_count_emitter(self):
     ce = CountEmitter(every=10, outfile=self.output, format="%s records\n")
     data = ce.attach([
         1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
         20, 21, 22
     ])
     for _ in data:
         pass
     self.assertEquals(self.output.getvalue(), '10 records\n20 records\n')
     ce.done()
     self.assertEquals(self.output.getvalue(),
                       '10 records\n20 records\n22 records\n')
Exemplo n.º 3
0
    def test_count_emitter(self):

        # values for test
        values = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]

        with closing(StringIO()) as output:

            # test without of parameter
            ce = CountEmitter(every=10, outfile=output, format="%(count)s records\n")
            list(ce.attach(values))
            self.assertEqual(output.getvalue(), '10 records\n20 records\n')
            ce.done()
            self.assertEqual(output.getvalue(), '10 records\n20 records\n22 records\n')

        with closing(StringIO()) as output:

            # test with of parameter
            ce = CountEmitter(every=10, outfile=output, of=len(values))
            list(ce.attach(values))
            self.assertEqual(output.getvalue(), '10 of 22\n20 of 22\n')
            ce.done()
            self.assertEqual(output.getvalue(), '10 of 22\n20 of 22\n22 of 22\n')