Skip to content

Commit

Permalink
Clean-up Tests
Browse files Browse the repository at this point in the history
Migrated "smoke" tests and dropped some of them
(without reducing test coverage).

work on issue #14
  • Loading branch information
adrianschlatter committed Sep 15, 2023
1 parent afff1b0 commit 12392e2
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 120 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ per-file-ignores =
test_C40.py: F401
test_text.py: F401
# bare except: We *are* trying to crash it:
test_smoke.py: E722
test_datamatrix.py: E722
filename =
*/src/*.py
*/docs/*.py
Expand Down
76 changes: 74 additions & 2 deletions tests/test_datamatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,43 @@
.. author: Adrian Schlatter
"""

import unittest
import ppf.datamatrix as put
import unittest
import random
from .common import EDIFACT, ASCII


class Test_DataMatrix_Attributes(unittest.TestCase):
"""Test DataMatrix attribute acces for unexpected exceptions"""

def setUp(self):
try:
self.dm = put.DataMatrix(EDIFACT)
except:
self.fail('Exception upon valid instantiation')

def test_methods(self):
"""Run each method and test for exceptions."""
methods = ['svg', '__repr__', '_repr_svg_']

for method in methods:
try:
getattr(self.dm, method)()
except:
self.fail(f'DataMatrix.{method} raises exception')

def test_properties(self):
"""Access each property and test for exceptions."""
props = ['message', 'matrix']

for prop in props:
try:
getattr(self.dm, prop)
except:
self.fail(f'DataMatrix.{prop} raises exception')


class Test_DataMatrix(unittest.TestCase):
class Test_DataMatrix_Invalid_Codec(unittest.TestCase):
"""Test DataMatrix"""

def test_invalid_codec(self):
Expand Down Expand Up @@ -51,3 +83,43 @@ def test_rect_matrix(self):
[1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
self.assertTrue(dm.matrix, truth)


class Test_CornerCases(unittest.TestCase):
"""Test corner cases such as rarely used branches etc."""

def test_corner_B_omit_upper_left_loop_exit(self):
"""Test said branch of code to avoid endless loop."""
msg = ')*+,-./01'
# make sure that this does not go into endless loop:
datamatrix = put.DataMatrix(msg)
self.assertTrue(len(datamatrix.matrix) > 0)

def test_l_greater_255_blocks(self):
"""Test branch l>255 #blocks in DataMatrix.matrix property."""
datamatrix = put.DataMatrix('A' * 230)
self.assertTrue(len(datamatrix.matrix) > 0)

def test_long_square_message(self):
"""Test very long messages for same behavior as datamatrix-svg."""
m = put.DataMatrix('~' * 1558).matrix
self.assertTrue(len(m) > 0)
with self.assertRaises(ValueError):
m = put.DataMatrix('~' * 1559).matrix

def test_long_rect_message(self):
"""Test very long rect messages for same behavior as datamatrix-svg."""
m = put.DataMatrix('~' * 49, rect=True).matrix
self.assertTrue(len(m) < len(m[0]))

m = put.DataMatrix('~' * 50, rect=True).matrix
self.assertTrue(len(m) == len(m[0]))

@unittest.skip
def test_random_messages(self):
"""Test random messages."""
while True:
n = random.randint(0, 1024)
msg = ''.join(random.choices(ASCII, k=n))
datamatrix = put.DataMatrix(msg)
self.assertTrue(len(datamatrix.matrix) > 0)
117 changes: 0 additions & 117 deletions tests/test_smoke.py

This file was deleted.

0 comments on commit 12392e2

Please sign in to comment.