def test_increment(self):
        # SETUP
        code = """\
i = 1
i += 1
"""
        expected_report = """\
i = 1 
i = 2 """
        # EXEC
        report = CodeTracer().trace_code(code)

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report.splitlines())
Exemple #2
0
    def test_increment(self):
        # SETUP
        code = """\
i = 1
i += 1
"""
        expected_report = """\
i = 1 
i = 2 """
        # EXEC
        report = CodeTracer().trace_code(code)

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report.splitlines())
    def test_method_call(self):
        # SETUP
        code = """\
a = [2, 1]
a.sort()
a.sort() # second call makes no change, nothing printed
"""
        expected_report = """\
a = [2, 1] 
a = [1, 2] """
        # EXEC
        report = CodeTracer().trace_code(code)

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report.splitlines())
Exemple #4
0
    def test_method_call(self):
        # SETUP
        code = """\
a = [2, 1]
a.sort()
a.sort() # second call makes no change, nothing printed
"""
        expected_report = """\
a = [2, 1] 
a = [1, 2] """
        # EXEC
        report = CodeTracer().trace_code(code)

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report.splitlines())
    def test_mutable(self):
        # SETUP
        code = """\
a = [1, 2, [3, 4]]
a[0] = 9
a[2][1] = 8
"""
        expected_report = """\
a = [1, 2, [3, 4]] 
a = [9, 2, [3, 4]] 
a = [9, 2, [3, 8]] """
        # EXEC
        report = CodeTracer().trace_code(code)

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report.splitlines())
    def test_loop(self):
        # SETUP
        code = """\
i = 1
for j in range(3):
    i += j
"""
        expected_report = """\
i = 1 
j = 0 | j = 1 | j = 2 
i = 1 | i = 2 | i = 4 """
        # EXEC
        report = CodeTracer().trace_code(code)

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report.splitlines())
Exemple #7
0
    def test_mutable(self):
        # SETUP
        code = """\
a = [1, 2, [3, 4]]
a[0] = 9
a[2][1] = 8
"""
        expected_report = """\
a = [1, 2, [3, 4]] 
a = [9, 2, [3, 4]] 
a = [9, 2, [3, 8]] """
        # EXEC
        report = CodeTracer().trace_code(code)

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report.splitlines())
Exemple #8
0
    def test_loop(self):
        # SETUP
        code = """\
i = 1
for j in range(3):
    i += j
"""
        expected_report = """\
i = 1 
j = 0 | j = 1 | j = 2 
i = 1 | i = 2 | i = 4 """
        # EXEC
        report = CodeTracer().trace_code(code)

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report.splitlines())
    def test_nested_loop(self):
        # SETUP
        code = """\
n = 0
for i in range(2):
    n += i
    for j in range(3):
        n += j
"""
        expected_report = """\
n = 0 
i = 0                 | i = 1 
n = 0                 | n = 4 
j = 0 | j = 1 | j = 2 | j = 0 | j = 1 | j = 2 
n = 0 | n = 1 | n = 3 | n = 4 | n = 5 | n = 7 """
        # EXEC
        report = CodeTracer().trace_code(code)

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report.splitlines())
Exemple #10
0
    def test_multivalue_yield(self):
        # SETUP
        code = """\
def foo():
    yield 1, 2
        
for x in foo():
    pass
"""
        expected_report = """\

yield 1, 2 

x = (1, 2) """

        # EXEC
        report = CodeTracer().trace_code(code)

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report.splitlines())
Exemple #11
0
    def test_nested_loop(self):
        # SETUP
        code = """\
n = 0
for i in range(2):
    n += i
    for j in range(3):
        n += j
"""
        expected_report = """\
n = 0 
i = 0                 | i = 1 
n = 0                 | n = 4 
j = 0 | j = 1 | j = 2 | j = 0 | j = 1 | j = 2 
n = 0 | n = 1 | n = 3 | n = 4 | n = 5 | n = 7 """
        # EXEC
        report = CodeTracer().trace_code(code)

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report.splitlines())
    def test_multivalue_yield(self):
        # SETUP
        code = """\
def foo():
    yield 1, 2
        
for x in foo():
    pass
"""
        expected_report = """\

yield 1, 2 

x = (1, 2) """

        # EXEC
        report = CodeTracer().trace_code(code)

        # VERIFY        
        self.assertEqual(expected_report.splitlines(), report.splitlines())
    def test_nested_method_call(self):
        # SETUP
        code = """\
class Foo(object):
    pass

f = Foo()
f.items = []
f.items.append(2)
"""
        expected_report = """\




f.items = [] 
f.items = [2] """
        # EXEC
        report = CodeTracer().trace_code(code)

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report.splitlines())
Exemple #14
0
    def test_nested_method_call(self):
        # SETUP
        code = """\
class Foo(object):
    pass

f = Foo()
f.items = []
f.items.append(2)
"""
        expected_report = """\




f.items = [] 
f.items = [2] """
        # EXEC
        report = CodeTracer().trace_code(code)

        # VERIFY
        self.assertEqual(expected_report.splitlines(), report.splitlines())