Exemplo n.º 1
0
def test_format_meter():
    assert format_meter(0, 1000, 13) == \
        "|----------| 0/1000   0% [elapsed: " \
        "00:13 left: ?,  0.00 iters/sec]"
    assert format_meter(231, 1000, 392) == \
        "|##--------| 231/1000  23% [elapsed: " \
        "06:32 left: 21:44,  0.59 iters/sec]"
Exemplo n.º 2
0
def test_format_meter():
    """ Test statistics and progress bar formatting """
    try:
        unich = unichr
    except NameError:
        unich = chr

    assert format_meter(0, 1000, 13) == \
        "  0%|          | 0/1000 [00:13<?,  0.00it/s]"
    assert format_meter(0, 1000, 13, ncols=68, prefix='desc: ') == \
        "desc:   0%|                            | 0/1000 [00:13<?,  0.00it/s]"
    assert format_meter(231, 1000, 392) == \
        " 23%|" + unich(0x2588) * 2 + unich(0x258e) + \
        "       | 231/1000 [06:32<21:44,  1.70s/it]"
    assert format_meter(10000, 1000, 13) == \
        "10000it [00:13, 769.23it/s]"
    assert format_meter(231, 1000, 392, ncols=56, ascii=True) == \
        " 23%|" + '#' * 3 + '6' + \
        "            | 231/1000 [06:32<21:44,  1.70s/it]"
    assert format_meter(100000, 1000, 13, unit_scale=True, unit='iB') == \
        "100KiB [00:13, 7.69KiB/s]"
    assert format_meter(100, 1000, 12, ncols=0, rate=7.33) == \
        " 10% 100/1000 [00:12<02:02,  7.33it/s]"
    assert format_meter(20, 100, 12, ncols=30, rate=8.1,
                        bar_format=r'{l_bar}{bar}|{n_fmt}/{total_fmt}') == \
        " 20%|" + unich(0x258f) + "|20/100"
Exemplo n.º 3
0
def test_format_meter():
    try:
        unich = unichr
    except NameError:
        unich = chr

    assert format_meter(0, 1000, 13) == \
        "  0%|          | 0/1000 [00:13<?,  0.00 it/s]"
    assert format_meter(0, 1000, 13, ncols=68, prefix='desc: ') == \
        "desc: 0%|                             | 0/1000 [00:13<?,  0.00 it/s]"
    assert format_meter(231, 1000, 392) == \
        " 23%|" + unich(0x2588)*2 + unich(0x258e) + \
        "       | 231/1000 [06:32<21:44,  0.59 it/s]"
    assert format_meter(10000, 1000, 13) == \
        "10000 [00:13, 769.23 it/s]"
    assert format_meter(231, 1000, 392, ncols=56, ascii=True) == \
        " 23%|" + '#'*3 + '4' + \
        "           | 231/1000 [06:32<21:44,  0.59 it/s]"
Exemplo n.º 4
0
    def run(self):
        if not self.t0: 
            self.t0 = time.time()

        sp = StatusPrinter(sys.stderr)

        dots = self.get_dots(self.indices_status,which=self.dot_type)
        sp.print_status(format_meter(self.ndone, self.ntotal, self.elapsed, size=13,extra=dots))

        for idx,ret in self.pool.imap_unordered(self.func,self.get_args()):
            self.indices_status[idx] = True
            self.outputs.append((idx,ret))
            # Try to add another arg, but won't work (see reason in get_args)
            # if self.ndone == 6:
            #     self.add_args(["sleep 2"])
            self.ndone += 1
            self.elapsed = time.time()-self.t0
            dots = self.get_dots(self.indices_status,which=self.dot_type)
            sp.print_status(format_meter(self.ndone, self.ntotal, self.elapsed, size=13,extra=dots))
        print
Exemplo n.º 5
0
    def run(self):
        if not self.t0:
            self.t0 = time.time()

        sp = StatusPrinter(sys.stderr)
        for idx, ret in self.pool.imap_unordered(self.func, self.get_args()):
            self.indices_status[idx] = True
            self.outputs.append((idx, ret))
            # Try to add another arg, but won't work (see reason in get_args)
            # if self.ndone == 6:
            #     self.add_args(["sleep 2"])
            self.ndone += 1
            self.elapsed = time.time() - self.t0
            dots = self.get_dots(self.indices_status, which=self.dot_type)
            sp.print_status(
                format_meter(self.ndone,
                             self.ntotal,
                             self.elapsed,
                             size=13,
                             extra=dots))
        print
