src/reportlab/lib/testutils.py
author robin <robin@reportlab.com>
Tue, 07 Mar 2017 10:00:34 +0000
changeset 4330 617ffa6bbdc8
parent 4302 f3ff56a22b2e
child 4338 6223e7fa13f6
permissions -rw-r--r--
changes for release 3.4.0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4330
617ffa6bbdc8 changes for release 3.4.0
robin <robin@reportlab.com>
parents: 4302
diff changeset
     1
#Copyright ReportLab Europe Ltd. 2000-2017
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
     2
#see license.txt for license details
4089
ca6c60fd1f62 testutils.py & rl_accel.py: use reportlab not __main__ to pacify App Engine, bump version to 3.1.10
robin
parents: 4006
diff changeset
     3
import reportlab
ca6c60fd1f62 testutils.py & rl_accel.py: use reportlab not __main__ to pacify App Engine, bump version to 3.1.10
robin
parents: 4006
diff changeset
     4
reportlab._rl_testing=True
ca6c60fd1f62 testutils.py & rl_accel.py: use reportlab not __main__ to pacify App Engine, bump version to 3.1.10
robin
parents: 4006
diff changeset
     5
del reportlab
4252
fe660f227cac changes for release 3.3.0
robin
parents: 4089
diff changeset
     6
__version__='3.3.0'
3029
eded59f94021 adding docstrings to lib
andy
parents: 2988
diff changeset
     7
__doc__="""Provides support for the test suite.
eded59f94021 adding docstrings to lib
andy
parents: 2988
diff changeset
     8
eded59f94021 adding docstrings to lib
andy
parents: 2988
diff changeset
     9
The test suite as a whole, and individual tests, need to share
eded59f94021 adding docstrings to lib
andy
parents: 2988
diff changeset
    10
certain support functions.  We have to put these in here so they
eded59f94021 adding docstrings to lib
andy
parents: 2988
diff changeset
    11
can always be imported, and so that individual tests need to import
eded59f94021 adding docstrings to lib
andy
parents: 2988
diff changeset
    12
nothing more than "reportlab.whatever..."
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    13
"""
3029
eded59f94021 adding docstrings to lib
andy
parents: 2988
diff changeset
    14
3914
180fb79614ec testutils.py: avoid copy import
robin
parents: 3907
diff changeset
    15
import sys, os, fnmatch, re
3871
4b2cdf036fd3 testutils.py: fix ConfigParser import for 2&3
robin
parents: 3862
diff changeset
    16
try:
4b2cdf036fd3 testutils.py: fix ConfigParser import for 2&3
robin
parents: 3862
diff changeset
    17
    from configparser import ConfigParser
4b2cdf036fd3 testutils.py: fix ConfigParser import for 2&3
robin
parents: 3862
diff changeset
    18
except ImportError:
4b2cdf036fd3 testutils.py: fix ConfigParser import for 2&3
robin
parents: 3862
diff changeset
    19
    from ConfigParser import ConfigParser
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    20
import unittest
4288
320d4d0667cf attempt to fix __loader__ issues in pyinstaller; version-->3.319
robin
parents: 4252
diff changeset
    21
from reportlab.lib.utils import isCompactDistro, __rl_loader__, rl_isdir, asUnicode
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    22
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    23
# Helper functions.
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    24
def isWritable(D):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    25
    try:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    26
        fn = '00DELETE.ME'
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    27
        f = open(fn, 'w')
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    28
        f.write('test of writability - can be deleted')
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    29
        f.close()
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    30
        if os.path.isfile(fn):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    31
            os.remove(fn)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    32
            return 1
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    33
    except:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    34
        return 0
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    35
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    36
_OUTDIR = None
2988
1540a4be3b99 reportlab: fixes to lib\testutils.py for testsFolder creation
rgbecker
parents: 2986
diff changeset
    37
RL_HOME = None
1540a4be3b99 reportlab: fixes to lib\testutils.py for testsFolder creation
rgbecker
parents: 2986
diff changeset
    38
testsFolder = None
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    39
def setOutDir(name):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    40
    """Is it a writable file system distro being invoked within
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    41
    test directory?  If so, can write test output here.  If not,
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    42
    it had better go in a temp directory.  Only do this once per
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    43
    process"""
