# -----------------------------------------------------------------------
# Copyright (C) 2004 Chris Ottrey
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
# -----------------------------------------------------------------------
#
# This code is part of the pytvgrab project:
# http://pytvgrab.sourceforge.net
#
# -----------------------------------------------------------------------
# Subversion Information, do not edit
#
# $Rev: 255 $
# $LastChangedDate: 2004-11-12 13:35:28 +1100 (Fri, 12 Nov 2004) $
# $LastChangedRevision: 255 $
# $LastChangedBy: ottrey $
#
# $Log: $
#
"""\
This calls the python unittest module to perform unit tests.
It has some trickery to ensures that the calling module is regression
tested each time it is changed, when it gets imported from elsewhere.
Hopefully some will put this in the python unittest module one day.
"""
import os
import sys
import string
import unittest
from unittest import *
import i18n
import traceback
def print_exc_plus(limit=None, file=None):
"""
Print the usual traceback information, followed by a listing of all the
local variables in each frame.
code based on http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52215
"""
tb = sys.exc_info()[2]
while tb.tb_next:
tb = tb.tb_next
stack = []
f = tb.tb_frame
while f:
stack.append(f)
f = f.f_back
stack.reverse()
traceback.print_exc(limit, file)
traceback._print(file)
traceback._print(file, _( 'Locals by frame, innermost last') )
for frame in stack:
traceback._print(file)
traceback._print(file, _( 'Frame %s in %s at line %s' ) %
(frame.f_code.co_name, frame.f_code.co_filename, frame.f_lineno))
for key, value in frame.f_locals.items():
traceback._print(file, '\t%20s = %s' % (key, repr(value)))
# print_exc_plus()
def main():
caller=sys._getframe(1).f_globals
file =caller.get('__file__', None)
module=caller.get('__name__', None)
if file and module:
if file[-3:] == '.py' and module.find('.') < 0:
sys.stderr.write( _( 'Unit testing %s\n' ) % module)
try:
unittest.main(module=module)
except SystemExit, e:
if e.code:
compiled_file=file+'c'
if module != '__main__':
#sys.stderr.write('Removing compiled file: %s\n' % compiled_file)
try:
os.remove(compiled_file)
except:
pass # gentoo's ebuild barfs on this for some reason.
#print_exc_plus(file=sys.stderr)
sys.exit(1)
# main()
|