Skip to content

Commit

Permalink
Tidy up datamatrix, remove distutils dep.
Browse files Browse the repository at this point in the history
  • Loading branch information
mmulqueen committed Jul 17, 2024
1 parent 7b5aa48 commit 42296df
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions pystrich/datamatrix/test_datamatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
__revision__ = "$Rev$"

import unittest
import os
from distutils.spawn import find_executable
from shutil import which
import subprocess

from pystrich.datamatrix import DataMatrixEncoder

dmtxread_path = find_executable("dmtxread")
dmtxwrite_path = find_executable("dmtxwrite")
dmtxread_path = which("dmtxread")
dmtxwrite_path = which("dmtxwrite")


def dmtxread(datamatrix_path: str) -> str:
"""Read a datamatrix barcode from an image file"""
if not dmtxread_path:
raise RuntimeError("dmtxread not found")
return subprocess.check_output([dmtxread_path, datamatrix_path]).decode()


class MatrixTest(unittest.TestCase):
Expand Down Expand Up @@ -50,12 +56,7 @@ def test_encode_decode(self):

encoder = DataMatrixEncoder(string)
encoder.save("datamatrix-test.png")

if not dmtxread_path:
print("dmtxread is not installed or cannot be found - Debian package libdmtx-utils")
else:
fin = os.popen("sh -c '%s datamatrix-test.png'" % dmtxread_path)
self.assertEqual(fin.readline(), string)
self.assertEqual(dmtxread("datamatrix-test.png"), string)

def test_encoding(self):
"""Test that text is correctly encoded, and also that padding
Expand Down

0 comments on commit 42296df

Please sign in to comment.