Exemplo n.º 6
0
def test_format_meter():
    try:
        unich = unichr
    except NameError:
        unich = chr

    assert format_meter(0, 1000, 13) == \
        "  0%|          | 0/1000 [00:13<?,  0.00it/s]"
    assert format_meter(0, 1000, 13, ncols=68, prefix='desc: ') == \
        "desc:   0%|                            | 0/1000 [00:13<?,  0.00it/s]"
    assert format_meter(231, 1000, 392) == \
        " 23%|" + unich(0x2588)*2 + unich(0x258e) + \
        "       | 231/1000 [06:32<21:44,  0.59it/s]"
    assert format_meter(10000, 1000, 13) == \
        "10000it [00:13, 769.23it/s]"
    assert format_meter(231, 1000, 392, ncols=56, ascii=True) == \
        " 23%|" + '#'*3 + '6' + \
        "            | 231/1000 [06:32<21:44,  0.59it/s]"
    assert format_meter(100000, 1000, 13, unit_scale=True, unit='iB') == \
        "100KiB [00:13, 7.69KiB/s]"
    assert format_meter(100, 1000, 12, ncols=0) == \
        " 10% 100/1000 [00:12<01:48,  8.33it/s]"
Exemplo n.º 7
0
def test_format_meter():
    """ Test statistics and progress bar formatting """
    try:
        unich = unichr
    except NameError:
        unich = chr

    assert format_meter(0, 1000, 13) == \
        "  0%|          | 0/1000 [00:13<?,  0.00it/s]"
    assert format_meter(0, 1000, 13, ncols=68, prefix='desc: ') == \
        "desc:   0%|                            | 0/1000 [00:13<?,  0.00it/s]"
    assert format_meter(231, 1000, 392) == \
        " 23%|" + unich(0x2588) * 2 + unich(0x258e) + \
        "       | 231/1000 [06:32<21:44,  1.70s/it]"
    assert format_meter(10000, 1000, 13) == \
        "10000it [00:13, 769.23it/s]"
    assert format_meter(231, 1000, 392, ncols=56, ascii=True) == \
        " 23%|" + '#' * 3 + '6' + \
        "            | 231/1000 [06:32<21:44,  1.70s/it]"
    assert format_meter(100000, 1000, 13, unit_scale=True, unit='iB') == \
        "100KiB [00:13, 7.69KiB/s]"
    assert format_meter(100, 1000, 12, ncols=0, rate=7.33) == \
        " 10% 100/1000 [00:12<02:02,  7.33it/s]"
Exemplo n.º 8
0
def test_si_format():
    """ Test SI unit prefixes """
    assert '9.00 ' in format_meter(1, 9, 1, unit_scale=True, unit='B')
    assert '99.0 ' in format_meter(1, 99, 1, unit_scale=True)
    assert '999 ' in format_meter(1, 999, 1, unit_scale=True)
    assert '9.99K ' in format_meter(1, 9994, 1, unit_scale=True)
    assert '10.0K ' in format_meter(1, 9999, 1, unit_scale=True)
    assert '99.5K ' in format_meter(1, 99499, 1, unit_scale=True)
    assert '100K ' in format_meter(1, 99999, 1, unit_scale=True)
    assert '1.00M ' in format_meter(1, 999999, 1, unit_scale=True)
    assert '1.00G ' in format_meter(1, 999999999, 1, unit_scale=True)
    assert '1.00T ' in format_meter(1, 999999999999, 1, unit_scale=True)
    assert '1.00P ' in format_meter(1, 999999999999999, 1, unit_scale=True)
    assert '1.00E ' in format_meter(1, 999999999999999999, 1, unit_scale=True)
    assert '1.00Z ' in format_meter(1,
                                    999999999999999999999,
                                    1,
                                    unit_scale=True)
    assert '1.0Y ' in format_meter(1,
                                   999999999999999999999999,
                                   1,
                                   unit_scale=True)
    assert '10.0Y ' in format_meter(1,
                                    9999999999999999999999999,
                                    1,
                                    unit_scale=True)
    assert '100.0Y ' in format_meter(1,
                                     99999999999999999999999999,
                                     1,
                                     unit_scale=True)
    assert '1000.0Y ' in format_meter(1,
                                      999999999999999999999999999,
                                      1,
                                      unit_scale=True)