2988
1540a4be3b99 reportlab: fixes to lib\testutils.py for testsFolder creation
rgbecker
parents: 2986
diff changeset
    44
    global _OUTDIR, RL_HOME, testsFolder
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    45
    if _OUTDIR: return _OUTDIR
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    46
    D = [d[9:] for d in sys.argv if d.startswith('--outdir=')]
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    47
    if D:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    48
        _OUTDIR = D[-1]
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    49
        try:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    50
            os.makedirs(_OUTDIR)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    51
        except:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    52
            pass
3328
4d7f836cd947 reportlab: fix 2to3 warnings
rgbecker
parents: 3326
diff changeset
    53
        for d in D: sys.argv.remove(d)
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    54
    else:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    55
        assert name=='__main__',"setOutDir should only be called in the main script"
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    56
        scriptDir=os.path.dirname(sys.argv[0])
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    57
        if not scriptDir: scriptDir=os.getcwd()
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    58
        _OUTDIR = scriptDir
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    59
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    60
    if not isWritable(_OUTDIR):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    61
        _OUTDIR = get_rl_tempdir('reportlab_test')
2988
1540a4be3b99 reportlab: fixes to lib\testutils.py for testsFolder creation
rgbecker
parents: 2986
diff changeset
    62
1540a4be3b99 reportlab: fixes to lib\testutils.py for testsFolder creation
rgbecker
parents: 2986
diff changeset
    63
    import reportlab
1540a4be3b99 reportlab: fixes to lib\testutils.py for testsFolder creation
rgbecker
parents: 2986
diff changeset
    64
    RL_HOME=reportlab.__path__[0]
1540a4be3b99 reportlab: fixes to lib\testutils.py for testsFolder creation
rgbecker
parents: 2986
diff changeset
    65
    if not os.path.isabs(RL_HOME): RL_HOME=os.path.normpath(os.path.abspath(RL_HOME))
1540a4be3b99 reportlab: fixes to lib\testutils.py for testsFolder creation
rgbecker
parents: 2986
diff changeset
    66
    topDir = os.path.dirname(RL_HOME)
1540a4be3b99 reportlab: fixes to lib\testutils.py for testsFolder creation
rgbecker
parents: 2986
diff changeset
    67
    testsFolder = os.path.join(topDir,'tests')
1540a4be3b99 reportlab: fixes to lib\testutils.py for testsFolder creation
rgbecker
parents: 2986
diff changeset
    68
    if not os.path.isdir(testsFolder):
1540a4be3b99 reportlab: fixes to lib\testutils.py for testsFolder creation
rgbecker
parents: 2986
diff changeset
    69
        testsFolder = os.path.join(os.path.dirname(topDir),'tests')
1540a4be3b99 reportlab: fixes to lib\testutils.py for testsFolder creation
rgbecker
parents: 2986
diff changeset
    70
    if not os.path.isdir(testsFolder):
3074
b7270812af81 reportlab: another attempt at fixing testsFolder
rgbecker
parents: 3055
diff changeset
    71
        if name=='__main__':
b7270812af81 reportlab: another attempt at fixing testsFolder
rgbecker
parents: 3055
diff changeset
    72
            scriptDir=os.path.dirname(sys.argv[0])
b7270812af81 reportlab: another attempt at fixing testsFolder
rgbecker
parents: 3055
diff changeset
    73
            if not scriptDir: scriptDir=os.getcwd()
b7270812af81 reportlab: another attempt at fixing testsFolder
rgbecker
parents: 3055
diff changeset
    74
            testsFolder = os.path.abspath(scriptDir)
b7270812af81 reportlab: another attempt at fixing testsFolder
rgbecker
parents: 3055
diff changeset
    75
        else:
b7270812af81 reportlab: another attempt at fixing testsFolder
rgbecker
parents: 3055
diff changeset
    76
            testsFolder = None
3076
6a959200100d testutils.py: make setOutDir put testsFolder parent on path
rgbecker
parents: 3074
diff changeset
    77
    if testsFolder:
