1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#Copyright ReportLab Europe Ltd. 2000-2013
#see license.txt for license details
"""
Tests for barcodes
"""
from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation
setOutDir(__name__)
import unittest, os, sys, glob
class BarcodeWidgetTestCase(unittest.TestCase):
"Test barcode classes."
@classmethod
def setUpClass(cls):
cls.outDir = outDir = outputfile('barcode-out')
if not os.path.isdir(outDir):
os.makedirs(outDir)
for x in glob.glob(os.path.join(outDir,'*')):
os.remove(x)
def test0(self):
from reportlab.graphics.shapes import Drawing
outDir = self.outDir
html = ['<html><head></head><body>']
a = html.append
formats = ['gif','pict','pdf']
from reportlab.graphics.barcode import getCodes
CN = list(getCodes().items())
for name,C in CN:
i = C()
D = Drawing(100,50)
D.add(i)
D.save(formats=formats,outDir=outDir,fnRoot=name)
a('<h2>%s</h2><img src="%s.gif"><br>' % (name, name))
for fmt in formats:
efn = os.path.join(outDir,'%s.%s' % (name,fmt))
self.assertTrue(os.path.isfile(efn),msg="Expected file %r was not created" % efn)
a('</body></html>')
open(os.path.join(outDir,'index.html'),'w').write('\n'.join(html))
def test1(self):
'''test createBarcodeDrawing'''
from reportlab.graphics.barcode import createBarcodeDrawing
from reportlab.graphics.barcode import getCodeNames
for name in getCodeNames():
d = createBarcodeDrawing(name)
for t in getattr(d.__class__,'_tests',[]):
createBarcodeDrawing(name,value=t)
def makeSuite():
return makeSuiteForClasses(BarcodeWidgetTestCase)
#noruntests
if __name__ == "__main__":
unittest.TextTestRunner().run(makeSuite())
printLocation()
|