Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

travis #10

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion elaphe/code39.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion elaphe/postscriptbarcode/LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Binary file modified elaphe/postscriptbarcode/barcode.ps
Binary file not shown.
4 changes: 4 additions & 0 deletions test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest import TestSuite
from doctest import DocTestSuite
from . import render

module_names = [
'elaphe',
Expand Down Expand Up @@ -38,3 +39,6 @@
# doctests
for module_name in module_names:
suite.addTest(DocTestSuite(module_name))


render.collect(suite)
Binary file modified test/img/auspost/001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/azteccode/001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/azteccode/002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/azteccode/003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/azteccode/004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/code11/001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/code39/001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/code39/002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/code39/003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/code93/001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/datamatrix/001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/datamatrix/002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/datamatrix/003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/maxicode/001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/maxicode/002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/maxicode/003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/maxicode/004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/maxicode/005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/msi/001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/msi/002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/msi/003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/onecode/002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/pdf417/001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/pdf417/002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/pdf417/003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/img/pdf417/004.png
Binary file modified test/img/rationalizedCodabar/001.png
104 changes: 60 additions & 44 deletions test/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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):
Expand All @@ -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__':
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py{27,34,35}, lint
envlist = py{27,35,36}, lint

[testenv]
commands = python setup.py test
Expand Down
2 changes: 1 addition & 1 deletion update.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down