tests/test_rl_accel.py
author robin <robin@reportlab.com>
Fri, 23 Mar 2018 16:02:08 +0000
changeset 4389 61a7f0840d00
parent 4367 9960d82643bf
child 4413 dec33c7e7922
permissions -rw-r--r--
more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4252
fe660f227cac changes for release 3.3.0
robin
parents: 4239
diff changeset
     1
__version__='3.3.0'
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
     2
__doc__='''basic tests.'''
4367
9960d82643bf remove ascii, cmp & xrange builtins abuse; version-->3.4.15
robin <robin@reportlab.com>
parents: 4252
diff changeset
     3
from reportlab import xrange, ascii
2984
c63f149d55aa tests.utils --> reportlab.lib.testutils
rgbecker
parents: 2977
diff changeset
     4
from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, printLocation
4239
75c7de3058a6 more changes related to pypy testing
robin
parents: 4003
diff changeset
     5
from reportlab.lib.utils import asBytes, isPyPy
2984
c63f149d55aa tests.utils --> reportlab.lib.testutils
rgbecker
parents: 2977
diff changeset
     6
setOutDir(__name__)
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
     7
2966
c9df63ccabdf reportlab-2.2: major changes to make tests run
rgbecker
parents: 2963
diff changeset
     8
import unittest
3862
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
     9
