Beispiel #1
0
 def test_coverage(self):
     test_filename = here + '_sandbox_test_coverage.py'
     with open(test_filename) as student_file:
         student_code = student_file.read()
     contextualize_report(student_code)
     student = Sandbox()
     student.tracer_style = 'coverage'
     student.run(student_code, filename=test_filename)
     self.assertIsNone(student.exception)
     self.assertEqual(student.trace.pc_covered, 80.0)
     self.assertEqual(student.trace.lines, {1, 2, 4, 7, 10, 11, 12, 13})
Beispiel #2
0
 def test_calls(self):
     student_code = dedent('''
         def x(n):
             if n > 0:
                 return x(n-1)
             return 0
         x(5)
     ''')
     student = Sandbox()
     student.tracer_style = 'calls'
     student.run(student_code, filename='student.py')
     self.assertEqual(len(student.trace.calls['x']), 6)
Beispiel #3
0
 def test_coverage(self):
     test_filename = here + '_sandbox_test_coverage.py'
     with open(test_filename) as student_file:
         student_code = student_file.read()
     contextualize_report(student_code)
     student = Sandbox()
     student.tracer_style = 'native'
     student.run(student_code, filename=test_filename)
     self.assertIsNone(student.exception)
     #self.assertEqual(round(student.trace.pc_covered), 85)
     self.assertEqual(student.trace.lines,
                      [1, 2, 3, 4, 6, 9, 12, 16, 14, 15, 17])
Beispiel #4
0
 def test_coverage_native(self):
     test_filename = here + '_sandbox_test_coverage.py'
     with open(test_filename) as student_file:
         student_code = student_file.read()
     contextualize_report(student_code)
     student = Sandbox()
     student.tracer_style = 'native'
     student.run(student_code, filename=test_filename)
     self.assertIsNone(student.exception)
     self.assertEqual(student.trace.lines,
                      [1, 2, 3, 4, 6, 9, 12, 16, 14, 15, 17])
     self.assertEqual(student.trace.calls, {
         'z': [{
             'args': (0, ),
             'banana': 2,
             'kwargs': {
                 'apple': 8
             },
             'p': 3
         }]
     })