예제 #1
0
    def test_basic_trackers(self):
        """Basic testing of all trackers; reset, and then retest."""
        sio_c = six.StringIO()
        sio_c2 = six.StringIO()
        sio_f = six.StringIO()
        sio_d = six.StringIO()

        tc = progress.CommandLineProgressTracker(output_file=sio_c)
        tc2 = progress.CommandLineProgressTracker(output_file=sio_c2,
                                                  term_delay=1)
        tf = progress.FunctionProgressTracker(output_file=sio_f)
        td = progress.DotProgressTracker(output_file=sio_d)
        tq = progress.QuietProgressTracker()

        mt = progress.MultiProgressTracker([tc, tc2, tf, tq, td])

        # run everything twice; this exercises that after a
        # reset(), everything still works correctly.
        for x in [1, 2]:
            progress.test_progress_tracker(mt, gofast=True)

            self.assertTrue(len(sio_c.getvalue()) > 100)
            self.assertTrue(len(sio_c2.getvalue()) > 100)
            self.assertTrue(len(sio_f.getvalue()) > 100)
            self.assertTrue(len(sio_d.getvalue()) > 1)
            # check that dot only printed dots
            self.assertTrue(len(sio_d.getvalue()) * "." == sio_d.getvalue())

            for f in [sio_c, sio_c2, sio_f, sio_d]:
                f.seek(0)
                f.truncate(0)

            # Reset them all, and go again, as a test of reset().
            mt.flush()
            mt.reset()
예제 #2
0
    def test_multi(self):
        """Test basic multi functionality."""
        sio1 = six.StringIO()
        sio2 = six.StringIO()

        #
        # The FunctionProgressTracker is used here because its
        # output doesn't contain any timing information.  The
        # output of the two Function progress trackers can thus
        # be tested for equality.
        #
        t1 = progress.FunctionProgressTracker(output_file=sio1)
        t2 = progress.FunctionProgressTracker(output_file=sio2)
        mt = progress.MultiProgressTracker([t1, t2])
        progress.test_progress_tracker(mt, gofast=True)

        self.assertTrue(len(sio1.getvalue()) > 100)
        self.assertTrue(len(sio2.getvalue()) > 100)
        self.assertEqual(sio1.getvalue(), sio2.getvalue())