Skip to content

Commit

Permalink
Merge pull request #119 from NaturalHistoryMuseum/feature/117-test-wo…
Browse files Browse the repository at this point in the history
…rkflows

Feature/117 test workflows
  • Loading branch information
quicklizard99 committed Oct 23, 2021
2 parents e19ebc1 + 153cfba commit 76d337d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 24 deletions.
18 changes: 11 additions & 7 deletions .github/worflows/test.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ jobs:
strategy:
matrix:
os: [ubuntu-18.04]
python-version: [2.7, 3.6, 3.7, 3.8, 3.9, 3.10]
python-version: [2.7, 3.6, 3.7, 3.8, 3.9, 3.10.0]
include:
- os: macos-10.15
python-version: 3.8
python-version: 3.10.0
# TODO Include DLLs in source code?
# - os: windows-2019
# python-version: 3.8
# python-version: 3.10

runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -42,12 +42,16 @@ jobs:

- name: Install dependencies
run: |
python -m pip install --upgrade pip==21.3
python -m pip install --upgrade pip==20.3.4
pip install -r requirements-test.txt
pip install coveralls>=3.2.0
- name: Run tests
run: pytest --verbose --cov=pyzbar yzbar
run: pytest --verbose --cov=pyzbar pyzbar

- name: Upload coverage
run: coveralls
if: ${{ matrix.python-version == '3.10.0' && runner.os == 'Linux' }}
run: |
pip install coveralls>=3.2.0
coveralls --service=github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.idea
.tox
MANIFEST.in
coverage.xml
build
dist
htmlcov
Expand Down
2 changes: 1 addition & 1 deletion DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
```
python -m venv venv
source ./venv/bin/activate
pip install -U pip==21.3
pip install -U pip==20.3.4
pip install -r requirements.txt
python -m pytest --verbose --cov=pyzbar --cov-report=term-missing --cov-report=html pyzbar
Expand Down
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ symbol types
>>> decode(Image.open('pyzbar/tests/qrcode.png'), symbols=[ZBarSymbol.CODE128])
[]

ZBar versions
-------------

Development of the `original zbar <http://zbar.sourceforge.net/>`__ stopped in 2012.
Development was started again in 2019 under a `new project <https://github.com/mchehab/zbar/>`__
that has added some new features, including support for decoding
barcode orientation. At the time of writing the project does not produce Windows DLLs.
If you see `orientation=None` then your system has an older release of zbar.
The ``zbar`` ``DLL``\ s that are included with the Windows Python wheels are
an old build that does not support orientation.

Quality field
-------------
From
Expand Down
11 changes: 9 additions & 2 deletions pyzbar/pyzbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
)

__all__ = [
'decode', 'Point', 'Rect', 'Decoded', 'ZBarSymbol', 'EXTERNAL_DEPENDENCIES'
'decode', 'Point', 'Rect', 'Decoded', 'ZBarSymbol', 'EXTERNAL_DEPENDENCIES', 'ORIENTATION_AVAILABLE'
]


ORIENTATION_AVAILABLE = zbar_symbol_get_orientation is not None

Decoded = namedtuple('Decoded', 'data type rect polygon quality orientation')

# ZBar's magic 'fourcc' numbers that represent image formats
Expand Down Expand Up @@ -120,7 +122,12 @@ def _decode_symbols(symbols):
)
for index in _RANGEFN(zbar_symbol_get_loc_size(symbol))
)
orientation = ZBarOrientation(zbar_symbol_get_orientation(symbol)).name

if zbar_symbol_get_orientation:
orientation = ZBarOrientation(zbar_symbol_get_orientation(symbol)).name
else:
orientation = None

yield Decoded(
data=data,
type=symbol_type,
Expand Down
14 changes: 7 additions & 7 deletions pyzbar/tests/test_pyzbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from pyzbar import wrapper
from pyzbar.pyzbar import (
decode, Decoded, Rect, ZBarSymbol, EXTERNAL_DEPENDENCIES
decode, Decoded, Rect, ZBarSymbol, EXTERNAL_DEPENDENCIES, ORIENTATION_AVAILABLE
)
from pyzbar.pyzbar_error import PyZbarError

Expand All @@ -40,15 +40,15 @@ class TestDecode(unittest.TestCase):
type='CODE128',
rect=Rect(left=37, top=550, width=324, height=76),
polygon=[(37, 551), (37, 625), (361, 626), (361, 550)],
orientation='UP',
orientation='UP' if ORIENTATION_AVAILABLE else None,
quality=77,
),
Decoded(
data=b'Rana temporaria',
type='CODE128',
rect=Rect(left=4, top=0, width=390, height=76),
polygon=[(4, 1), (4, 75), (394, 76), (394, 0)],
orientation='UP',
orientation='UP' if ORIENTATION_AVAILABLE else None,
quality=77,
),
]
Expand All @@ -59,7 +59,7 @@ class TestDecode(unittest.TestCase):
type='CODE128',
rect=Rect(left=4, top=0, width=390, height=75),
polygon=[(4, 1), (4, 75), (394, 74), (394, 0)],
orientation="UP",
orientation="UP" if ORIENTATION_AVAILABLE else None,
quality=76,
),
]
Expand All @@ -70,7 +70,7 @@ class TestDecode(unittest.TestCase):
type='QRCODE',
rect=Rect(left=27, top=27, width=145, height=145),
polygon=[(27, 27), (27, 172), (172, 172), (172, 27)],
orientation='UP',
orientation='UP' if ORIENTATION_AVAILABLE else None,
quality=1,
),
]
Expand All @@ -82,15 +82,15 @@ class TestDecode(unittest.TestCase):
type='QRCODE',
rect=Rect(left=173, top=10, width=205, height=205),
polygon=[(173, 113), (276, 215), (378, 113), (276, 10)],
orientation='UP',
orientation='UP' if ORIENTATION_AVAILABLE else None,
quality=1,
),
Decoded(
data=b'Thalassiodracon',
type='QRCODE',
rect=Rect(left=32, top=208, width=158, height=158),
polygon=[(32, 352), (177, 366), (190, 222), (46, 208)],
orientation='RIGHT',
orientation='RIGHT' if ORIENTATION_AVAILABLE else None,
quality=1,
),
]
Expand Down
16 changes: 11 additions & 5 deletions pyzbar/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,17 @@ def zbar_function(fname, restype, *args):
c_uint
)

zbar_symbol_get_orientation = zbar_function(
'zbar_symbol_get_orientation',
c_uint,
POINTER(zbar_symbol)
)

try:
zbar_symbol_get_orientation = zbar_function(
'zbar_symbol_get_orientation',
c_uint,
POINTER(zbar_symbol)
)
except AttributeError:
# This function not present in the original pre-20
zbar_symbol_get_orientation = None


zbar_symbol_next = zbar_function(
'zbar_symbol_next',
Expand Down
4 changes: 2 additions & 2 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ nose>=1.3.4
numpy>=1.8.2
pathlib>=1.0.1; python_version == '2.7'
Pillow>=3.2.0
pytest>=6.2.5
pytest-cov>=3.0.0
pytest>=4.6.11
pytest-cov>=2.12.1

0 comments on commit 76d337d

Please sign in to comment.