tests/test_graphics_barcode.py
author robin <robin@reportlab.com>
Tue, 07 Mar 2017 10:00:34 +0000
changeset 4330 617ffa6bbdc8
parent 4252 fe660f227cac
child 4374 81e88861fee2
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: 4252
diff changeset
     1
#Copyright ReportLab Europe Ltd. 2000-2017
3968
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
     2
#see license.txt for license details
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
     3
"""
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
     4
Tests for barcodes
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
     5
"""
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
     6
from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
     7
setOutDir(__name__)
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
     8
import unittest, os, sys, glob
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
     9
4239
75c7de3058a6 more changes related to pypy testing
robin
parents: 4110
diff changeset
    10
try:
75c7de3058a6 more changes related to pypy testing
robin
parents: 4110
diff changeset
    11
    from reportlab.graphics import _renderPM
75c7de3058a6 more changes related to pypy testing
robin
parents: 4110
diff changeset
    12
except ImportError:
75c7de3058a6 more changes related to pypy testing
robin
parents: 4110
diff changeset
    13
    _renderPM = None
75c7de3058a6 more changes related to pypy testing
robin
parents: 4110
diff changeset
    14
3968
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    15
class BarcodeWidgetTestCase(unittest.TestCase):
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    16
    "Test barcode classes."
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    17
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    18
    @classmethod
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    19
    def setUpClass(cls):
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    20
        cls.outDir = outDir = outputfile('barcode-out')
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    21
        if not os.path.isdir(outDir):
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    22
            os.makedirs(outDir)
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    23
        for x in glob.glob(os.path.join(outDir,'*')):
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    24
            os.remove(x)
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    25
4239
75c7de3058a6 more changes related to pypy testing
robin
parents: 4110
diff changeset
    26
    @unittest.skipIf(not _renderPM,'no _renderPM')
3968
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    27
    def test0(self):
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    28
        from reportlab.graphics.shapes import Drawing
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    29
        outDir = self.outDir
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    30
        html = ['<html><head></head><body>']
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    31
        a = html.append
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    32
        formats = ['gif','pict','pdf']
4013
543363c28fc9 test_graphics_barcode.py: fix so we call createBarcodeDrawing on everything
robin
parents: 4011
diff changeset
    33
        from reportlab.graphics.barcode import getCodes
543363c28fc9 test_graphics_barcode.py: fix so we call createBarcodeDrawing on everything
robin
parents: 4011
diff changeset
    34
        CN = list(getCodes().items())
4011
c5fabef0e6eb test_graphics_barcode.py: ensure QR gets tested
robin
parents: 3968
diff changeset
    35
        for name,C in CN:
3968
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    36
            i = C()
4110
3fef785c0da6 test_graphics_barcode.py: fix drawing size
robin
parents: 4015
diff changeset
    37
            x0,y0,x1,y1 = i.getBounds()
3fef785c0da6 test_graphics_barcode.py: fix drawing size
robin
parents: 4015
diff changeset
    38
            D = Drawing(x1-x0,y1-y0)
3968
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    39
            D.add(i)
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    40
            D.save(formats=formats,outDir=outDir,fnRoot=name)
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    41
            a('<h2>%s</h2><img src="%s.gif"><br>' % (name, name))
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    42
            for fmt in formats:
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    43
                efn = os.path.join(outDir,'%s.%s' % (name,fmt))
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    44
                self.assertTrue(os.path.isfile(efn),msg="Expected file %r was not created" % efn)
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    45
        a('</body></html>')
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    46
        open(os.path.join(outDir,'index.html'),'w').write('\n'.join(html))
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    47
4013
543363c28fc9 test_graphics_barcode.py: fix so we call createBarcodeDrawing on everything
robin
parents: 4011
diff changeset
    48
    def test1(self):
543363c28fc9 test_graphics_barcode.py: fix so we call createBarcodeDrawing on everything
robin
parents: 4011
diff changeset
    49
        '''test createBarcodeDrawing'''
543363c28fc9 test_graphics_barcode.py: fix so we call createBarcodeDrawing on everything
robin
parents: 4011
diff changeset
    50
        from reportlab.graphics.barcode import createBarcodeDrawing
543363c28fc9 test_graphics_barcode.py: fix so we call createBarcodeDrawing on everything
robin
parents: 4011
diff changeset
    51
        from reportlab.graphics.barcode import getCodeNames
543363c28fc9 test_graphics_barcode.py: fix so we call createBarcodeDrawing on everything
robin
parents: 4011
diff changeset
    52
        for name in getCodeNames():
543363c28fc9 test_graphics_barcode.py: fix so we call createBarcodeDrawing on everything
robin
parents: 4011
diff changeset
    53
            d = createBarcodeDrawing(name)
4015
bd77dfb45715 test_graphics_barcode.py: run all the widget test values
robin
parents: 4013
diff changeset
    54
            for t in getattr(d.__class__,'_tests',[]):
bd77dfb45715 test_graphics_barcode.py: run all the widget test values
robin
parents: 4013
diff changeset
    55
                createBarcodeDrawing(name,value=t)
4013
543363c28fc9 test_graphics_barcode.py: fix so we call createBarcodeDrawing on everything
robin
parents: 4011
diff changeset
    56
3968
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    57
def makeSuite():
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    58
    return makeSuiteForClasses(BarcodeWidgetTestCase)
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    59
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    60
#noruntests
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    61
if __name__ == "__main__":
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    62
    unittest.TextTestRunner().run(makeSuite())
82a857d098ba test_graphics_barcode.py: start tests for barcdoes etc etc
robin
parents:
diff changeset
    63
    printLocation()