6a959200100d testutils.py: make setOutDir put testsFolder parent on path
rgbecker
parents: 3074
diff changeset
    78
        sys.path.insert(0,os.path.dirname(testsFolder))
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    79
    return _OUTDIR
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    80
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    81
def outputfile(fn):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    82
    """This works out where to write test output.  If running
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    83
    code in a locked down file system, this will be a
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    84
    temp directory; otherwise, the output of 'test_foo.py' will
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    85
    normally be a file called 'test_foo.pdf', next door.
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    86
    """
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    87
    D = setOutDir(__name__)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    88
    if fn: D = os.path.join(D,fn)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    89
    return D
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    90
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    91
def printLocation(depth=1):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    92
    if sys._getframe(depth).f_locals.get('__name__')=='__main__':
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    93
        outDir = outputfile('')
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    94
        if outDir!=_OUTDIR:
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
    95
            print('Logs and output files written to folder "%s"' % outDir)
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    96
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    97
def makeSuiteForClasses(*classes):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    98
    "Return a test suite with tests loaded from provided classes."
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
    99
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   100
    suite = unittest.TestSuite()
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   101
    loader = unittest.TestLoader()
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   102
    for C in classes:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   103
        suite.addTest(loader.loadTestsFromTestCase(C))
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   104
    return suite
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   105
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   106
def getCVSEntries(folder, files=1, folders=0):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   107
    """Returns a list of filenames as listed in the CVS/Entries file.
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   108
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   109
    'folder' is the folder that should contain the CVS subfolder.
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   110
    If there is no such subfolder an empty list is returned.
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   111
    'files' is a boolean; 1 and 0 means to return files or not.
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   112
    'folders' is a boolean; 1 and 0 means to return folders or not.
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   113
    """
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   114
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   115
    join = os.path.join
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   116
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   117
    # If CVS subfolder doesn't exist return empty list.
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   118
    try:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   119
        f = open(join(folder, 'CVS', 'Entries'))
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   120
    except IOError:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   121
        return []
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   122
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   123
    # Return names of files and/or folders in CVS/Entries files.
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   124
    allEntries = []
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   125
    for line in f.readlines():
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   126
        if folders and line[0] == 'D' \
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   127
           or files and line[0] != 'D':
3794
398ea04239b5 string module usage minimization
robin
parents: 3721
diff changeset
   128
            entry = line.split('/')[1]
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   129
            if entry:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   130
                allEntries.append(join(folder, entry))
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   131
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   132
    return allEntries
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   133
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   134
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   135
# Still experimental class extending ConfigParser's behaviour.
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   136
class ExtConfigParser(ConfigParser):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   137
    "A slightly extended version to return lists of strings."
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   138
4302
f3ff56a22b2e bump version --> 3.3.25
robin
parents: 4288
diff changeset
   139
    pat = re.compile(r'\s*\[.*\]\s*')
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   140
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   141
    def getstringlist(self, section, option):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   142
        "Coerce option to a list of strings or return unchanged if that fails."
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   143
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3076
diff changeset
   144
        value = ConfigParser.get(self, section, option)
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   145
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   146
        # This seems to allow for newlines inside values
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   147
        # of the config file, but be careful!!
3794
398ea04239b5 string module usage minimization
robin
parents: 3721
diff changeset
   148
        val = value.replace('\n', '')
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   149
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   150
        if self.pat.match(val):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   151
            return eval(val)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   152
        else:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   153
            return value
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   154
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   155
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   156
# This class as suggested by /F with an additional hook
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   157
# to be able to filter filenames.
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   158
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   159
class GlobDirectoryWalker:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   160
    "A forward iterator that traverses files in a directory tree."
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   161
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   162
    def __init__(self, directory, pattern='*'):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   163
        self.index = 0
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   164
        self.pattern = pattern
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   165
        directory.replace('/',os.sep)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   166
        if os.path.isdir(directory):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   167
            self.stack = [directory]
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   168
            self.files = []
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   169
        else:
4288
320d4d0667cf attempt to fix __loader__ issues in pyinstaller; version-->3.319
robin
parents: 4252
diff changeset
   170
            if not isCompactDistro() or not __rl_loader__ or not rl_isdir(directory):
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   171
                raise ValueError('"%s" is not a directory' % directory)
