def test_hacked_timerit_verbose(): import textwrap with CaptureStdout(suppress=False) as cap: HackedTimerit(3, label='foo', verbose=0).call(lambda: None) assert cap.text.strip() == textwrap.dedent(''' ''').strip() with CaptureStdout(suppress=False) as cap: HackedTimerit(3, label='foo', verbose=1).call(lambda: None) assert cap.text.strip() == textwrap.dedent(''' Timed best=42.000 s, mean=42.000 +- 0.0 s for foo ''').strip() with CaptureStdout(suppress=False) as cap: HackedTimerit(3, label='foo', verbose=2).call(lambda: None) assert cap.text.strip() == textwrap.dedent(''' Timed foo for: 3 loops, best of 3 time per loop: best=42.000 s, mean=42.000 +- 0.0 s ''').strip() with CaptureStdout(suppress=False) as cap: HackedTimerit(3, label='foo', verbose=3).call(lambda: None) assert cap.text.strip() == textwrap.dedent(''' Timing foo for: 3 loops, best of 3 Timed foo for: 3 loops, best of 3 body took: 126.000 s time per loop: best=42.000 s, mean=42.000 +- 0.0 s ''').strip()
def test_timerit_verbose(): from xdoctest.utils import CaptureStdout with CaptureStdout() as cap: ub.Timerit(3, label='foo', verbose=0).call(lambda: None) assert cap.text == '' with CaptureStdout() as cap: ub.Timerit(3, label='foo', verbose=1).call(lambda: None) assert cap.text.count('\n') == 2 assert cap.text.count('foo') == 1 with CaptureStdout() as cap: ub.Timerit(3, label='foo', verbose=2).call(lambda: None) assert cap.text.count('\n') == 3 assert cap.text.count('foo') == 2 with CaptureStdout() as cap: ub.Timerit(3, label='foo', verbose=3).call(lambda: None) assert cap.text.count('\n') == 4 assert cap.text.count('foo') == 2 with CaptureStdout() as cap: ub.Timerit(3, label='foo', verbose=4).call(lambda: None) assert cap.text.count('\n') == 4 assert cap.text.count('foo') == 2
def test_timerit_default_verbosity(): with CaptureStdout() as cap: Timerit(10, '').call(lambda: None) assert cap.text == '', 'should be quiet by default when label is not given' with CaptureStdout() as cap: Timerit(10, 'alabel').call(lambda: None) assert cap.text != '', 'should be verbose by default when label is given'
def test_timer_default_verbosity(): with CaptureStdout() as cap: ub.Timer('').tic().toc() assert cap.text == '', 'should be quiet by default when label is not given' with CaptureStdout() as cap: ub.Timer('a label').tic().toc() assert cap.text != '', 'should be verbose by default when label is given'
def test_timer_nonewline(): from xdoctest.utils import CaptureStdout with CaptureStdout() as cap: timer = ub.Timer(newline=False) timer.tic() timer.toc() assert cap.text.replace('u', '').startswith("\ntic('')...toc('')")
def test_timerit_verbose(): with CaptureStdout() as cap: Timerit(3, label='foo', verbose=0).call(lambda: None) assert cap.text == '' with CaptureStdout() as cap: Timerit(3, label='foo', verbose=1).call(lambda: None) assert cap.text.count('\n') == 1 assert cap.text.count('foo') == 1 with CaptureStdout() as cap: Timerit(3, label='foo', verbose=2).call(lambda: None) assert cap.text.count('\n') == 2 assert cap.text.count('foo') == 1 with CaptureStdout() as cap: Timerit(3, label='foo', verbose=3).call(lambda: None) assert cap.text.count('\n') == 4 assert cap.text.count('foo') == 2 with CaptureStdout() as cap: Timerit(3, label='foo', verbose=4).call(lambda: None) assert cap.text.count('\n') == 4 assert cap.text.count('foo') == 2
def test_tqdm_compatibility(): prog = ProgIter(range(20), total=20, miniters=17, show_times=False) assert prog.pos == 0 assert prog.freq == 17 for _ in prog: pass with CaptureStdout() as cap: ProgIter.write('foo') assert cap.text.strip() == 'foo' with CaptureStdout() as cap: prog = ProgIter(show_times=False) prog.set_description('new desc', refresh=False) prog.begin() prog.refresh() prog.close() assert prog.label == 'new desc' assert 'new desc' in cap.text.strip() with CaptureStdout() as cap: prog = ProgIter(show_times=False) prog.set_description('new desc', refresh=True) prog.close() assert prog.label == 'new desc' assert 'new desc' in cap.text.strip() with CaptureStdout() as cap: prog = ProgIter(show_times=False) prog.set_description_str('new desc') prog.begin() prog.refresh() prog.close() assert prog.label == 'new desc' assert 'new desc' in cap.text.strip() with CaptureStdout() as cap: prog = ProgIter(show_times=False) prog.set_postfix({'foo': 'bar'}, baz='biz', x=object(), y=2) prog.begin() assert prog.length is None assert 'foo=bar' in cap.text.strip() assert 'baz=biz' in cap.text.strip() assert 'y=2' in cap.text.strip() assert 'x=<object' in cap.text.strip() with CaptureStdout() as cap: prog = ProgIter(show_times=False) prog.set_postfix_str('bar baz', refresh=False) assert 'bar baz' not in cap.text.strip()
def test_timer_nonewline(): with CaptureStdout() as cap: timer = Timer(newline=False, verbose=1) timer.tic() timer.toc() assert cap.text.replace('u', '').startswith("\ntic('')...toc('')")