Skip to content

Commit

Permalink
Updated unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjko committed Oct 22, 2023
1 parent eef2936 commit eb3bb3f
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ class JpeginfoTests(unittest.TestCase):
def run_test(self, args, check=True):
"""execute jpeginfo for a test"""
command = [self.program] + args
if self.debug:
print(f'\nRun command: {" ".join(command)}')
res = subprocess.run(command, encoding="utf-8", check=check,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = res.stdout
if self.debug:
print(res)
print(f'Result: {res.returncode}')
print(f'---\n{output}\n---\n')
return output, res.returncode


Expand All @@ -63,13 +66,22 @@ def test_basic(self):

def test_check_mode(self):
"""test checking image integrity"""
output, res = self.run_test(['-c','jpeginfo_test2.jpg'], check=False)
output, res = self.run_test(['-c', 'jpeginfo_test2.jpg'], check=False)
self.assertEqual(0, res)
self.assertRegex(output, r'\sOK\s*$')
output, res = self.run_test(['-c','jpeginfo_test2_broken.jpg'], check=False)

def test_broken_image(self):
"""test processing broken image"""
output, res = self.run_test(['-c', 'jpeginfo_test2_broken.jpg'], check=False)
self.assertIn('WARNING Premature end of JPEG file', output)
self.assertNotEqual(0, res)

def test_non_image(self):
"""test processing non-image file"""
output, res = self.run_test(['-c', 'README'], check=False)
self.assertRegex(output, r'\sERROR\s+Not a JPEG file')
self.assertNotEqual(0, res)

def test_progressive(self):
"""test progressive mode detection"""
output, _ = self.run_test(['jpeginfo_test1.jpg'])
Expand Down

0 comments on commit eb3bb3f

Please sign in to comment.