Exemplo n.º 9
0
__author__ = 'RMGiroux'

from tqdm import format_meter
from blessings import Terminal
from time import sleep

term = Terminal()

"""
    A simple experiment to see if TQDM (great progress bars!) and blessings
    (great terminal location and colour control) can coexist.

    TODO: This should be wrapped in a something that can be pumped from
    asyncio.

"""
for i in range(10):
    with term.location(1,1):
        print(term.red+term.on_black, format_meter(i, 9, 0.3*i))
        sleep(0.3)


Exemplo n.º 10
0
    def line_callback(self, line):
        line = line.rstrip()

        if debug_mode:
            with term.location(1, 30 + self.position * 2):
                print(" " * 80)
            with term.location(1, 30 + self.position * 2):
                print("%-20s: %-50s" % (self.ufid, line.decode("ascii")[-50:]))

        match = progress_regex.search(line)
        if match is not None:
            with term.location(1, self.position * 2):
                print(
                    format_meter(int(match.group(1)),
                                 int(match.group(2)),
                                 (datetime.now() -
                                  self.start_time).total_seconds(),
                                 ascii=True,
                                 prefix=("%-20s" % self.ufid)))
            with term.location(5, self.position * 2 + 1):
                print("%60s" % match.group(3).decode("ascii")[-60:])

            return  # RETURN

        if self.processing_diag:
            match = LineProcessor.block_end_pattern.search(line)
            if match is not None:
                self.diagnostic_buffer += line
                # TODO: Hand off diagnostic to database
                with term.location(1, 50):
                    print(" " * 80)
                with term.location(1, 50):
                    print(self.diagnostic_buffer[0:60])

                self.processing_diag = False
                return

            self.diagnostic_buffer += line
            return

        match = LineProcessor.block_start_pattern.search(line)
        if match is not None:
            self.processing_diag = True
            self.diagnostic_buffer = line

            self.diagnostic_component = match.group(1)
            self.diagnostic_type = match.group(2)

            return

        match = test_summary_regex.search(line)
        if match is not None:
            with term.location(5, self.position * 2 + 1):
                print("%60s" % " ")
            with term.location(5, self.position * 2 + 1):
                print("%-60s" % line.decode("ascii")[-60:])

            if debug_mode:
                with term.location(1, 40 + self.position * 3):
                    print("%-20s: Test summary matched" % self.ufid)

                with term.location(1, 50):
                    print("%-20s: test summary match - hit enter to continue" %
                          self.ufid)

                    my_input = sys.stdin.readline()

            return  # RETURN

        match = test_pass_regex.search(line)
        if match is not None:
            with term.location(5, self.position * 2 + 1):
                print("[%-60s]" % term.green(line.decode("ascii")[-60:]))

            if debug_mode:
                with term.location(1, 41 + self.position * 3):
                    print("%-20s: Test pass regex matched" % self.ufid)

                with term.location(1, 50):
                    print("%-20s: test pass    match - hit enter to continue" %
                          self.ufid)

                    my_input = sys.stdin.readline()

            return  # RETURN

        match = test_fail_regex.search(line)
        if match is not None:
            with term.location(5, self.position * 2 + 1):
                print("[%-60s]" % term.red(line.decode("ascii")[-60:]))

            if debug_mode:
                with term.location(1, 42 + self.position * 3):
                    print("%-20s: Test fail regex matched" % self.ufid)

                with term.location(1, 50):
                    print("%-20s: test fail    match - hit enter to continue" %
                          self.ufid)

                    my_input = sys.stdin.readline()

            return  # RETURN
