def test_clearline(): """ Make sure a question mark is printed if the total is unknown pytest tests/test_progiter.py::test_clearline """ file = cStringIO() # Clearline=False version should simply have a newline at the end. prog = ProgIter(file=file, show_times=False, clearline=False) message = prog.format_message() assert strip_ansi(message).strip(' ') == '0/?... \n' # Clearline=True version should carrage return at the begining and have no # newline at the end. prog = ProgIter(file=file, show_times=False, clearline=True) message = prog.format_message() assert strip_ansi(message).strip(' ') == '\r 0/?...'
def test_initial(): """ Make sure a question mark is printed if the total is unknown """ file = cStringIO() prog = ProgIter(initial=9001, file=file, show_times=False, clearline=False) message = prog.format_message() assert strip_ansi(message) == ' 9001/?... \n'
def test_rate_format(): # Define a function that takes some time file = cStringIO() prog = ProgIter(file=file) prog.begin() prog._iters_per_second = .000001 msg = prog.format_message() rate_part = msg.split('rate=')[1].split(' Hz')[0] assert rate_part == '1e-06' prog._iters_per_second = .1 msg = prog.format_message() rate_part = msg.split('rate=')[1].split(' Hz')[0] assert rate_part == '0.10' prog._iters_per_second = 10000 msg = prog.format_message() rate_part = msg.split('rate=')[1].split(' Hz')[0] assert rate_part == '10000.00'