def getFuncs(name):
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
    10
    return (_c_funcs.get(name,None),'c'),(_py_funcs.get(name,None),'py')
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    11
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    12
def getrc(defns,depth=1):
4239
75c7de3058a6 more changes related to pypy testing
robin
parents: 4003
diff changeset
    13
    if isPyPy: return ''
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    14
    from sys import getrefcount, _getframe
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    15
    f = _getframe(depth)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    16
    G0 = f.f_globals
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    17
    L = f.f_locals
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    18
    if L is not G0:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    19
        LL = [L]
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    20
        while 1:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    21
            f = f.f_back
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    22
            G = f.f_globals
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    23
            L = f.f_locals
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    24
            if G is not G0 or G is L: break
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    25
            LL.append(L)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    26
        L = {}
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    27
        LL.reverse()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    28
        for l in LL:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    29
            L.update(l)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    30
    else:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    31
        L = L.copy()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    32
    G0 = G0.copy()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    33
    return ' '.join([str(getrefcount(eval(x,L,G0))-1) for x in defns.split()])
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    34
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    35
def checkrc(defns,rcv0):
4239
75c7de3058a6 more changes related to pypy testing
robin
parents: 4003
diff changeset
    36
    if isPyPy: return ''
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    37
    rcv1 = getrc(defns,2)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    38
    return ' '.join(["%s %s-->%s" % (x,v,w) for x,v,w in zip(defns.split(),rcv0.split(),rcv1.split()) if v!=w])
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    39
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    40
class RlAccelTestCase(unittest.TestCase):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    41
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    42
    def testFpStr(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    43
        # should give siz decimal places if less than 1.
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    44
        # if more, give up to seven sig figs
3862
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
    45
        for func, kind in getFuncs('fp_str'):
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
    46
            assert func(1,2,3)=='1 2 3', "%s fp_str(1,2,3)=='1 2 3' fails with value %s!" % (kind,ascii(func(1,2,3)))
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
    47
            assert func(1) == '1', "%s fp_str(1) == '1' fails with value %s!" % (kind,ascii(func(1)))
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
    48
            assert func(595.275574) == '595.2756', "%s fp_str(595.275574) == '595.2756' fails with value %s!" % (kind,ascii(func(595.25574)))
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
    49
            assert func(59.5275574) == '59.52756', "%s fp_str(59.5275574) == '59.52756' fails with value %s!" % (kind,ascii(func(59.525574)))
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
    50
            assert func(5.95275574) == '5.952756', "%s fp_str(5.95275574) == '5.952756' fails with value %s!" % (kind,ascii(func(5.9525574)))
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    51
3862
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
    52
    def testAsciiBase85Encode(self):
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
    53
        for func, kind in getFuncs('asciiBase85Encode'):
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
    54
            assert func('Dragan Andric')=='6ul^K@;[2RDIdd%@f~>',"%s asciiBase85Encode('Dragan Andric')=='6ul^K@;[2RDIdd%@f~>' fails with value %s!" % (
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
    55
                    kind,ascii(func('Dragan Andric')))
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    56
3862
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
    57
    def testAsciiBase85Decode(self):
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
    58
        for func, kind in getFuncs('asciiBase85Decode'):
4003
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    59
            assert func('6ul^K@;[2RDIdd%@f~>')==b'Dragan Andric',"%s asciiBase85Decode('6ul^K@;[2RDIdd%@f~>')=='Dragan Andric' fails with value %s!" % (
3862
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
    60
                    kind,ascii(func('Dragan Andric')))
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    61
4003
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    62
    def testAsciiBase85RoundTrip(self):
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    63
        plain = 'What is the average velocity of a sparrow?'
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    64
        eFuncs = getFuncs('asciiBase85Encode')
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    65
        for i in xrange(256):
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    66
            for j,(dfunc, kind) in enumerate(getFuncs('asciiBase85Decode')):
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    67
                efunc = eFuncs[j][0]
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    68
                encoded = efunc(plain)
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    69
                decoded = dfunc(encoded)
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    70
                assert decoded == asBytes(plain,'latin1'), "Round-trip AsciiBase85 failed for %s & %s\nplain=%s\nencoded=%s\ndecoded=%s" % (
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    71
                        ascii(efunc),ascii(dfunc), ascii(plain), ascii(encoded), ascii(decoded))
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    72
                if not j:
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    73
                    enc0 = encoded
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    74
                    dec0 = decoded
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    75
                else:
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    76
                    assert encoded==enc0, " Python & C encodings differ failed for %s & %s\nplain=%s\nencode0=%s\nencoded=%s\ndecode0=%sdecoded=%s" % (
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    77
                        ascii(efunc),ascii(dfunc), ascii(plain), ascii(enc0), ascii(encoded), ascii(dec0), ascii(decoded))
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    78
                    assert decoded==dec0, " Python & C decodings differ failed for %s & %s\nplain=%s\nencode0=%s\nencoded=%s\ndecode0=%sdecoded=%s" % (
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    79
                        ascii(efunc),ascii(dfunc), ascii(plain), ascii(enc0), ascii(encoded), ascii(dec0), ascii(decoded))
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    80
            plain += chr(i)
623f585f5fbc test_rl_accel.py & test_pdfbase_pdfutils.py : fix for new a85 decode output
robin
parents: 3877
diff changeset
    81
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    82
    def testEscapePDF(self):
3862
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
    83
        for func, kind in getFuncs('escapePDF'):
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
    84
            assert func('(test)')=='\\(test\\)',"%s escapePDF('(test)')=='\\\\(test\\\\)' fails with value %s!" % (
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
    85
                    kind,ascii(func('(test)')))
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    86
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    87
    def testCalcChecksum(self):
3862
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
    88
        for func, kind in getFuncs('calcChecksum'):
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
    89
            assert func('test')==1952805748, "%s calcChecksum('test')==1952805748 fails with value %s!" % (
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
    90
                    kind,ascii(func(rawBytes('test'))))
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    91
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    92
    def test_instanceStringWidth(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    93
        from reportlab.pdfbase.pdfmetrics import registerFont, getFont, _fonts, unicode2T1
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    94
        from reportlab.pdfbase.ttfonts import TTFont
2977
beca8d75f400 reportlab: remove LetErrorRobot-Chrome, rina & luxi. Add DarkGardenMK and fix tests
rgbecker
parents: 2966
diff changeset
    95
        ttfn = 'Vera'
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    96
        t1fn = 'Times-Roman'
2977
beca8d75f400 reportlab: remove LetErrorRobot-Chrome, rina & luxi. Add DarkGardenMK and fix tests
rgbecker
parents: 2966
diff changeset
    97
        registerFont(TTFont(ttfn, "Vera.ttf"))
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    98
        ttf = getFont(ttfn)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
    99
        t1f = getFont(t1fn)
3862
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   100
        testCp1252 = b'copyright \xa9 trademark \x99 registered \xae ReportLab! Ol\xe9!'
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   101
        enc='cp1252'
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   102
        senc = 'utf8'
3862
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   103
        ts = b'ABCDEF\xce\x91\xce\xb2G'
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   104
        utext = b'ABCDEF\xce\x91\xce\xb2G'.decode(senc)
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   105
        fontSize = 12
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   106
        defns="ttfn t1fn ttf t1f testCp1252 enc senc ts utext fontSize ttf.face ttf.face.charWidths ttf.face.defaultWidth t1f.widths t1f.encName t1f.substitutionFonts _fonts"
3867
b0fd3fd9faee test_rl_accel.py: allow refcounts to stabilize
robin
parents: 3862
diff changeset
   107
        import sys
3876
cf5368404b78 test_rl_accel.py: make it work more usefully
robin
parents: 3867
diff changeset
   108
        F = []
3867
b0fd3fd9faee test_rl_accel.py: allow refcounts to stabilize
robin
parents: 3862
diff changeset
   109
        def tfunc(f,ts,fontSize,enc,funcs,i):
b0fd3fd9faee test_rl_accel.py: allow refcounts to stabilize
robin
parents: 3862
diff changeset
   110
            w1 = funcs[i][0](f,ts,fontSize,enc)
b0fd3fd9faee test_rl_accel.py: allow refcounts to stabilize
robin
parents: 3862
diff changeset
   111
            w2 = funcs[1][0](f,ts,fontSize,enc) #python version
3876
cf5368404b78 test_rl_accel.py: make it work more usefully
robin
parents: 3867
diff changeset
   112
            if abs(w1-w2)>=1e-10: F.append("stringWidth%s(%r,%r,%s,%r)-->%r != f._py_stringWidth(...)-->%r" % (fontType,f,ts,fontSize,enc,w1,w2))
3867
b0fd3fd9faee test_rl_accel.py: allow refcounts to stabilize
robin
parents: 3862
diff changeset
   113
        for font,fontType in ((t1f,'T1'),(ttf,'TTF')):
b0fd3fd9faee test_rl_accel.py: allow refcounts to stabilize
robin
parents: 3862
diff changeset
   114
            funcs = getFuncs('instanceStringWidth'+fontType)
b0fd3fd9faee test_rl_accel.py: allow refcounts to stabilize
robin
parents: 3862
diff changeset
   115
            for i,kind in enumerate(('c','py')):
3877
d80621d2f960 test_rl_accel.py: fix so test works in linux
robin
parents: 3876
diff changeset
   116
                for j in (3,2,1,0): #we run several times to allow the refcounts to stabilize
3867
b0fd3fd9faee test_rl_accel.py: allow refcounts to stabilize
robin
parents: 3862
diff changeset
   117
                    if j: rcv = getrc(defns)
b0fd3fd9faee test_rl_accel.py: allow refcounts to stabilize
robin
parents: 3862
diff changeset
   118
                    tfunc(font,testCp1252,fontSize,enc,funcs,i)
b0fd3fd9faee test_rl_accel.py: allow refcounts to stabilize
robin
parents: 3862
diff changeset
   119
                    tfunc(font,ts,fontSize,senc,funcs,i)
b0fd3fd9faee test_rl_accel.py: allow refcounts to stabilize
robin
parents: 3862
diff changeset
   120
                    tfunc(font,utext,fontSize,senc,funcs,i)
3877
d80621d2f960 test_rl_accel.py: fix so test works in linux
robin
parents: 3876
diff changeset
   121
                    if not j:
3867
b0fd3fd9faee test_rl_accel.py: allow refcounts to stabilize
robin
parents: 3862
diff changeset
   122
                        rcc = checkrc(defns,rcv)
3876
cf5368404b78 test_rl_accel.py: make it work more usefully
robin
parents: 3867
diff changeset
   123
                        if rcc: F.append("%s %s refcount diffs (%s)" % (fontType,kind,rcc))
cf5368404b78 test_rl_accel.py: make it work more usefully
robin
parents: 3867
diff changeset
   124
        assert not F,"instanceStringWidth failures\n\t%s" % '\n\t'.join(F)
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   125
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   126
    def test_unicode2T1(self):
3862
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   127
        from reportlab.pdfbase.pdfmetrics import getFont, _fonts
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   128
        t1fn = 'Times-Roman'
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   129
        t1f = getFont(t1fn)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   130
        enc = 'cp1252'
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   131
        senc = 'utf8'
3862
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   132
        testCp1252 = b'copyright \xa9 trademark \x99 registered \xae ReportLab! Ol\xe9!'.decode(enc)
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   133
        utext = b'This is the end of the \xce\x91\xce\xb2 world. This is the end of the \xce\x91\xce\xb2 world jap=\xe3\x83\x9b\xe3\x83\x86. This is the end of the \xce\x91\xce\xb2 world. This is the end of the \xce\x91\xce\xb2 world jap=\xe3\x83\x9b\xe3\x83\x86'.decode('utf8')
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   134
        FUNCS = getFuncs('unicode2T1')
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   135
        def tfunc(f,ts,func,kind):
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   136
            w1 = func(ts,[f]+f.substitutionFonts)
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   137
            w2 = FUNCS[1][0](ts,[f]+f.substitutionFonts)
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   138
            assert w1==w2,"%s unicode2T1 %r != %r" % (kind,w1,w2)
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   139
        defns="t1fn t1f testCp1252 enc senc utext t1f.widths t1f.encName t1f.substitutionFonts _fonts"
3876
cf5368404b78 test_rl_accel.py: make it work more usefully
robin
parents: 3867
diff changeset
   140
        F = []
3862
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   141
        for func,kind in FUNCS:
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   142
            rcv = getrc(defns)
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   143
            tfunc(t1f,testCp1252,func,kind)
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   144
            tfunc(t1f,utext,func,kind)
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   145
            rcc = checkrc(defns,rcv)
3876
cf5368404b78 test_rl_accel.py: make it work more usefully
robin
parents: 3867
diff changeset
   146
            if rcc: F.append("%s refcount diffs (%s)" % (kind,rcc))
cf5368404b78 test_rl_accel.py: make it work more usefully
robin
parents: 3867
diff changeset
   147
        assert not F,"test_unicode2T1 failures\n\t%s" % '\n\t'.join(F)
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   148
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   149
    def test_sameFrag(self):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   150
        class ABag:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   151
            def __init__(self,**kwd):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   152
                self.__dict__.update(kwd)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   153
            def __str__(self):
3723
99aa837b6703 second stage of port to Python 3.3; working hello world
rptlab
parents: 3721
diff changeset
   154
                V=['%s=%r' % v for v in self.__dict__.items()]
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   155
                V.sort()
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   156
                return 'ABag(%s)' % ','.join(V)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   157
3862
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   158
        for func,kind in getFuncs('sameFrag'):
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   159
            if not func: continue
4389
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4367
diff changeset
   160
            a=ABag(fontName='Helvetica',fontSize=12, textColor="red", rise=0, us_lines=0, link="aaaa")
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4367
diff changeset
   161
            b=ABag(fontName='Helvetica',fontSize=12, textColor="red", rise=0, us_lines=0, link="aaaa")
61a7f0840d00 more controllable under and strike lines; fix for issue 137 contributed by Tom Alexander @ bitbucket; version-->3.4.30
robin <robin@reportlab.com>
parents: 4367
diff changeset
   162
            for name in ("fontName", "fontSize", "textColor", "rise", "us_lines", "link"):
3862
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   163
                old = getattr(a,name)
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   164
                assert func(a,b)==1, "%s sameFrag(%s,%s)!=1" % (kind,a,b)
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   165
                assert func(b,a)==1, "%s sameFrag(%s,%s)!=1" % (kind,b,a)
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   166
                setattr(a,name,None)
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   167
                assert func(a,b)==0, "%s sameFrag(%s,%s)!=0" % (kind,a,b)
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   168
                assert func(b,a)==0, "%s sameFrag(%s,%s)!=0" % (kind,b,a)
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   169
                delattr(a,name)
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   170
                assert func(a,b)==0, "%s sameFrag(%s,%s)!=0" % (kind,a,b)
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   171
                assert func(b,a)==0, "%s sameFrag(%s,%s)!=0" % (kind,b,a)
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   172
                delattr(b,name)
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   173
                assert func(a,b)==1, "%s sameFrag(%s,%s)!=1" % (kind,a,b)
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   174
                assert func(b,a)==1, "%s sameFrag(%s,%s)!=1" % (kind,b,a)
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   175
                setattr(a,name,old)
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   176
                setattr(b,name,old)
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   177
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   178
def makeSuite():
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   179
    # only run the tests if _rl_accel is present
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   180
    try:
3862
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   181
        from reportlab.lib import _rl_accel, rl_accel
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   182
        Klass = RlAccelTestCase
3862
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   183
        global _py_funcs, _c_funcs
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   184
        _c_funcs=rl_accel._c_funcs
272e650eecf5 rl_accel.py: improvements and more tests working
robin
parents: 3723
diff changeset
   185
        _py_funcs=rl_accel._py_funcs
2963
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   186
    except:
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   187
        class Klass(unittest.TestCase):
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   188
            pass
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   189
    return makeSuiteForClasses(Klass)
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   190
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   191
#noruntests
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   192
if __name__ == "__main__":
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   193
    unittest.TextTestRunner().run(makeSuite())
c414c0ab69e7 reportlab-2.2: first stage of major re-org
rgbecker
parents:
diff changeset
   194
    printLocation()