Пример #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 parse_argv():
    misc.setlocale(locale.LC_ALL, "", None)
    gettext.install("pkg", "/usr/share/locale")

    gofast = False
    opts, argv = getopt.getopt(sys.argv[1:], "f")
    for (opt, arg) in opts:
        if opt == '-f':
            gofast = True
        else:
            sys.exit(2)

    trackers = {
        "null": progress.NullProgressTracker,
        "func": progress.FunctionProgressTracker,
        "fancy": progress.FancyUNIXProgressTracker,
        "cli": progress.CommandLineProgressTracker,
        "dot": progress.DotProgressTracker,
        "quiet": progress.QuietProgressTracker,
        "default": progress.FancyUNIXProgressTracker,
    }

    pts = []

    first = True
    while first or len(argv) > 0:
        first = False

        outputdevname = "/dev/stdout"
        if len(argv) >= 2 and argv[1] != "-":
            outputdevname = argv[1]

        tname = "default"
        if len(argv) >= 1 and argv[0] != "-":
            tname = argv[0]
        outputdev = open(outputdevname, "w")

        # Get a reference to the tracker class
        try:
            trackerclass = trackers[tname]
        except KeyError:
            print("unknown tracker {0}".format(argv[0]))
            sys.exit(2)

        try:
            st = trackerclass(output_file=outputdev)
        except TypeError:
            st = trackerclass()
        pts.append(st)

        print("Created {0} progress tracker on {1}".format(
            trackerclass.__name__, outputdevname))
        argv = argv[2:]

    if len(pts) > 1:
        t = progress.MultiProgressTracker(pts)
    else:
        t = pts[0]
    return (t, gofast)
Пример #3
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())