Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue #52 - allow schemes AutoFast and AutoBest to be used #57

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pylibdmtx/pylibdmtx.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def encode(data, scheme=None, size=None):

scheme = scheme if scheme else 'Ascii'
scheme_name = '{0}{1}'.format(
ENCODING_SCHEME_PREFIX, scheme.capitalize()
ENCODING_SCHEME_PREFIX, scheme
)
if not hasattr(DmtxScheme, scheme_name):
raise PyLibDMTXError(
Expand Down
30 changes: 28 additions & 2 deletions pylibdmtx/tests/test_pylibdmtx.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,42 @@ def test_encode_size(self):

def test_encode_scheme(self):
data = b'hello world'
encoded = encode(data, scheme='Base256')
encoded = encode(data, scheme="Base256")

# Check returned data, with the exception of the pixel data
self.assertEqual(
Encoded(width=110, height=110, bpp=24, pixels=None),
encoded._replace(pixels=None)
encoded._replace(pixels=None),
)

self._assert_encoded_data(data, encoded)

def test_encode_all_schemes(self):
data_mixed = b'Hello World 1*'
data_upper = b'HELLO WORLD 1*'

# Go through all supported encodings and check their output
for scheme, expected_size in dict(
AutoBest=100,
Ascii=110,
C40=110,
Text=100,
X12=100,
Edifact=100,
Base256=110,
).items():
data = data_upper if scheme in ["X12","Edifact"] else data_mixed
encoded = encode(data, scheme=scheme)

# Check returned data, with the exception of the pixel data
self.assertEqual(
Encoded(width=expected_size, height=expected_size, bpp=24, pixels=None),
encoded._replace(pixels=None),
'Failure with encoding scheme "{0}"'.format(scheme)
)

self._assert_encoded_data(data, encoded)

def test_invalid_scheme(self):
self.assertRaisesRegex(
PyLibDMTXError,
Expand Down