Exemplo n.º 11
0
def test_si_format():
    """ Test SI unit prefixes """
    assert '9.00 ' in format_meter(1, 9, 1, unit_scale=True, unit='B')
    assert '99.0 ' in format_meter(1, 99, 1, unit_scale=True)
    assert '999 ' in format_meter(1, 999, 1, unit_scale=True)
    assert '9.99K ' in format_meter(1, 9994, 1, unit_scale=True)
    assert '10.0K ' in format_meter(1, 9999, 1, unit_scale=True)
    assert '99.5K ' in format_meter(1, 99499, 1, unit_scale=True)
    assert '100K ' in format_meter(1, 99999, 1, unit_scale=True)
    assert '1.00M ' in format_meter(1, 999999, 1, unit_scale=True)
    assert '1.00G ' in format_meter(1, 999999999, 1, unit_scale=True)
    assert '1.00T ' in format_meter(1, 999999999999, 1, unit_scale=True)
    assert '1.00P ' in format_meter(1, 999999999999999, 1, unit_scale=True)
    assert '1.00E ' in format_meter(1, 999999999999999999, 1, unit_scale=True)
    assert '1.00Z ' in format_meter(1, 999999999999999999999, 1,
                                    unit_scale=True)
    assert '1.0Y ' in format_meter(1, 999999999999999999999999, 1,
                                   unit_scale=True)
    assert '10.0Y ' in format_meter(1, 9999999999999999999999999, 1,
                                    unit_scale=True)
    assert '100.0Y ' in format_meter(1, 99999999999999999999999999, 1,
                                     unit_scale=True)
    assert '1000.0Y ' in format_meter(1, 999999999999999999999999999, 1,
                                      unit_scale=True)
Exemplo n.º 12
0
    def line_callback(self, line):
        line = line.rstrip()

        if debug_mode:
            with term.location(1, 30 + self.position * 2):
                print(" " * 80)
            with term.location(1, 30 + self.position * 2):
                print("%-20s: %-50s" % (self.ufid, line.decode("ascii")[-50:]))

        match = progress_regex.search(line)
        if match is not None:
            with term.location(1, self.position * 2):
                print(format_meter(int(match.group(1)), int(match.group(2)),
                                   (datetime.now() - self.start_time).total_seconds(),
                                   ascii=True, prefix=("%-20s" % self.ufid)))
            with term.location(5, self.position * 2 + 1):
                print("%60s" % match.group(3).decode("ascii")[-60:])

            return  # RETURN

        if self.processing_diag:
            match = LineProcessor.block_end_pattern.search(line)
            if match is not None:
                self.diagnostic_buffer+=line
                # TODO: Hand off diagnostic to database
                with term.location(1, 50):
                    print(" " * 80)
                with term.location(1, 50):
                    print(self.diagnostic_buffer[0:60])

                self.processing_diag = False
                return

            self.diagnostic_buffer+=line
            return

        match = LineProcessor.block_start_pattern.search(line)
        if match is not None:
            self.processing_diag = True
            self.diagnostic_buffer = line

            self.diagnostic_component = match.group(1)
            self.diagnostic_type = match.group(2)

            return

        match = test_summary_regex.search(line)
        if match is not None:
            with term.location(5, self.position * 2 + 1):
                print("%60s" % " ")
            with term.location(5, self.position * 2 + 1):
                print("%-60s" % line.decode("ascii")[-60:])

            if debug_mode:
                with term.location(1, 40 + self.position * 3):
                    print("%-20s: Test summary matched" % self.ufid)

                with term.location(1, 50):
                    print(
                            "%-20s: test summary match - hit enter to continue" % self.ufid)

                    my_input = sys.stdin.readline()

            return  # RETURN

        match = test_pass_regex.search(line)
        if match is not None:
            with term.location(5, self.position * 2 + 1):
                print("[%-60s]" % term.green(line.decode("ascii")[-60:]))

            if debug_mode:
                with term.location(1, 41 + self.position * 3):
                    print("%-20s: Test pass regex matched" % self.ufid)

                with term.location(1, 50):
                    print(
                            "%-20s: test pass    match - hit enter to continue" % self.ufid)

                    my_input = sys.stdin.readline()

            return  # RETURN

        match = test_fail_regex.search(line)
        if match is not None:
            with term.location(5, self.position * 2 + 1):
                print("[%-60s]" % term.red(line.decode("ascii")[-60:]))

            if debug_mode:
                with term.location(1, 42 + self.position * 3):
                    print("%-20s: Test fail regex matched" % self.ufid)

                with term.location(1, 50):
                    print(
                            "%-20s: test fail    match - hit enter to continue" % self.ufid)

                    my_input = sys.stdin.readline()

            return  # RETURN