Exemplo n.º 1
0
def test_other_debug_arg():
    debug.timer()
    v = debug.format([1, 2])

    # check only the original code is included in the warning
    s = normalise_output(str(v))
    assert s == ('tests/test_expr_render.py:<line no> test_other_debug_arg\n'
                 '    [1, 2] (list) len=2')
Exemplo n.º 2
0
def test_other_debug_arg_not_literal():
    debug.timer()
    x = 1
    y = 2
    v = debug.format([x, y])

    s = normalise_output(str(v))
    assert s == (
        'tests/test_expr_render.py:<line no> test_other_debug_arg_not_literal\n'
        '    [x, y]: [1, 2] (list) len=2')
def test_other_debug_arg_not_literal():
    debug.timer()
    x = 1
    y = 2
    v = debug.format([x, y])

    s = re.sub(r':\d{2,}', ':<line no>', str(v))
    assert s == (
        'tests/test_expr_render.py:<line no> test_other_debug_arg_not_literal\n'
        '    [x, y]: [1, 2] (list) len=2')
Exemplo n.º 4
0
def test_executing_failure():
    debug.timer()
    x = 1
    y = 2

    # executing fails inside a pytest assert ast the AST is modified
    assert normalise_output(str(debug.format([
        x, y
    ]))) == ('tests/test_expr_render.py:<line no> test_executing_failure '
             '(executing failed to find the calling node)\n'
             '    [1, 2] (list) len=2')
Exemplo n.º 5
0
def test_format_inside_error():
    debug.timer()
    x = 1
    y = 2
    try:
        raise RuntimeError(debug.format([x, y]))
    except RuntimeError as e:
        v = str(e)

    s = normalise_output(str(v))
    assert s == (
        'tests/test_expr_render.py:<line no> test_format_inside_error\n'
        '    [x, y]: [1, 2] (list) len=2')
Exemplo n.º 6
0
def test_simple():
    f = io.StringIO()
    t = debug.timer(name='foobar', file=f)
    with t:
        sleep(0.01)
    v = f.getvalue()
    assert re.fullmatch(r'foobar: 0\.01[012]s elapsed\n', v)
Exemplo n.º 7
0
def iterative_run(dem, start, end, sf=1.0, testname = 'hike', n=5, maxweight=4):
    """Synchronously run over a range of values"""
    z_weights = np.linspace(0, maxweight, n)
    vis.cleardir(f'output/{testname}')
    t = debug.timer()
    for zw in z_weights:
        with t(f'Shortest Path Run, zw: {zw}', verbose=False):
            run(dem, start, end, sf=sf, zw=zw, testname=testname)
    t.summary(verbose=True)
Exemplo n.º 8
0
import random

from devtools import debug

# debug.format() behaves the same as debug() except it returns an object to inspect or print
r = debug.format(x=123, y=321)
print(r)
print(repr(r))

values = list(range(int(1e5)))
# timer can be used as a context manager or directly
with debug.timer('shuffle values'):
    random.shuffle(values)

t2 = debug.timer('sort values').start()
sorted(values)
t2.capture()

# if used repeatedly a summary is available
t3 = debug.timer()
for i in [1e4, 1e6, 1e7]:
    with t3('sum {}'.format(i), verbose=False):
        sum(range(int(i)))

t3.summary(verbose=True)

# debug.breakpoint()
# would drop to a prompt:
# > /python-devtools/docs/examples/more_debug.py(28)<module>()->None
# -> debug.breakpoint()
# (Pdb)