Skip to content

Commit 6032c01

Browse files
author
Hugo Osvaldo Barrera
committed
Tidy up tests
1 parent 07b5e59 commit 6032c01

7 files changed

Lines changed: 97 additions & 79 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
barcode/__pycache*
1313
build/*
1414
dist/*
15-
tests/*
1615
docs/_build/*
1716
MANIFEST
1817
barcode/version.py

Pipfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
pytest = "*"
8+
pytest-cov = "*"
9+
10+
[packages]
11+
python-barcode = {editable = true,path = "."}
12+
13+
[requires]
14+
python_version = "3.7"

setup.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[tool:pytest]
2+
addopts =
3+
-vv
4+
--cov=barcode
5+
--cov-report=term-missing:skip-covered
6+
--no-cov-on-fail
7+
8+
[yapf]
9+
coalesce_brackets = true
10+
dedent_closing_brackets = true
11+
space_between_ending_comma_and_closing_bracket = false
12+
split_arguments_when_comma_terminated = true
13+
split_all_top_level_comma_separated_values = false

tests/__init__.py

Whitespace-only changes.

tests/test_builds.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from barcode import get_barcode
2+
3+
4+
def test_ean8_builds():
5+
ref = (
6+
'1010100011000110100100110101111010101000100'
7+
'100010011100101001000101'
8+
)
9+
ean = get_barcode('ean8', '40267708')
10+
bc = ean.build()
11+
assert ref == bc[0]

tests/test_checksums.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from barcode import get_barcode
2+
3+
4+
def test_code39_checksum():
5+
code39 = get_barcode('code39', 'Code39')
6+
assert 'CODE39W' == code39.get_fullcode()
7+
8+
9+
def test_pzn_checksum():
10+
pzn = get_barcode('pzn', '103940')
11+
assert 'PZN-1039406' == pzn.get_fullcode()
12+
13+
14+
def test_ean13_checksum():
15+
ean = get_barcode('ean13', '400614457735')
16+
assert '4006144577350' == ean.get_fullcode()
17+
18+
19+
def test_ean8_checksum():
20+
ean = get_barcode('ean8', '6032299')
21+
assert '60322999' == ean.get_fullcode()
22+
23+
24+
def test_jan_checksum():
25+
jan = get_barcode('jan', '491400614457')
26+
assert '4914006144575' == jan.get_fullcode()
27+
28+
29+
def test_ean14_checksum():
30+
ean = get_barcode('ean14', '1234567891258')
31+
assert '12345678912589' == ean.get_fullcode()
32+
33+
34+
def test_isbn10_checksum():
35+
isbn = get_barcode('isbn10', '376926085')
36+
assert '3769260856' == isbn.isbn10
37+
38+
39+
def test_isbn13_checksum():
40+
isbn = get_barcode('isbn13', '978376926085')
41+
assert '9783769260854' == isbn.get_fullcode()
42+
43+
44+
def test_gs1_128_checksum():
45+
gs1_128 = get_barcode('gs1_128', '00376401856400470087')
46+
assert '00376401856400470087' == gs1_128.get_fullcode()
Lines changed: 13 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
1-
"""
2-
3-
Performs some tests with pyBarcode. All created barcodes where saved in the
4-
tests subdirectory with a tests.html to watch them.
5-
6-
"""
7-
__docformat__ = 'restructuredtext en'
1+
"""Generates barcodes for visually inspecting the results."""
82

93
import codecs
104
import os
115
import sys
12-
import unittest
136

147
from barcode import get_barcode, get_barcode_class, version
15-
try:
16-
from barcode.writer import ImageWriter
17-
except ImportError:
18-
ImageWriter = None # lint:ok
8+
from barcode.writer import ImageWriter
199

2010
PATH = os.path.dirname(os.path.abspath(__file__))
21-
TESTPATH = os.path.join(PATH, 'tests')
11+
TESTPATH = os.path.join(PATH, 'test_outputs')
2212
HTMLFILE = os.path.join(TESTPATH, 'index.html')
2313

2414
HTML = """<!DOCTYPE html>
@@ -62,17 +52,17 @@
6252
)
6353

6454

65-
def test():
66-
if not os.path.isdir(TESTPATH):
67-
try:
68-
os.mkdir(TESTPATH)
69-
except OSError as e:
70-
print('Test not run.')
71-
print('Error:', e)
72-
sys.exit(1)
55+
def test_generating_barcodes():
56+
os.makedirs(TESTPATH, exist_ok=True)
57+
7358
objects = []
74-
append = lambda x, y: objects.append(OBJECTS.format(filename=x, name=y))
75-
append_img = lambda x, y: objects.append(IMAGES.format(filename=x, name=y))
59+
60+
def append(x, y):
61+
objects.append(OBJECTS.format(filename=x, name=y))
62+
63+
def append_img(x, y):
64+
objects.append(IMAGES.format(filename=x, name=y))
65+
7666
options = {'module_width': 0.495, 'module_height': 25.0}
7767
for codename, code in TESTCODES:
7868
bcode = get_barcode(codename, code)
@@ -108,59 +98,4 @@ def test():
10898
obj = '\n'.join(objects)
10999
f.write(HTML.format(version=version, body=obj))
110100

111-
112-
class TestBarcodeBuilds(unittest.TestCase):
113-
def test_ean8(self):
114-
ref = (
115-
'1010100011000110100100110101111010101000100'
116-
'100010011100101001000101'
117-
)
118-
ean = get_barcode('ean8', '40267708')
119-
bc = ean.build()
120-
self.assertEqual(ref, bc[0])
121-
122-
123-
class TestChecksums(unittest.TestCase):
124-
def test_code39(self):
125-
code39 = get_barcode('code39', 'Code39')
126-
self.assertEqual('CODE39W', code39.get_fullcode())
127-
128-
def test_pzn(self):
129-
pzn = get_barcode('pzn', '103940')
130-
self.assertEqual('PZN-1039406', pzn.get_fullcode())
131-
132-
def test_ean13(self):
133-
ean = get_barcode('ean13', '400614457735')
134-
self.assertEqual('4006144577350', ean.get_fullcode())
135-
136-
def test_ean8(self):
137-
ean = get_barcode('ean8', '6032299')
138-
self.assertEqual('60322999', ean.get_fullcode())
139-
140-
def test_jan(self):
141-
jan = get_barcode('jan', '491400614457')
142-
self.assertEqual('4914006144575', jan.get_fullcode())
143-
144-
def test_ean14(self):
145-
ean = get_barcode('ean14', '1234567891258')
146-
self.assertEqual('12345678912589', ean.get_fullcode())
147-
148-
def test_isbn10(self):
149-
isbn = get_barcode('isbn10', '376926085')
150-
self.assertEqual('3769260856', isbn.isbn10)
151-
152-
def test_isbn13(self):
153-
isbn = get_barcode('isbn13', '978376926085')
154-
self.assertEqual('9783769260854', isbn.get_fullcode())
155-
156-
def test_gs1_128(self):
157-
gs1_128 = get_barcode('gs1_128', '00376401856400470087')
158-
self.assertEqual('00376401856400470087', gs1_128.get_fullcode())
159-
160-
161-
if __name__ == '__main__':
162-
test()
163101
print('\nNow open {htmlfile} in your browser.'.format(htmlfile=HTMLFILE))
164-
if '-v' not in sys.argv:
165-
sys.argv.append('-v')
166-
unittest.main()

0 commit comments

Comments
 (0)