diff --git a/.travis.yml b/.travis.yml index ec20204..4d1937c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,11 +2,15 @@ sudo: false language: python python: 3.5 env: + - TOX_ENV=py26 - TOX_ENV=py27 - - TOX_ENV=py33 - - TOX_ENV=py34 - TOX_ENV=py35 + - TOX_ENV=py36 - TOX_ENV=lint +matrix: + include: + - env: TOX_ENV=py36 + python: "3.6" install: pip install tox script: tox -e $TOX_ENV cache: pip diff --git a/elaphe/code39.py b/elaphe/code39.py index 6852b02..cfa1eeb 100644 --- a/elaphe/code39.py +++ b/elaphe/code39.py @@ -74,7 +74,7 @@ def _text_bbox(self, codestring): textmaxy = textyoffset + textsize textmaxx = 16*(len(codestring)+1)+0.6*textsize if hidestars: - textmaxx = 16, textmaxx-16 + textmaxx = textmaxx - 16 return [0, textyoffset, textmaxx, textmaxy] def build_params(self, codestring): diff --git a/elaphe/postscriptbarcode/LICENSE b/elaphe/postscriptbarcode/LICENSE index afc1d97..bb5853a 100644 --- a/elaphe/postscriptbarcode/LICENSE +++ b/elaphe/postscriptbarcode/LICENSE @@ -1,7 +1,7 @@ Barcode Writer in Pure PostScript http://bwipp.terryburton.co.uk -Copyright (c) 2004-2014 Terry Burton +Copyright (c) 2004-2017 Terry Burton Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated diff --git a/elaphe/postscriptbarcode/barcode.ps b/elaphe/postscriptbarcode/barcode.ps index cc036d2..074f3b6 100644 Binary files a/elaphe/postscriptbarcode/barcode.ps and b/elaphe/postscriptbarcode/barcode.ps differ diff --git a/test/__init__.py b/test/__init__.py index 94f98a3..f7290a2 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -1,5 +1,6 @@ from unittest import TestSuite from doctest import DocTestSuite +from . import render module_names = [ 'elaphe', @@ -38,3 +39,6 @@ # doctests for module_name in module_names: suite.addTest(DocTestSuite(module_name)) + + +render.collect(suite) diff --git a/test/img/auspost/001.png b/test/img/auspost/001.png index fe0cc50..761a0fc 100644 Binary files a/test/img/auspost/001.png and b/test/img/auspost/001.png differ diff --git a/test/img/azteccode/001.png b/test/img/azteccode/001.png index fad5d30..807eb1e 100644 Binary files a/test/img/azteccode/001.png and b/test/img/azteccode/001.png differ diff --git a/test/img/azteccode/002.png b/test/img/azteccode/002.png index cef1f5d..e8e7ca8 100644 Binary files a/test/img/azteccode/002.png and b/test/img/azteccode/002.png differ diff --git a/test/img/azteccode/003.png b/test/img/azteccode/003.png index 02dce3e..aea84da 100644 Binary files a/test/img/azteccode/003.png and b/test/img/azteccode/003.png differ diff --git a/test/img/azteccode/004.png b/test/img/azteccode/004.png index 5baaa87..560645e 100644 Binary files a/test/img/azteccode/004.png and b/test/img/azteccode/004.png differ diff --git a/test/img/code11/001.png b/test/img/code11/001.png index 37f27f4..c7eb855 100644 Binary files a/test/img/code11/001.png and b/test/img/code11/001.png differ diff --git a/test/img/code39/001.png b/test/img/code39/001.png index d4d2078..7d1f49e 100644 Binary files a/test/img/code39/001.png and b/test/img/code39/001.png differ diff --git a/test/img/code39/002.png b/test/img/code39/002.png index b9082fc..3e5239c 100644 Binary files a/test/img/code39/002.png and b/test/img/code39/002.png differ diff --git a/test/img/code39/003.png b/test/img/code39/003.png index d422912..543a037 100644 Binary files a/test/img/code39/003.png and b/test/img/code39/003.png differ diff --git a/test/img/code93/001.png b/test/img/code93/001.png index ab7b973..c7f9691 100644 Binary files a/test/img/code93/001.png and b/test/img/code93/001.png differ diff --git a/test/img/datamatrix/001.png b/test/img/datamatrix/001.png index c0b5cd8..035d025 100644 Binary files a/test/img/datamatrix/001.png and b/test/img/datamatrix/001.png differ diff --git a/test/img/datamatrix/002.png b/test/img/datamatrix/002.png index c0b5cd8..035d025 100644 Binary files a/test/img/datamatrix/002.png and b/test/img/datamatrix/002.png differ diff --git a/test/img/datamatrix/003.png b/test/img/datamatrix/003.png index 25e8232..7fca250 100644 Binary files a/test/img/datamatrix/003.png and b/test/img/datamatrix/003.png differ diff --git a/test/img/maxicode/001.png b/test/img/maxicode/001.png index ff13165..3696fe3 100644 Binary files a/test/img/maxicode/001.png and b/test/img/maxicode/001.png differ diff --git a/test/img/maxicode/002.png b/test/img/maxicode/002.png index ff13165..3696fe3 100644 Binary files a/test/img/maxicode/002.png and b/test/img/maxicode/002.png differ diff --git a/test/img/maxicode/003.png b/test/img/maxicode/003.png index 3c5bf1b..2f761e4 100644 Binary files a/test/img/maxicode/003.png and b/test/img/maxicode/003.png differ diff --git a/test/img/maxicode/004.png b/test/img/maxicode/004.png index 2b24dea..42e4d30 100644 Binary files a/test/img/maxicode/004.png and b/test/img/maxicode/004.png differ diff --git a/test/img/maxicode/005.png b/test/img/maxicode/005.png index c5cd7b2..a944699 100644 Binary files a/test/img/maxicode/005.png and b/test/img/maxicode/005.png differ diff --git a/test/img/msi/001.png b/test/img/msi/001.png index 74bc2e2..b875080 100644 Binary files a/test/img/msi/001.png and b/test/img/msi/001.png differ diff --git a/test/img/msi/002.png b/test/img/msi/002.png index 61054b0..f99e50e 100644 Binary files a/test/img/msi/002.png and b/test/img/msi/002.png differ diff --git a/test/img/msi/003.png b/test/img/msi/003.png index 0c60e43..3eef6d9 100644 Binary files a/test/img/msi/003.png and b/test/img/msi/003.png differ diff --git a/test/img/onecode/002.png b/test/img/onecode/002.png index f37bcde..42d1628 100644 Binary files a/test/img/onecode/002.png and b/test/img/onecode/002.png differ diff --git a/test/img/pdf417/001.png b/test/img/pdf417/001.png index 95cae47..a8ea102 100644 Binary files a/test/img/pdf417/001.png and b/test/img/pdf417/001.png differ diff --git a/test/img/pdf417/002.png b/test/img/pdf417/002.png index 8abebc2..458d3c0 100644 Binary files a/test/img/pdf417/002.png and b/test/img/pdf417/002.png differ diff --git a/test/img/pdf417/003.png b/test/img/pdf417/003.png index 9f82429..9c417f1 100644 Binary files a/test/img/pdf417/003.png and b/test/img/pdf417/003.png differ diff --git a/test/img/pdf417/004.png b/test/img/pdf417/004.png index 2d02ec5..45bda0b 100644 Binary files a/test/img/pdf417/004.png and b/test/img/pdf417/004.png differ diff --git a/test/img/rationalizedCodabar/001.png b/test/img/rationalizedCodabar/001.png index 1acad33..3245f78 100644 Binary files a/test/img/rationalizedCodabar/001.png and b/test/img/rationalizedCodabar/001.png differ diff --git a/test/render.py b/test/render.py index bdcc2db..28878f0 100644 --- a/test/render.py +++ b/test/render.py @@ -6,7 +6,7 @@ from elaphe import barcode from os import makedirs from os.path import abspath, dirname, join -from StringIO import StringIO +from io import BytesIO from uu import encode as uuencode @@ -50,51 +50,64 @@ class RenderTestCaseBase(TestCase): def runTest(self): symbology = self.conf.symbology + args = self.conf.args + if symbology == 'datamatrix' and args[1] == 'Rectangular': + self.skipTest('this datamatrix produces an empty image') + img_prefix = join(IMG_ROOT, symbology) - for args in self.conf.cases: - img_filename, codestring = args[:2] - options = args[2] if len(args) > 2 else {} - render_options = dict((args[3] if len(args) > 3 else {}), scale=2.0) - generated = barcode(symbology, codestring, options, **render_options).convert('L') - loaded = Image.open(join(img_prefix, img_filename)).convert('L') - diff = None - try: - # image size comparison - self.assertEqual(generated.size, loaded.size) - # pixel-wize comparison - diff = ImageChops.difference(generated, loaded) - diff_bbox = diff.getbbox() - self.assertIsNone(diff_bbox) - except AssertionError as exc: - # generate and show diagnostics image - if diff: - # if diff exists, generate 3-row diagnostics image - lw, lh = loaded.size - gw, gh = generated.size - diag = Image.new('L', (max(lw, gw), (lh+gh+max(lh, gh)))) - diag.paste(loaded, (0, 0, lw, lh)) - diag.paste(generated, (0, lh, gw, lh+gh)) - diag.paste(diff, (0, lh+gh, max(lw, gw), (lh+gh+max(lh, gh)))) - else: - # else, just write generated image - diag = generated - sio_img = StringIO() - diag.convert('L').save(sio_img, 'PNG') - # reopen sio_img - sio_img = StringIO(sio_img.getvalue()) - sio_uu = StringIO() - uuencode(sio_img, sio_uu, name='diag_%s' % img_filename) - raise AssertionError( - 'Image difference detected (%s)\n' - 'uu of generated image:\n----\n%s----\n' - % (exc.args, sio_uu.getvalue())) + img_filename, codestring = args[:2] + options = args[2] if len(args) > 2 else {} + render_options = dict((args[3] if len(args) > 3 else {}), scale=2.0) + generated = barcode(symbology, codestring, options, **render_options).convert('L') + loaded = Image.open(join(img_prefix, img_filename)).convert('L') + diff = None + try: + # image size comparison + self.assertEqual(generated.size, loaded.size) + # pixel-wize comparison + diff = ImageChops.difference(generated, loaded) + diff_bbox = diff.getbbox() + self.assertIsNone(diff_bbox) + except AssertionError as exc: + # generate and show diagnostics image + if diff: + # if diff exists, generate 3-row diagnostics image + lw, lh = loaded.size + gw, gh = generated.size + diag = Image.new('L', (max(lw, gw), (lh+gh+max(lh, gh)))) + diag.paste(loaded, (0, 0, lw, lh)) + diag.paste(generated, (0, lh, gw, lh+gh)) + diag.paste(diff, (0, lh+gh, max(lw, gw), (lh+gh+max(lh, gh)))) + else: + # else, just write generated image + diag = generated + sio_img = BytesIO() + diag.convert('L').save(sio_img, 'PNG') + # reopen sio_img + sio_img = BytesIO(sio_img.getvalue()) + sio_uu = BytesIO() + uuencode(sio_img, sio_uu, name='diag_%s' % img_filename) + raise AssertionError( + 'Image difference detected (%s)\n' + 'uu of generated image:\n----\n%s----\n' + % (exc.args, sio_uu.getvalue())) def gen_render_test_case(symbology): conf_mod = load_module(symbology, *find_module(symbology, ['test'])) - test_case = type(symbology.capitalize()+'RenderTest', - (RenderTestCaseBase,), dict(conf=conf_mod))() - return test_case + for i, case in enumerate(conf_mod.cases): + + class Conf(object): + symbology = conf_mod.symbology + args = case + + RenderTestCase = type( + symbology.capitalize()+'RenderTest'+str(i), + (RenderTestCaseBase,), + dict(conf=Conf) + ) + + yield RenderTestCase() def gen_test_images(symbology): @@ -112,10 +125,13 @@ def gen_test_images(symbology): generated.save(join(img_prefix, img_filename), 'PNG') -suite = TestSuite() +def collect(ts): + for symbology in symbologies: + for test in gen_render_test_case(symbology): + ts.addTest(test) + -for symbology in symbologies: - suite.addTest(gen_render_test_case(symbology)) +suite = collect(TestSuite()) if __name__ == '__main__': diff --git a/tox.ini b/tox.ini index 0dba9de..01f1a4c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py{27,34,35}, lint +envlist = py{27,35,36}, lint [testenv] commands = python setup.py test diff --git a/update.sh b/update.sh old mode 100644 new mode 100755 index 91bdb10..c2943f5 --- a/update.sh +++ b/update.sh @@ -2,7 +2,7 @@ set -euo pipefail IFS=$'\n\t' -version='2017-04-04' +version='2017-07-10' curl -fSL https://github.com/bwipp/postscriptbarcode/releases/download/$version/postscriptbarcode-monolithic-package-$version.tgz -o psbc.tgz tar -zxC ./elaphe/postscriptbarcode/ -f psbc.tgz --strip=2 --no-anchored barcode.ps LICENSE README