unittest2.py :  » Web-Services » python-xmltv » pytvgrab-lib-0.5.1 » lib » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Services » python xmltv 
python xmltv » pytvgrab lib 0.5.1 » lib » unittest2.py
# -----------------------------------------------------------------------
# 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()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.