4288
320d4d0667cf attempt to fix __loader__ issues in pyinstaller; version-->3.319
robin
parents: 4252
diff changeset
   172
            self.directory = directory[len(__rl_loader__.archive)+len(os.sep):]
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   173
            pfx = self.directory+os.sep
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   174
            n = len(pfx)
4288
320d4d0667cf attempt to fix __loader__ issues in pyinstaller; version-->3.319
robin
parents: 4252
diff changeset
   175
            self.files = list(map(lambda x, n=n: x[n:],list(filter(lambda x,pfx=pfx: x.startswith(pfx),list(__rl_loader__._files.keys())))))
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   176
            self.stack = []
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   177
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   178
    def __getitem__(self, index):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   179
        while 1:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   180
            try:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   181
                file = self.files[self.index]
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   182
                self.index = self.index + 1
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   183
            except IndexError:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   184
                # pop next directory from stack
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   185
                self.directory = self.stack.pop()
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   186
                self.files = os.listdir(self.directory)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   187
                # now call the hook
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   188
                self.files = self.filterFiles(self.directory, self.files)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   189
                self.index = 0
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   190
            else:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   191
                # got a filename
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   192
                fullname = os.path.join(self.directory, file)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   193
                if os.path.isdir(fullname) and not os.path.islink(fullname):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   194
                    self.stack.append(fullname)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   195
                if fnmatch.fnmatch(file, self.pattern):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   196
                    return fullname
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   197
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   198
    def filterFiles(self, folder, files):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   199
        "Filter hook, overwrite in subclasses as needed."
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   200
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   201
        return files
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   202
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   203
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   204
class RestrictedGlobDirectoryWalker(GlobDirectoryWalker):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   205
    "An restricted directory tree iterator."
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   206
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   207
    def __init__(self, directory, pattern='*', ignore=None):
3326
ce725978d11c Initial Python3 compatibility fixes
damian
parents: 3076
diff changeset
   208
        GlobDirectoryWalker.__init__(self, directory, pattern)
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   209
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   210
        if ignore == None:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   211
            ignore = []
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   212
        self.ignoredPatterns = []
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   213
        if type(ignore) == type([]):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   214
            for p in ignore:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   215
                self.ignoredPatterns.append(p)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   216
        elif type(ignore) == type(''):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   217
            self.ignoredPatterns.append(ignore)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   218
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   219
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   220
    def filterFiles(self, folder, files):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   221
        "Filters all items from files matching patterns to ignore."
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   222
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   223
        indicesToDelete = []
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   224
        for i in range(len(files)):
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   225
            f = files[i]
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   226
            for p in self.ignoredPatterns:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   227
                if fnmatch.fnmatch(f, p):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   228
                    indicesToDelete.append(i)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   229
        indicesToDelete.reverse()
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   230
        for i in indicesToDelete:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   231
            del files[i]
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   232
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   233
        return files
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   234
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   235
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   236
class CVSGlobDirectoryWalker(GlobDirectoryWalker):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   237
    "An directory tree iterator that checks for CVS data."
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   238
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   239
    def filterFiles(self, folder, files):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   240
        """Filters files not listed in CVS subfolder.
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   241
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   242
        This will look in the CVS subfolder of 'folder' for
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   243
        a file named 'Entries' and filter all elements from
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   244
        the 'files' list that are not listed in 'Entries'.
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   245
        """
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   246
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   247
        join = os.path.join
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   248
        cvsFiles = getCVSEntries(folder)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   249
        if cvsFiles:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   250
            indicesToDelete = []
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   251
            for i in range(len(files)):
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   252
                f = files[i]
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   253
                if join(folder, f) not in cvsFiles:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   254
                    indicesToDelete.append(i)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   255
            indicesToDelete.reverse()
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   256
            for i in indicesToDelete:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   257
                del files[i]
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   258
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   259
        return files
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   260
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   261
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   262
# An experimental untested base class with additional 'security'.
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   263
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   264
class SecureTestCase(unittest.TestCase):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   265
    """Secure testing base class with additional pre- and postconditions.
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   266
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   267
    We try to ensure that each test leaves the environment it has
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   268
    found unchanged after the test is performed, successful or not.
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   269
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   270
    Currently we restore sys.path and the working directory, but more
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   271
    of this could be added easily, like removing temporary files or
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   272
    similar things.
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   273
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   274
    Use this as a base class replacing unittest.TestCase and call
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   275
    these methods in subclassed versions before doing your own
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   276
    business!
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   277
    """
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   278
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   279
    def setUp(self):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   280
        "Remember sys.path and current working directory."
