Beispiel #1
0
    def __t_pty_tracker(self, trackerclass, **kwargs):
        def __drain(masterf):
            while True:
                chunksz = 1024
                termdata = masterf.read(chunksz)
                if len(termdata) < chunksz:
                    # assume we hit EOF
                    break

        #
        # - Allocate a pty
        # - Create a thread to drain off the master side; without
        #   this, the slave side will block when trying to write.
        # - Connect the prog tracker to the slave side
        # - Set it running
        #
        (master, slave) = pty.openpty()
        slavef = os.fdopen(slave, "w")
        masterf = os.fdopen(master, "rb")

        t = threading.Thread(target=__drain, args=(masterf, ))
        t.start()

        p = trackerclass(output_file=slavef, **kwargs)
        progress.test_progress_tracker(p, gofast=True)
        slavef.close()

        t.join()
        masterf.close()
Beispiel #2
0
        def __t_pty_tracker(self, trackerclass, **kwargs):
                def __drain(masterf):
                        while True:
                                termdata = masterf.read(1024)
                                if len(termdata) == 0:
                                        break

                #
                # - Allocate a pty
                # - Create a thread to drain off the master side; without
                #   this, the slave side will block when trying to write.
                # - Connect the prog tracker to the slave side
                # - Set it running
                #
                (master, slave) = pty.openpty()
                slavef = os.fdopen(slave, "w")
                masterf = os.fdopen(master, "r")

                t = threading.Thread(target=__drain, args=(masterf,))
                t.start()

                p = trackerclass(output_file=slavef, **kwargs)
                progress.test_progress_tracker(p, gofast=True)
                slavef.close()

                t.join()
                masterf.close()
Beispiel #3
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()
Beispiel #4
0
        def test_multi(self):
                """Test basic multi functionality."""
                sio1 = StringIO.StringIO()
                sio2 = StringIO.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.assert_(len(sio1.getvalue()) > 100)
                self.assert_(len(sio2.getvalue()) > 100)
                self.assertEqual(sio1.getvalue(), sio2.getvalue())
Beispiel #5
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())
Beispiel #6
0
        def test_basic_trackers(self):
                """Basic testing of all trackers; reset, and then retest."""
                sio_c = StringIO.StringIO()
                sio_c2 = StringIO.StringIO()
                sio_f = StringIO.StringIO()
                sio_d = StringIO.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.assert_(len(sio_c.getvalue()) > 100)
                        self.assert_(len(sio_c2.getvalue()) > 100)
                        self.assert_(len(sio_f.getvalue()) > 100)
                        self.assert_(len(sio_d.getvalue()) > 1)
                        # check that dot only printed dots
                        self.assert_(
                            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()
Beispiel #7
0
            trackerclass.__name__, outputdevname))
        argv = argv[2:]

    if len(pts) > 1:
        t = progress.MultiProgressTracker(pts)
    else:
        t = pts[0]
    return (t, gofast)


#
# This utility is a useful aid in developing or tweaking progress trackers.
# Arguments are passed in tuples of <trackername> <outputfile>.  The
# multi-progress tracker will be used if multiple trackers are specified.  '-'
# can be used to set an argument to its default value.
#
# Example: python runprogress.py - - cli /tmp/outfile
#
# This will create the default tracker on the default device (/dev/stdout)
# and also a CommandLineProgressTracker outputting to /tmp/outfile.
# Happy hacking.
#
if __name__ == "__main__":
    try:
        (_tracker, _gofast) = parse_argv()
        progress.test_progress_tracker(_tracker, gofast=_gofast)
    except progress.ProgressTrackerException as e:
        print("Error: {0}".format(e), file=sys.stderr)
        sys.exit(1)
    sys.exit(0)
Beispiel #8
0
                argv = argv[2:]

        if len(pts) > 1:
                t = MultiProgressTracker(pts)
        else:
                t = pts[0]
        return (t, gofast)


#
# This utility is a useful aid in developing or tweaking progress trackers.
# Arguments are passed in tuples of <trackername> <outputfile>.  The
# multi-progress tracker will be used if multiple trackers are specified.  '-'
# can be used to set an argument to its default value.
#
# Example: python progress.py - - cli /tmp/outfile
#
# This will create the default tracker on the default device (/dev/stdout)
# and also a CommandLineProgressTracker outputting to /tmp/outfile.
# Happy hacking.
#
if __name__ == "__main__":
        try:
                (_tracker, _gofast) = parse_argv()
                progress.test_progress_tracker(_tracker, gofast=_gofast)
        except progress.ProgressTrackerException, e:
                print >> sys.stderr, "Error: %s" % e
                sys.exit(1)
        sys.exit(0)