Skip to content

Commit fe5de7b

Browse files
author
whitie
committed
Fixed issue #31. Modernized tests.
1 parent ae4c2e2 commit fe5de7b

6 files changed

Lines changed: 34 additions & 30 deletions

File tree

barcode/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
# -*- coding: utf-8 -*-
22

3-
from barcode.errors import BarcodeNotFoundError
4-
from barcode.codex import Code39, PZN, Code128
5-
from barcode.ean import EAN8, EAN13, JAN
6-
from barcode.isxn import ISBN10, ISBN13, ISSN
7-
from barcode.upc import UPCA
8-
from barcode.itf import ITF
9-
103
"""
114
125
pyBarcode
@@ -41,6 +34,12 @@
4134
'Topic :: Multimedia :: Graphics',
4235
]
4336

37+
from barcode.errors import BarcodeNotFoundError
38+
from barcode.codex import Code39, PZN, Code128
39+
from barcode.ean import EAN8, EAN13, JAN
40+
from barcode.isxn import ISBN10, ISBN13, ISSN
41+
from barcode.upc import UPCA
42+
from barcode.itf import ITF
4443

4544
try:
4645
_strbase = basestring # lint:ok

barcode/codex.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ def build(self):
7373
chars.append(code39.EDGE)
7474
return [code39.MIDDLE.join(chars)]
7575

76-
def render(self, writer_options):
76+
def render(self, writer_options, text=None):
7777
options = dict(module_width=MIN_SIZE, quiet_zone=MIN_QUIET_ZONE)
7878
options.update(writer_options or {})
79-
return Barcode.render(self, options)
79+
return Barcode.render(self, options, text)
8080

8181

8282
class PZN(Code39):
@@ -246,7 +246,7 @@ def build(self):
246246
code += '11'
247247
return [code]
248248

249-
def render(self, writer_options):
249+
def render(self, writer_options, text=None):
250250
options = dict(module_width=MIN_SIZE, quiet_zone=MIN_QUIET_ZONE)
251251
options.update(writer_options or {})
252-
return Barcode.render(self, options)
252+
return Barcode.render(self, options, text)

barcode/ean.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ def to_ascii(self):
105105
code[i] = line.replace('1', '|').replace('0', ' ')
106106
return '\n'.join(code)
107107

108-
def render(self, writer_options=None):
108+
def render(self, writer_options=None, text=None):
109109
options = dict(module_width=SIZES['SC2'])
110110
options.update(writer_options or {})
111-
return Barcode.render(self, options)
111+
return Barcode.render(self, options, text)
112112

113113

114114
class JapanArticleNumber(EuropeanArticleNumber13):

barcode/itf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ def build(self):
7474
raw += '0' * self.narrow
7575
return [raw]
7676

77-
def render(self, writer_options):
77+
def render(self, writer_options, text=None):
7878
options = dict(module_width=MIN_SIZE/self.narrow,
7979
quiet_zone=MIN_QUIET_ZONE)
8080
options.update(writer_options or {})
81-
return Barcode.render(self, options)
81+
return Barcode.render(self, options, text)

barcode/upc.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
from barcode.charsets import upc as _upc
77
from barcode.errors import *
88

9+
try:
10+
reduce
11+
except NameError:
12+
from functools import reduce
13+
914
"""Module: barcode.upc
1015
1116
:Provided barcodes: UPC-A
@@ -101,9 +106,9 @@ def to_ascii(self):
101106
code[i] = line.replace('1', '|').replace('0', '_')
102107
return '\n'.join(code)
103108

104-
def render(self, writer_options=None):
109+
def render(self, writer_options=None, text=None):
105110
options = dict(module_width=0.33)
106111
options.update(writer_options or {})
107-
return Barcode.render(self, options)
112+
return Barcode.render(self, options, text)
108113

109114
UPCA = UniversalProductCodeA

test.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@
2626
TESTPATH = os.path.join(PATH, 'tests')
2727
HTMLFILE = os.path.join(TESTPATH, 'index.html')
2828

29-
HTML = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
30-
"http://www.w3.org/TR/html4/strict.dtd">
29+
HTML = """<!DOCTYPE html>
3130
<html>
3231
<head>
32+
<meta charset="utf-8">
3333
<title>pyBarcode {version} Test</title>
34-
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
3534
</head>
3635
<body>
3736
<h1>pyBarcode {version} Tests</h1>
@@ -40,12 +39,11 @@
4039
</html>
4140
"""
4241

43-
OBJECTS = ('<p><h2>{name}</h2><br />\n'
44-
'<object data="{filename}" type="image/svg+xml">\n'
45-
'<param name="src" value="{filename}" /></object>')
42+
OBJECTS = ('<p><h2>{name}</h2><br>\n'
43+
'<img src="{filename}" alt="SVG {name}">\n')
4644

47-
IMAGES = ('<h3>As PNG-Image</h3><br />\n'
48-
'<img src="{filename}" alt="{name}" /></p>\n')
45+
IMAGES = ('<h3>As PNG-Image</h3><br>\n'
46+
'<img src="{filename}" alt="PNG {name}"></p>\n')
4947

5048
NO_PIL = '<h3>PIL was not found. No PNG-Image created.</h3></p>\n'
5149

@@ -82,20 +80,22 @@ def test():
8280
options['center_text'] = False
8381
else:
8482
options['center_text'] = True
85-
filename = bcode.save(os.path.join(TESTPATH, codename), options)
83+
filename = bcode.save(os.path.join(TESTPATH, codename),
84+
options=options)
8685
print('Code: {0}, Input: {1}, Output: {2}'.format(
8786
bcode.name, code, bcode.get_fullcode()))
88-
append(filename, bcode.name)
87+
append(os.path.basename(filename), bcode.name)
8988
if ImageWriter is not None:
9089
bcodec = get_barcode_class(codename)
9190
bcode = bcodec(code, writer=ImageWriter())
9291
opts = dict(font_size=14, text_distance=1)
9392
if codename.startswith('i'):
9493
opts['center_text'] = False
9594
else:
96-
options['center_text'] = True
97-
filename = bcode.save(os.path.join(TESTPATH, codename), opts)
98-
append_img(filename, bcode.name)
95+
opts['center_text'] = True
96+
filename = bcode.save(os.path.join(TESTPATH, codename),
97+
options=opts)
98+
append_img(os.path.basename(filename), bcode.name)
9999
else:
100100
objects.append(NO_PIL)
101101
# Save htmlfile with all objects

0 commit comments

Comments
 (0)