File: test-pm.py.in

package info (click to toggle)
pydb 1.26-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 2,460 kB
  • ctags: 1,061
  • sloc: python: 4,200; perl: 2,479; sh: 873; lisp: 866; makefile: 634; ansic: 16
file content (85 lines) | stat: -rwxr-xr-x 2,789 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!@PYTHON@ -t
# $Id: test-pm.py.in,v 1.2 2008/11/17 19:06:39 rockyb Exp $ -*- Python -*-
"Unit test for Extended Python debugger's Post-Mortem (pm) commands "
import difflib, os, time, sys, unittest

top_builddir = "@top_builddir@"
if top_builddir[-1] != os.path.sep:
    top_builddir += os.path.sep
sys.path.insert(0, os.path.join(top_builddir, 'pydb'))
top_srcdir = "@top_srcdir@"
if top_srcdir[-1] != os.path.sep:
    top_srcdir += os.path.sep
sys.path.insert(0, os.path.join(top_srcdir, 'pydb'))

import pydb                

builddir     = "@builddir@"
if builddir[-1] != os.path.sep:
    builddir += os.path.sep

top_builddir = "@top_builddir@"
if top_builddir[-1] != os.path.sep:
    top_builddir += os.path.sep

srcdir = "@srcdir@"
if srcdir[-1] != os.path.sep:
    srcdir += os.path.sep

pydir        = os.path.join(top_builddir, "pydb")
pydb_short   = "pydb.py"
pydb_path    = os.path.join(pydir, pydb_short)

def raise_error():
    raise FloatingPointError

class PdbTests(unittest.TestCase):

    ## Don't use assertTrue to be compatible with older version of
    ## unittest
    
    def test_postmortem2(self):
        """Test post-mortem processing without a traceback"""
        pydb.post_mortem()
        self.assertEqual(True, True, "post-mortem test with no traceback")

    def test_postmortem(self):
        """Test post-mortem processing"""
        try:
            raise_error()
        except FloatingPointError:
            t = sys.exc_info()[2]
            outfile    = 'pm.out'
            rightfile  = os.path.join(srcdir, 'data', 'pm.right')
            errfile    = 'pm.err'
            old_stdout = sys.stdout
            old_stderr = sys.stderr
            sys.stdout = open(outfile, 'w')
            sys.stderr = open(errfile, 'w')
            pydb.post_mortem(t=t, dbg_cmds=None,
                             cmdfile=os.path.join(srcdir, 'pm.cmd'))
            sys.stdout.close()
            sys.stderr.close()
            sys.stdout = old_stdout
            sys.stderr = old_stderr
            fromfile  = rightfile
            fromdate  = time.ctime(os.stat(fromfile).st_mtime)
            fromlines = open(fromfile, 'U').readlines()
            tofile    = outfile
            todate    = time.ctime(os.stat(tofile).st_mtime)
            tolines   = open(tofile, 'U').readlines()
            
            diff = list(difflib.unified_diff(fromlines, tolines, fromfile,
                                             tofile, fromdate, todate))
            
            if len(diff) == 0:
                os.unlink(outfile)
                os.unlink(errfile)
            for line in diff:
                print line,
            self.assertEqual(0, len(diff), "post-mortem test")
            return 

        
if __name__ == "__main__":
    unittest.main()