Esempio n. 1
0
    def test_get_tb_source_func(self):
        # func frame
        def check_even(n):
            print
            n
            assert n % 2 == 0

        try:
            check_even(1)
        except AssertionError:
            et, ev, tb = sys.exc_info()
            lines, lineno = tbsource(tb)
            out = textwrap.dedent(''.join(lines))
            if sys.version_info < (3,):
                first_line = '    print n\n'
            else:
                first_line = '    print(n)\n'
            self.assertEqual(out,
                             first_line +
                             '    assert n % 2 == 0\n'
                             'try:\n'
                             '    check_even(1)\n'
                             'except AssertionError:\n'
                             '    et, ev, tb = sys.exc_info()\n'
                             )
            self.assertEqual(lineno, 3)
Esempio n. 2
0
 def test_get_tb_source_simple(self):
     # no func frame
     try:
         assert False
     except AssertionError:
         et, ev, tb = sys.exc_info()
         lines, lineno = tbsource(tb, 1)
         self.assertEqual(''.join(lines).strip(), 'assert False')
         self.assertEqual(lineno, 0)
Esempio n. 3
0
 def test_get_tb_source_simple(self):
     # no func frame
     try:
         assert False
     except AssertionError:
         et, ev, tb = sys.exc_info()
         lines, lineno = tbsource(tb, 1)
         self.assertEqual(''.join(lines).strip(), 'assert False')
         self.assertEqual(lineno, 0)
Esempio n. 4
0
 def test_get_tb_source_func(self):        
     # func frame
     def check_even(n):
         print n
         assert n % 2 == 0
     try:
         check_even(1)
     except AssertionError:
         et, ev, tb = sys.exc_info()
         lines, lineno = tbsource(tb)
         out = textwrap.dedent(''.join(lines))
         self.assertEqual(out,
                          '    print n\n'
                          '    assert n % 2 == 0\n'
                          'try:\n'
                          '    check_even(1)\n'
                          'except AssertionError:\n'
                          '    et, ev, tb = sys.exc_info()\n'
                          )
         self.assertEqual(lineno, 3)