python/dist/src/Lib/test test_traceback.py, 1.7, 1.8
Update of /cvsroot/python/python/dist/src/Lib/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19767/Lib/test Modified Files: test_traceback.py Log Message: SF #737473: Show up-to-date source code in tracebacks always. And add an optional argument 'filename' to linecache.checkcache() to enable checking caches per-file. Index: test_traceback.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_traceback.py,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- test_traceback.py 6 Nov 2002 11:45:15 -0000 1.7 +++ test_traceback.py 26 Oct 2004 09:16:41 -0000 1.8 @@ -40,6 +40,47 @@ self.assert_(len(err) == 3) self.assert_(err[1].strip() == "[x for x in x] = x") + def test_bug737473(self): + import sys, os, tempfile + savedpath = sys.path[:] + testdir = tempfile.mkdtemp() + try: + sys.path.insert(0, testdir) + testfile = os.path.join(testdir, 'test_bug737473.py') + print >> open(testfile, 'w'), """\ +def test(): + raise ValueError""" + + if hasattr(os, 'utime'): + os.utime(testfile, (0, 0)) + else: + import time + time.sleep(3) # not to stay in same mtime. + + if 'test_bug737473' in sys.modules: + del sys.modules['test_bug737473'] + import test_bug737473 + + try: + test_bug737473.test() + except ValueError: + # this loads source code to linecache + traceback.extract_tb(sys.exc_traceback) + + print >> open(testfile, 'w'), """\ +def test(): + raise NotImplementedError""" + reload(test_bug737473) + try: + test_bug737473.test() + except NotImplementedError: + src = traceback.extract_tb(sys.exc_traceback)[-1][-1] + self.failUnlessEqual(src, 'raise NotImplementedError') + finally: + sys.path[:] = savedpath + for f in os.listdir(testdir): + os.unlink(os.path.join(testdir, f)) + os.rmdir(testdir) def test_main(): run_unittest(TracebackCases)
participants (1)
-
perky@users.sourceforge.net