3914
180fb79614ec testutils.py: avoid copy import
robin
parents: 3907
diff changeset
   281
        self._initialPath = sys.path[:]
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   282
        self._initialWorkDir = os.getcwd()
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   283
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   284
    def tearDown(self):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   285
        "Restore previous sys.path and working directory."
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   286
        sys.path = self._initialPath
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   287
        os.chdir(self._initialWorkDir)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   288
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   289
class NearTestCase(unittest.TestCase):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   290
    def assertNear(a,b,accuracy=1e-5):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   291
        if isinstance(a,(float,int)):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   292
            if abs(a-b)>accuracy:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   293
                raise AssertionError("%s not near %s" % (a, b))
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   294
        else:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   295
            for ae,be in zip(a,b):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   296
                if abs(ae-be)>accuracy:
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   297
                    raise AssertionError("%s not near %s" % (a, b))
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   298
    assertNear = staticmethod(assertNear)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   299
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   300
class ScriptThatMakesFileTest(unittest.TestCase):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   301
    """Runs a Python script at OS level, expecting it to produce a file.
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   302
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   303
    It CDs to the working directory to run the script."""
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   304
    def __init__(self, scriptDir, scriptName, outFileName, verbose=0):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   305
        self.scriptDir = scriptDir
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   306
        self.scriptName = scriptName
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   307
        self.outFileName = outFileName
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   308
        self.verbose = verbose
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   309
        # normally, each instance is told which method to run)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   310
        unittest.TestCase.__init__(self)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   311
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   312
    def setUp(self):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   313
        self.cwd = os.getcwd()
3055
af8146d7cf65 Fixed wrong import - tests.utils does not exist anymore.
jonas
parents: 3029
diff changeset
   314
        global testsFolder
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   315
        scriptDir=self.scriptDir
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   316
        if not os.path.isabs(scriptDir):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   317
            scriptDir=os.path.join(testsFolder,scriptDir)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   318
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   319
        os.chdir(scriptDir)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   320
        assert os.path.isfile(self.scriptName), "Script %s not found!" % self.scriptName
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   321
        if os.path.isfile(self.outFileName):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   322
            os.remove(self.outFileName)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   323
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   324
    def tearDown(self):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   325
        os.chdir(self.cwd)
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   326
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   327
    def runTest(self):
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   328
        fmt = sys.platform=='win32' and '"%s" %s' or '%s %s'
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   329
        p = os.popen(fmt % (sys.executable,self.scriptName),'r')
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   330
        out = p.read()
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   331
        if self.verbose:
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   332
            print(out)
2986
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   333
        status = p.close()
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   334
        assert os.path.isfile(self.outFileName), "File %s not created!" % self.outFileName
89edcdd280a7 tests.utils --> reportlab.lib.testutils
rgbecker
parents:
diff changeset
   335
3907
ebce55a07ce9 testutils.py: added equalStrings
robin
parents: 3871
diff changeset
   336
def equalStrings(a,b,enc='utf8'):
ebce55a07ce9 testutils.py: added equalStrings
robin
parents: 3871
diff changeset
   337
    return a==b if type(a)==type(b) else asUnicode(a,enc)==asUnicode(b,enc)
4006
028bdf783369 testutils.py: add eqCheck function
robin
parents: 3936
diff changeset
   338
028bdf783369 testutils.py: add eqCheck function
robin
parents: 3936
diff changeset
   339
def eqCheck(r,x):
028bdf783369 testutils.py: add eqCheck function
robin
parents: 3936
diff changeset
   340
    if r!=x:
028bdf783369 testutils.py: add eqCheck function
robin
parents: 3936
diff changeset
   341
        print('Strings unequal\nexp: %s\ngot: %s' % (ascii(x),ascii(r)))