X Tutup
Skip to content

Add test with pyzbar, to use external library to validate rendered barcodes#256

Open
rejjen wants to merge 3 commits intoWhyNotHugo:mainfrom
rejjen:test_with_pyzbar
Open

Add test with pyzbar, to use external library to validate rendered barcodes#256
rejjen wants to merge 3 commits intoWhyNotHugo:mainfrom
rejjen:test_with_pyzbar

Conversation

@rejjen
Copy link

@rejjen rejjen commented Jan 7, 2026

This is attempt to handle #181.

Requires Pillow and pyzbar to do any testing, but should gracefully skip if not installed
Requires cairosvg to test svg rendered, but also gracefully skip.

They should install with pip install .[test_with_pyzbar]

Copy link
Owner

@WhyNotHugo WhyNotHugo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the changes to barcode/isxn.py related?

Comment on lines +15 to +21
try:
import cairosvg
import cairocffi
cairocffi.Context(cairocffi.ImageSurface(cairocffi.FORMAT_ARGB32, 1, 1))
HAS_CAIROSVG = True
except (ImportError, OSError):
HAS_CAIROSVG = False
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer for tests to outright fail; this skips them silently and it would be easy to miss that they're not running properly.

I have no objection to adding test-only dependencies; users won't be affected by these.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should mark tests as skipped I believe and provide reason if library is not loaded correctly.
https://github.com/WhyNotHugo/python-barcode/pull/256/changes#diff-2d1975a58b23083a3f9f1331cb6534c4e8da053b6f66b1c60a1c035ec035d79bR99

Similarly to pytest.importorskip above.

pyproject.toml Outdated

[project.optional-dependencies]
images = ["pillow"]
test_with_pyzbar = ["pillow", "cairosvg", "pyzbar"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use dependency groups for these:

[dependency-groups]
test = ["pillow", "cairosvg", "pyzbar"]
``

@rejjen
Copy link
Author

rejjen commented Mar 8, 2026

Are the changes to barcode/isxn.py related?

Yes, without changes validation will fail for tests/test_with_pyzbar.py::test_imagewriter - AssertionError: ISSN failed to decode.

There is some overlap with PR #255

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

X Tutup