Esempio n. 1
0
def run_frame_name(name,
                   delay=None,
                   char_delay=None,
                   timeout=None,
                   file=sys.stdout):
    """ Run a single animated progress FrameSet by name. """
    try:
        frames = Frames.get_by_name(name)
    except ValueError as ex:
        print_err(ex)
        return 1
    p = AnimatedProgress(
        'Testing animated progress: {}'.format(frames.name),
        frames=frames,
        delay=delay,
        char_delay=char_delay,
        show_time=True,
        timeout=timeout,
        file=file,
    )
    try:
        p.start()
        framelen = len(frames)
        minruntime = 2
        runtime = max((p.delay * framelen) * 2, minruntime)
        sleep(runtime)
        p.stop()
    except ProgressTimedOut as ex:
        print_err('\n{}'.format(ex))
        return 1
    return 0
Esempio n. 2
0
def run_staticprogress(delay=None, char_delay=None, file=sys.stdout):
    """ This is a rough test of the StaticProgress class. """
    print(C('Testing StaticProgress class...', 'cyan'))

    s = 'Testing StaticProgress.'
    msgs = (
        'Further testing in progress.',
        'Switching the messages up a little bit.',
        'Another message for you.',
        'Just ran out of messages.',
    )
    p = StaticProgress(
        s,
        delay=delay,
        char_delay=char_delay,
        fmt=None,
        show_time=True,
        file=file,
    )
    p.start()
    for i, msg in enumerate(msgs):
        p.text = '{}: {}'.format(i + 1, msg)
        sleep(1)
    p.stop()

    print('\nFinished with static progress functions.\n')
    return 0
Esempio n. 3
0
def run_bar_name(name,
                 delay=None,
                 char_delay=None,
                 file=sys.stdout,
                 min_run_time=5,
                 timeout=None):
    """ Run a single animated progress BarSet by name. """
    try:
        bars = Bars.get_by_name(name)
    except ValueError as ex:
        print_err(ex)
        return 1
    delay = delay or (min_run_time / 20)
    p = ProgressBar(
        'Testing progress bar: {}'.format(bars.name),
        bars=bars,
        show_time=True,
        timeout=timeout,
        file=file,
    )
    try:
        with p:
            for x in range(0, 55, 5):
                p.update(x)
                sleep(delay)
            p.message = 'Almost through with: {}'.format(bars.name)
            for x in range(50, 105, 5):
                p.update(x)
                sleep(delay)
        p.stop()
    except ProgressTimedOut as ex:
        print_err('\n{}'.format(ex))
        return 1
    return 0
Esempio n. 4
0
    def run_frame_type(frames, framename):
        nonlocal frameindex
        frameindex += 1

        p = AnimatedProgress(
            '({}/{}) Testing frame type: {}'.format(
                frameindex,
                frameslen,
                framename,
            ),
            frames=frames,
            delay=delay,
            char_delay=char_delay,
            fmt=None,
            show_time=True,
            file=file,
        )
        p.start()
        sleepsecs = (p.delay * len(frames)) * 2
        # Should be enough time to see the animation play through once.
        sleep(min((sleepsecs, 2)))
        p.text = '({}/{}) Almost through with: {}'.format(
            frameindex,
            frameslen,
            framename,
        )
        sleep(min((sleepsecs, 2)))
        p.stop()
Esempio n. 5
0
    def run_bar_type(bars, barsname):
        nonlocal frameindex
        frameindex += 1

        p = ProgressBar(
            '({}/{}) Testing frame type: {}'.format(
                frameindex,
                barslen,
                barsname,
            ),
            bars=bars,
            show_time=True,
            file=file,
        )
        with p:
            for x in range(0, 50, 5):
                p.update(x)
                sleep(delay)
            p.message = '({}/{}) Almost through with: {}'.format(
                frameindex,
                barslen,
                barsname,
            )
            for x in range(50, 100, 5):
                p.update(x)
                sleep(delay)
            p.update(100)
            sleep(delay)
        p = ProgressBar(
            '({}/{}) Testing percent {}: {}'.format(
                frameindex,
                barslen,
                0,
                barsname,
            ),
            bars=bars,
            show_time=False,
            file=file,
        )
        with p:
            for x in range(0, 160, 10):
                p.message = '({}/{}) Testing percent {}: {}'.format(
                    frameindex,
                    barslen,
                    x,
                    barsname,
                )
                p.update(x)
                sleep(delay * 0.9)
Esempio n. 6
0
def run_processbase(delay=None, file=sys.stdout):
    """ This is a rough test of the WriterProcessBase class. """
    print(C('Testing WriterProcessBase class...', 'cyan'))
    write_lock = Lock()
    text_queue = Queue(maxsize=1)
    err_queue = Queue(maxsize=1)
    stopped = Value(c_bool, True)
    time_started = Value(c_double, 0)
    time_elapsed = Value(c_double, 0)
    timeout = Value(c_double, 0)

    def change_text(s):
        text_queue.put_nowait(s)

    p = WriterProcessBase(
        text_queue,
        err_queue,
        write_lock,
        stopped,
        time_started,
        time_elapsed,
        timeout,
        file=file,
    )
    change_text('.')
    p.start()
    sleep(1)
    change_text('!')
    sleep(1)
    change_text('?')
    sleep(1)
    p.stop()
    print()
    for attr in ('stop_flag', 'time_started', 'time_elapsed'):
        val = getattr(p, attr).value
        print('{:>16}: {}'.format(attr, val))

    print('\nFinished with WriterProcessBase functions.\n')
    return 0
Esempio n. 7
0
def run_process(delay=None, file=sys.stdout):
    """ This is a rough test of the WriterProcess class. """
    print(C('Testing WriterProcess class...', 'cyan'))

    p = WriterProcess(
        '.',
        file=file,
    )
    p.start()
    sleep(1)
    p.text = '!'
    sleep(1)
    p.text = '?'
    sleep(1)
    p.stop()
    # Test elapsed time changes.
    assert p.elapsed > 1
    print()
    for attr in ('stopped', 'started', 'elapsed'):
        val = getattr(p, attr)
        print('{:>16}: {}'.format(attr, val))

    print('\nFinished with WriterProcess functions.\n')
    return 0