File:  [CENS] / python / pyGiNaC / test4 / test_all.py
Revision 1.7: download - view: text, annotated - select for diffs - revision graph
Thu Nov 22 14:50:04 2001 UTC (16 years ago) by pearu
Branches: MAIN
CVS tags: HEAD
See NEWS.txt for changes. There too many changes to list them here

#!/usr/bin/env python
"""
  test_all - run all PyGiNaC tests.
  Usage:
    python test_all.py [-v]
"""
"""
  This file is part of the PyGiNaC package.
  http://cens.ioc.ee/projects/pyginac/

  $Revision: 1.7 $
  $Id: test_all.py,v 1.7 2001-11-22 14:50:04 pearu Exp $
 
  Copyright 2001 Pearu Peterson all rights reserved,
  Pearu Peterson <pearu@cens.ioc.ee>
  Permission to use, modify, and distribute this software is given under the
  terms of the LGPL.  See http://www.fsf.org
 
  NO WARRANTY IS EXPRESSED OR IMPLIED.  USE AT YOUR OWN RISK.
"""

import sys
import os
from distutils import util

try:
    p = os.path.join (os.path.dirname (__file__),'..')
except NameError:
    p = '.'
sys.path.insert(0,os.path.abspath(os.path.join(p,
                                               'build',"lib.%s-%s" % \
                                               (util.get_platform(),
                                                sys.version[0:3]))))
save_caches = []
def get_save_cache():
    i = len(save_caches)
    save_caches.append({})
    def save(i=i,**kws):
        for k,v in kws.items():
            save_caches[i][k] = v
    import ginac
    for k in ginac.__all__:
        save_caches[i][k] = getattr(ginac,k)
    save(test_save=save)
    return save_caches[i]

def get_methods(c):
    r = []
    for n in dir(c):
        if n in ['__doc__','__module__']: continue
        if n[0]=='_' and n[:2]!='__': continue
        r.append(n)
    for b in c.__bases__:
        for n in get_methods(b):
            if n not in r:
                r.append(n)
    return r

def test(module):
    import doctest,types
    dict = get_save_cache()
    nf,n=doctest.testmod(module, globs=dict)
    print ' ',n-nf,'tests passed',
    if nf: print 'and',nf,'failed'
    else: print
    c = getattr(module,module.__name__)
    d = c.__dict__
    if type(c) is not types.ClassType:
        return nf,n
    tests = d.keys()
    todo = []
    if c.__bases__:
        for k in get_methods(c.__bases__[0]):
            if k not in tests:
                todo.append(k)
    if todo:
        print '  untested:',
        out = ''
        w = 0
        for t in todo:
            if out:
                out += ', '
            out += t
            if len(out)>50:
                print w*' ',out
                out = ''
                w = 12
        print w*' ',out
    print
    return nf,n

def _test():
    import warnings
    import ginac
    nf_total,n_total = 0,0
    for t in ginac.__all__:
        try: exec 'import test_%s as m'%t
        except ImportError:
            print 'Skipping test_'+t
            continue
        print 'Running test_'+t+':'
        nf,n = m._test()
        nf_total += nf
        n_total += n
    print '\nIn total:\n\t',n_total-nf_total,'tests passed',
    if nf_total: print 'and',nf_total,'failed'
    else: print

if __name__ == "__main__":
    _test()

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>