Example #1
0
def test_infinite_loop_pass_in_function():
    code = """\
def foo():
    while True:
        pass

foo()
"""
    expected_report1 = """\

RuntimeError: live coding message limit exceeded


RuntimeError: live coding message limit exceeded"""
    expected_report2 = """\


RuntimeError: live coding message limit exceeded

RuntimeError: live coding message limit exceeded"""
    tracer = TraceRunner()
    tracer.message_limit = 3

    report = tracer.trace_code(code)

    assert report in (expected_report1, expected_report2)
Example #2
0
def test_infinite_loop_before_traced_block():
    code = """\
from space_tracer import traced


def foo():
    while True:
        pass


@traced
def bar(n):
    s = 'a'
    for i in range(n):
        s += 'b'
    return s

foo()
print(bar(3))
"""
    expected_report = """\
from space_tracer import traced | -------------------------------- |
                                | Traced blocks were never called. |
                                | -------------------------------- |"""

    tracer = TraceRunner()
    tracer.message_limit = 20

    with replace_input(code):
        report = tracer.trace_command(
            ['space_tracer', '--traced_file', 'example.py', 'example.py'])

    assert report == expected_report
Example #3
0
def test_infinite_loop_pass():
    code = """\
while True:
    pass
"""
    expected_report = """\
RuntimeError: live coding message limit exceeded"""
    tracer = TraceRunner()
    tracer.message_limit = 3

    report = tracer.trace_code(code)

    assert report in (expected_report + '\n', '\n' + expected_report)
def test_infinite_loop_by_count():
    code = """\
n = 0
while True:
    n += 1
"""
    expected_report = """\
n = 0
      |       |
n = 1 | n = 2 | RuntimeError: live coding message limit exceeded"""
    tracer = TraceRunner()
    tracer.message_limit = 8

    report = tracer.trace_code(code)

    assert report == expected_report
Example #5
0
    def test_infinite_loop_pass(self):
        # SETUP
        code = """\
while True:
    pass
"""
        expected_report = """\
RuntimeError: live coding message limit exceeded """
        tracer = TraceRunner()
        tracer.message_limit = 3

        # EXEC
        report = tracer.trace_code(code)

        # VERIFY
        self.assertReportEqual(expected_report, report)
Example #6
0
    def test_infinite_loop_by_count(self):
        # SETUP
        code = """\
n = 0
while True:
    n += 1
"""
        expected_report = """\
n = 0
      |       |
n = 1 | n = 2 | RuntimeError: live coding message limit exceeded """
        tracer = TraceRunner()
        tracer.message_limit = 8

        # EXEC
        report = tracer.trace_code(code)

        # VERIFY
        self.assertReportEqual(expected_report, report)
Example #7
0
def test_traced_decorator_avoids_message_limit():
    code = """\
from space_tracer import traced


def foo(n):
    s = 'x'
    for i in range(n):
        s += 'y'
    return s


@traced
def bar(n):
    s = 'a'
    for i in range(n):
        s += 'b'
    return s

print(foo(3000))
print(bar(3))
"""
    expected_report = """\
@traced                |
def bar(n):            | n = 3
    s = 'a'            | s = 'a'
    for i in range(n): | i = 0    | i = 1     | i = 2
        s += 'b'       | s = 'ab' | s = 'abb' | s = 'abbb'
    return s           | return 'abbb'"""

    tracer = TraceRunner()
    tracer.message_limit = 20

    with replace_input(code):
        report = tracer.trace_command(
            ['space_tracer', '--traced_file', 'example.py', 'example.py'])

    assert report == expected_report