pybarcodes 1.0.2__tar.gz → 1.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pybarcodes-1.0.2 → pybarcodes-1.0.3}/PKG-INFO +12 -14
- {pybarcodes-1.0.2 → pybarcodes-1.0.3}/README.rst +1 -1
- {pybarcodes-1.0.2 → pybarcodes-1.0.3}/pybarcodes/__init__.py +1 -1
- pybarcodes-1.0.3/pybarcodes.egg-info/PKG-INFO +135 -0
- pybarcodes-1.0.3/pybarcodes.egg-info/SOURCES.txt +19 -0
- pybarcodes-1.0.3/pybarcodes.egg-info/dependency_links.txt +1 -0
- pybarcodes-1.0.3/pybarcodes.egg-info/requires.txt +1 -0
- pybarcodes-1.0.3/pybarcodes.egg-info/top_level.txt +1 -0
- {pybarcodes-1.0.2 → pybarcodes-1.0.3}/pyproject.toml +11 -13
- pybarcodes-1.0.3/setup.cfg +4 -0
- pybarcodes-1.0.3/tests/test_codes.py +29 -0
- pybarcodes-1.0.3/tests/test_ean.py +170 -0
- {pybarcodes-1.0.2 → pybarcodes-1.0.3}/LICENSE +0 -0
- {pybarcodes-1.0.2 → pybarcodes-1.0.3}/pybarcodes/barcode.py +0 -0
- {pybarcodes-1.0.2 → pybarcodes-1.0.3}/pybarcodes/codes.py +0 -0
- {pybarcodes-1.0.2 → pybarcodes-1.0.3}/pybarcodes/codings/__init__.py +0 -0
- {pybarcodes-1.0.2 → pybarcodes-1.0.3}/pybarcodes/codings/codex.py +0 -0
- {pybarcodes-1.0.2 → pybarcodes-1.0.3}/pybarcodes/codings/ean.py +0 -0
- {pybarcodes-1.0.2 → pybarcodes-1.0.3}/pybarcodes/ean.py +0 -0
- {pybarcodes-1.0.2 → pybarcodes-1.0.3}/pybarcodes/exceptions.py +0 -0
- {pybarcodes-1.0.2 → pybarcodes-1.0.3}/pybarcodes/fonts/arial.ttf +0 -0
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pybarcodes
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: A Python package for barcode generation
|
|
5
|
+
Author-email: atbuy <buy@atbuy.dev>
|
|
5
6
|
License-Expression: MIT
|
|
6
|
-
|
|
7
|
+
Project-URL: Homepage, https://github.com/atbuy/pybarcodes
|
|
8
|
+
Project-URL: Repository, https://github.com/atbuy/pybarcodes
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/atbuy/pybarcodes/issues
|
|
10
|
+
Project-URL: Source Code, https://github.com/atbuy/pybarcodes
|
|
11
|
+
Project-URL: CI/CD, https://github.com/atbuy/pybarcodes/actions
|
|
7
12
|
Keywords: barcode,scanner,generator,ean13,code39,jan,python
|
|
8
|
-
Author: atbuy
|
|
9
|
-
Author-email: buy@atbuy.dev
|
|
10
|
-
Requires-Python: >=3.10
|
|
11
13
|
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
13
14
|
Classifier: Intended Audience :: Developers
|
|
14
15
|
Classifier: Natural Language :: English
|
|
15
16
|
Classifier: Operating System :: OS Independent
|
|
@@ -23,13 +24,11 @@ Classifier: Topic :: Multimedia :: Graphics
|
|
|
23
24
|
Classifier: Topic :: Software Development :: Libraries
|
|
24
25
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
26
|
Classifier: Topic :: Utilities
|
|
26
|
-
Requires-
|
|
27
|
-
Project-URL: Bug Tracker, https://github.com/atbuy/pybarcodes/issues
|
|
28
|
-
Project-URL: CI/CD, https://github.com/atbuy/pybarcodes/actions
|
|
29
|
-
Project-URL: Homepage, https://github.com/atbuy/pybarcodes
|
|
30
|
-
Project-URL: Repository, https://github.com/atbuy/pybarcodes
|
|
31
|
-
Project-URL: Source Code, https://github.com/atbuy/pybarcodes
|
|
27
|
+
Requires-Python: >=3.10
|
|
32
28
|
Description-Content-Type: text/x-rst
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Requires-Dist: pillow<13,>8
|
|
31
|
+
Dynamic: license-file
|
|
33
32
|
|
|
34
33
|
pybarcodes
|
|
35
34
|
==========
|
|
@@ -70,7 +69,7 @@ PRs are welcome :)
|
|
|
70
69
|
Installing
|
|
71
70
|
-----------
|
|
72
71
|
|
|
73
|
-
**Python 3.
|
|
72
|
+
**Python 3.10 or higher is required**
|
|
74
73
|
|
|
75
74
|
To install the library you can run the following command:
|
|
76
75
|
|
|
@@ -134,4 +133,3 @@ Links
|
|
|
134
133
|
|
|
135
134
|
- `Documentation <https://pybarcodes.readthedocs.io/en/latest/index.html>`_
|
|
136
135
|
- `PyPi <https://pypi.org/project/pybarcodes/>`_
|
|
137
|
-
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pybarcodes
|
|
3
|
+
Version: 1.0.3
|
|
4
|
+
Summary: A Python package for barcode generation
|
|
5
|
+
Author-email: atbuy <buy@atbuy.dev>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/atbuy/pybarcodes
|
|
8
|
+
Project-URL: Repository, https://github.com/atbuy/pybarcodes
|
|
9
|
+
Project-URL: Bug Tracker, https://github.com/atbuy/pybarcodes/issues
|
|
10
|
+
Project-URL: Source Code, https://github.com/atbuy/pybarcodes
|
|
11
|
+
Project-URL: CI/CD, https://github.com/atbuy/pybarcodes/actions
|
|
12
|
+
Keywords: barcode,scanner,generator,ean13,code39,jan,python
|
|
13
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Natural Language :: English
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
26
|
+
Classifier: Topic :: Utilities
|
|
27
|
+
Requires-Python: >=3.10
|
|
28
|
+
Description-Content-Type: text/x-rst
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Requires-Dist: pillow<13,>8
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
pybarcodes
|
|
34
|
+
==========
|
|
35
|
+
|
|
36
|
+
.. image:: https://readthedocs.org/projects/pybarcodes/badge/?version=latest
|
|
37
|
+
:target: https://pybarcodes.readthedocs.io/en/latest/?badge=latest
|
|
38
|
+
:alt: Documentation Status
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
.. image:: https://img.shields.io/pypi/v/pybarcodes.svg
|
|
42
|
+
:target: https://pypi.python.org/pypi/pybarcodes
|
|
43
|
+
:alt: PyPI version info
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
.. image:: https://img.shields.io/pypi/pyversions/pybarcodes.svg
|
|
47
|
+
:target: https://pypi.python.org/pypi/pybarcodes
|
|
48
|
+
:alt: PyPI supported Python versions
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
This is a python package to create and read barcodes
|
|
52
|
+
You can create file-like objects, text files and images from just a barcode number.
|
|
53
|
+
Image generation is fast so it can be used to create images in bulk.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
Supported Barcode Types
|
|
57
|
+
------------------------
|
|
58
|
+
|
|
59
|
+
- EAN13
|
|
60
|
+
- EAN8
|
|
61
|
+
- EAN14
|
|
62
|
+
- JAN
|
|
63
|
+
- CODE39
|
|
64
|
+
|
|
65
|
+
More types will soon be supported.
|
|
66
|
+
PRs are welcome :)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
Installing
|
|
70
|
+
-----------
|
|
71
|
+
|
|
72
|
+
**Python 3.10 or higher is required**
|
|
73
|
+
|
|
74
|
+
To install the library you can run the following command:
|
|
75
|
+
|
|
76
|
+
.. code:: bash
|
|
77
|
+
|
|
78
|
+
pip install pybarcodes
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
Quick Example
|
|
82
|
+
--------------
|
|
83
|
+
|
|
84
|
+
You can see what barcodes are supported
|
|
85
|
+
|
|
86
|
+
.. code:: py
|
|
87
|
+
|
|
88
|
+
>>> import pybarcodes
|
|
89
|
+
>>> pybarcodes.SUPPORTED_BARCODES
|
|
90
|
+
['EAN13', 'EAN8', 'EAN14', 'JAN', 'CODE39']
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
And you can use this to view the barcode that was generated:
|
|
95
|
+
|
|
96
|
+
.. code:: py
|
|
97
|
+
|
|
98
|
+
from pybarcodes import EAN13
|
|
99
|
+
|
|
100
|
+
CODE = "012345678905"
|
|
101
|
+
barcode = EAN13(CODE)
|
|
102
|
+
barcode.show()
|
|
103
|
+
|
|
104
|
+
This is pretty much all the code you need to generate a barcode.
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
Saving an image of the barcode is pretty straightforward.
|
|
108
|
+
|
|
109
|
+
.. code:: py
|
|
110
|
+
|
|
111
|
+
from pybarcodes import EAN14
|
|
112
|
+
|
|
113
|
+
barcode = EAN14("40700719670720")
|
|
114
|
+
|
|
115
|
+
# Saves the image in PNG format
|
|
116
|
+
barcode.save("myimage.png")
|
|
117
|
+
|
|
118
|
+
# You can also resize it.
|
|
119
|
+
barcode.save("myimage2.png", size=(100000, 1000000))
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
EAN13 output from example 2:
|
|
125
|
+
|
|
126
|
+
.. image:: https://i.imgur.com/wd7jyIx.png
|
|
127
|
+
:target: https://i.imgur.com/wd7jyIx.png
|
|
128
|
+
:alt: Image of Barcode
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
Links
|
|
132
|
+
------
|
|
133
|
+
|
|
134
|
+
- `Documentation <https://pybarcodes.readthedocs.io/en/latest/index.html>`_
|
|
135
|
+
- `PyPi <https://pypi.org/project/pybarcodes/>`_
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.rst
|
|
3
|
+
pyproject.toml
|
|
4
|
+
pybarcodes/__init__.py
|
|
5
|
+
pybarcodes/barcode.py
|
|
6
|
+
pybarcodes/codes.py
|
|
7
|
+
pybarcodes/ean.py
|
|
8
|
+
pybarcodes/exceptions.py
|
|
9
|
+
pybarcodes.egg-info/PKG-INFO
|
|
10
|
+
pybarcodes.egg-info/SOURCES.txt
|
|
11
|
+
pybarcodes.egg-info/dependency_links.txt
|
|
12
|
+
pybarcodes.egg-info/requires.txt
|
|
13
|
+
pybarcodes.egg-info/top_level.txt
|
|
14
|
+
pybarcodes/codings/__init__.py
|
|
15
|
+
pybarcodes/codings/codex.py
|
|
16
|
+
pybarcodes/codings/ean.py
|
|
17
|
+
pybarcodes/fonts/arial.ttf
|
|
18
|
+
tests/test_codes.py
|
|
19
|
+
tests/test_ean.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pillow<13,>8
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pybarcodes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pybarcodes"
|
|
3
|
-
version = "1.0.
|
|
3
|
+
version = "1.0.3"
|
|
4
4
|
description = "A Python package for barcode generation"
|
|
5
5
|
authors = [{ name = "atbuy", email = "buy@atbuy.dev" }]
|
|
6
6
|
license = "MIT"
|
|
@@ -15,10 +15,8 @@ keywords = [
|
|
|
15
15
|
"jan",
|
|
16
16
|
"python",
|
|
17
17
|
]
|
|
18
|
-
include = ["fonts/*.ttf"]
|
|
19
18
|
classifiers = [
|
|
20
19
|
"Development Status :: 5 - Production/Stable",
|
|
21
|
-
"License :: OSI Approved :: MIT License",
|
|
22
20
|
"Intended Audience :: Developers",
|
|
23
21
|
"Natural Language :: English",
|
|
24
22
|
"Operating System :: OS Independent",
|
|
@@ -35,6 +33,10 @@ classifiers = [
|
|
|
35
33
|
]
|
|
36
34
|
dependencies = ["pillow>8,<13"]
|
|
37
35
|
|
|
36
|
+
[dependency-groups]
|
|
37
|
+
dev = ["pre-commit==4.6.0", "ruff==0.15.12"]
|
|
38
|
+
tests = ["pytest==9.0.3", "pytest-cov==7.1.0"]
|
|
39
|
+
|
|
38
40
|
[project.urls]
|
|
39
41
|
Homepage = "https://github.com/atbuy/pybarcodes"
|
|
40
42
|
Repository = "https://github.com/atbuy/pybarcodes"
|
|
@@ -42,16 +44,12 @@ Repository = "https://github.com/atbuy/pybarcodes"
|
|
|
42
44
|
"Source Code" = "https://github.com/atbuy/pybarcodes"
|
|
43
45
|
"CI/CD" = "https://github.com/atbuy/pybarcodes/actions"
|
|
44
46
|
|
|
47
|
+
[tool.setuptools.packages.find]
|
|
48
|
+
include = ["pybarcodes*"]
|
|
45
49
|
|
|
46
|
-
[tool.
|
|
47
|
-
|
|
48
|
-
pytest-cov = "7.0.0"
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
[tool.poetry.group.dev.dependencies]
|
|
52
|
-
pre-commit = "4.5.1"
|
|
53
|
-
ruff = "0.15.1"
|
|
50
|
+
[tool.setuptools.package-data]
|
|
51
|
+
pybarcodes = ["fonts/*.ttf"]
|
|
54
52
|
|
|
55
53
|
[build-system]
|
|
56
|
-
requires = ["
|
|
57
|
-
build-backend = "
|
|
54
|
+
requires = ["setuptools"]
|
|
55
|
+
build-backend = "setuptools.build_meta"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from pybarcodes import CODE39
|
|
2
|
+
from pybarcodes.exceptions import IncorrectFormat
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def test_code39():
|
|
6
|
+
code = "0123456789abcdefghijklmnopqrstuvwxyz.-$+/$ "
|
|
7
|
+
barcode = CODE39(code)
|
|
8
|
+
|
|
9
|
+
assert barcode.BARCODE_FONT_SIZE
|
|
10
|
+
assert barcode.BARCODE_PADDING
|
|
11
|
+
assert barcode.BARCODE_SIZE
|
|
12
|
+
assert barcode.BARCODE_COLUMN_NUMBER
|
|
13
|
+
|
|
14
|
+
assert barcode == code.upper() + "/"
|
|
15
|
+
|
|
16
|
+
assert barcode.calculate_checksum(code) == 40
|
|
17
|
+
assert barcode.calculate_checksum() == 40
|
|
18
|
+
|
|
19
|
+
try:
|
|
20
|
+
code = "^"
|
|
21
|
+
barcode = CODE39(code)
|
|
22
|
+
except IncorrectFormat:
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
binary_string = barcode.get_binary_string
|
|
26
|
+
start_char = binary_string[:6]
|
|
27
|
+
stop_char = binary_string[-6:]
|
|
28
|
+
assert start_char == "0 0110"
|
|
29
|
+
assert stop_char == "0 0110"
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
from pybarcodes import EAN8, EAN13, EAN14, JAN
|
|
2
|
+
from pybarcodes.exceptions import IncorrectFormat
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def test_ean13():
|
|
6
|
+
code = "400638133393"
|
|
7
|
+
barcode = EAN13(code)
|
|
8
|
+
barcode2 = EAN13(code)
|
|
9
|
+
|
|
10
|
+
# Check if the required attributes exist
|
|
11
|
+
assert barcode.BARCODE_LENGTH
|
|
12
|
+
assert barcode.BARCODE_SIZE
|
|
13
|
+
assert barcode.BARCODE_FONT_SIZE
|
|
14
|
+
assert barcode.BARCODE_COLUMN_NUMBER
|
|
15
|
+
assert barcode.BARCODE_PADDING
|
|
16
|
+
assert barcode.FIRST_SECTION
|
|
17
|
+
assert barcode.SECOND_SECTION
|
|
18
|
+
assert barcode.WEIGHTS
|
|
19
|
+
assert barcode.HAS_STRUCTURE
|
|
20
|
+
|
|
21
|
+
assert barcode == code + "1"
|
|
22
|
+
assert barcode == barcode2
|
|
23
|
+
|
|
24
|
+
# Check if the checksum digit is calculated correctly
|
|
25
|
+
# The check digit should be `1`
|
|
26
|
+
code = "400638133393"
|
|
27
|
+
checkdigit = EAN13.calculate_checksum(code)
|
|
28
|
+
assert checkdigit == 1
|
|
29
|
+
|
|
30
|
+
code = "40063813339398736412039867123409586345"
|
|
31
|
+
barcode = EAN13(code)
|
|
32
|
+
# The check digit is calculated when instansiating
|
|
33
|
+
assert barcode == "4006381333931"
|
|
34
|
+
|
|
35
|
+
try:
|
|
36
|
+
code = "1"
|
|
37
|
+
barcode = EAN13(code)
|
|
38
|
+
except IncorrectFormat:
|
|
39
|
+
pass
|
|
40
|
+
|
|
41
|
+
# Check if guards are in the correct positions
|
|
42
|
+
binary_string = barcode.get_binary_string
|
|
43
|
+
left_guard = binary_string[:3]
|
|
44
|
+
right_guard = binary_string[-3:]
|
|
45
|
+
center_guard = binary_string[45:50]
|
|
46
|
+
assert left_guard == "101"
|
|
47
|
+
assert right_guard == "101"
|
|
48
|
+
assert center_guard == "01010"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_ean8():
|
|
52
|
+
code = "0123456"
|
|
53
|
+
barcode = EAN8(code)
|
|
54
|
+
|
|
55
|
+
# Check if the required attributes exist
|
|
56
|
+
assert barcode.BARCODE_LENGTH
|
|
57
|
+
assert barcode.BARCODE_SIZE
|
|
58
|
+
assert barcode.BARCODE_FONT_SIZE
|
|
59
|
+
assert barcode.BARCODE_COLUMN_NUMBER
|
|
60
|
+
assert barcode.BARCODE_PADDING
|
|
61
|
+
assert barcode.FIRST_SECTION
|
|
62
|
+
assert barcode.SECOND_SECTION
|
|
63
|
+
assert barcode.WEIGHTS
|
|
64
|
+
assert not barcode.HAS_STRUCTURE
|
|
65
|
+
|
|
66
|
+
# Check digit for this barcode should be `5`
|
|
67
|
+
assert EAN8.calculate_checksum(code) == 5
|
|
68
|
+
|
|
69
|
+
code = "012345628743652398476528347652987"
|
|
70
|
+
barcode = EAN8(code)
|
|
71
|
+
|
|
72
|
+
# The check digit is calculated when instansiating
|
|
73
|
+
assert barcode == "01234565"
|
|
74
|
+
|
|
75
|
+
try:
|
|
76
|
+
code = "1"
|
|
77
|
+
barcode = EAN8(code)
|
|
78
|
+
except IncorrectFormat:
|
|
79
|
+
pass
|
|
80
|
+
|
|
81
|
+
# Check if guards in correct positions
|
|
82
|
+
binary_string = barcode.get_binary_string
|
|
83
|
+
left_guard = binary_string[:3]
|
|
84
|
+
right_guard = binary_string[-3:]
|
|
85
|
+
center_guard = binary_string[33:38]
|
|
86
|
+
assert left_guard == "101"
|
|
87
|
+
assert right_guard == "101"
|
|
88
|
+
assert center_guard == "01010"
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_ean14():
|
|
92
|
+
code = "4070071967072013242346"
|
|
93
|
+
barcode = EAN14(code)
|
|
94
|
+
|
|
95
|
+
# Check if the required attributes exist
|
|
96
|
+
assert barcode.BARCODE_LENGTH
|
|
97
|
+
assert barcode.BARCODE_SIZE
|
|
98
|
+
assert barcode.BARCODE_FONT_SIZE
|
|
99
|
+
assert barcode.BARCODE_COLUMN_NUMBER
|
|
100
|
+
assert barcode.BARCODE_PADDING
|
|
101
|
+
assert barcode.FIRST_SECTION
|
|
102
|
+
assert barcode.SECOND_SECTION
|
|
103
|
+
assert barcode.WEIGHTS
|
|
104
|
+
assert barcode.HAS_STRUCTURE
|
|
105
|
+
|
|
106
|
+
# Check digit for this barcode should be `0`
|
|
107
|
+
assert EAN14.calculate_checksum(code) == 0
|
|
108
|
+
|
|
109
|
+
# The check digit is calculated when instansiating
|
|
110
|
+
assert barcode == "40700719670720"
|
|
111
|
+
|
|
112
|
+
try:
|
|
113
|
+
code = "1"
|
|
114
|
+
barcode = EAN14(code)
|
|
115
|
+
except IncorrectFormat:
|
|
116
|
+
pass
|
|
117
|
+
|
|
118
|
+
# Check if guards in correct positions
|
|
119
|
+
binary_string = barcode.get_binary_string
|
|
120
|
+
left_guard = binary_string[:3]
|
|
121
|
+
right_guard = binary_string[-3:]
|
|
122
|
+
center_guard = binary_string[45:50]
|
|
123
|
+
assert left_guard == "101"
|
|
124
|
+
assert right_guard == "101"
|
|
125
|
+
assert center_guard == "01010"
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def test_jan():
|
|
129
|
+
code = "450638133393"
|
|
130
|
+
barcode = JAN(code)
|
|
131
|
+
barcode2 = JAN(code)
|
|
132
|
+
|
|
133
|
+
# Check if the required attributes exist
|
|
134
|
+
assert barcode.BARCODE_LENGTH
|
|
135
|
+
assert barcode.BARCODE_SIZE
|
|
136
|
+
assert barcode.BARCODE_FONT_SIZE
|
|
137
|
+
assert barcode.BARCODE_COLUMN_NUMBER
|
|
138
|
+
assert barcode.BARCODE_PADDING
|
|
139
|
+
assert barcode.FIRST_SECTION
|
|
140
|
+
assert barcode.SECOND_SECTION
|
|
141
|
+
assert barcode.WEIGHTS
|
|
142
|
+
assert barcode.HAS_STRUCTURE
|
|
143
|
+
|
|
144
|
+
assert barcode == code + "6"
|
|
145
|
+
assert barcode == barcode2
|
|
146
|
+
|
|
147
|
+
# Check if the checksum digit is calculated correctly
|
|
148
|
+
# The check digit should be `1`
|
|
149
|
+
code = "450638133393"
|
|
150
|
+
checkdigit = JAN.calculate_checksum(code)
|
|
151
|
+
assert checkdigit == 6
|
|
152
|
+
|
|
153
|
+
code = "45063813339398736412039867123409586345"
|
|
154
|
+
barcode = JAN(code)
|
|
155
|
+
# The check digit is calculated when instansiating
|
|
156
|
+
assert barcode == "4506381333936"
|
|
157
|
+
try:
|
|
158
|
+
code = "1"
|
|
159
|
+
barcode = JAN(code)
|
|
160
|
+
except IncorrectFormat:
|
|
161
|
+
pass
|
|
162
|
+
|
|
163
|
+
# Check if guards are in the correct positions
|
|
164
|
+
binary_string = barcode.get_binary_string
|
|
165
|
+
left_guard = binary_string[:3]
|
|
166
|
+
right_guard = binary_string[-3:]
|
|
167
|
+
center_guard = binary_string[45:50]
|
|
168
|
+
assert left_guard == "101"
|
|
169
|
+
assert right_guard == "101"
|
|
170
|
+
assert center_guard == "01010"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|