Skip to content

Commit

Permalink
More test.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjko committed Oct 22, 2023
1 parent 047c144 commit 145b83e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 12 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/compile-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@ jobs:
run: |
sudo apt-get -y install libjpeg-dev
# Initialize and build
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.11"

- name: Build
run: |
./configure
make -j
make printable.man
- name: Tests
run: |
make test
# Gather documentation and executables to a common directory
- name: Prepare files
if: matrix.os != 'ubuntu-latest'
Expand Down
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ spell:
codespell -S .git,tools

test: all
(cd test && $(PYTHON) test.py)
(cd test && $(PYTHON) test.py -v)


.PHONY: test
Expand Down
59 changes: 49 additions & 10 deletions test/test.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ class JpeginfoTests(unittest.TestCase):

def run_test(self, args, check=True):
"""execute jpeginfo for a test"""
command = [self.program]
if isinstance(args, list):
command.extend(args)
else:
if len(args) > 0:
command.append(args)
command = [self.program] + args
res = subprocess.run(command, encoding="utf-8", check=check,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = res.stdout
Expand All @@ -47,25 +42,69 @@ def run_test(self, args, check=True):

def test_version(self):
"""test version information output"""
output, _ = self.run_test('--version')
output, _ = self.run_test(['--version'])
self.assertIn('GNU General Public License', output)
self.assertRegex(output, r'jpeginfo v\d+\.\d+\.\d')

def test_noarguments(self):
"""test running withouth arguments"""
output, res = self.run_test('', check=False)
output, res = self.run_test([], check=False)
self.assertEqual(1, res)
self.assertIn('file arguments missing', output)

def test_basic(self):
"""test basic output"""
output, _ = self.run_test('jpeginfo_test1.jpg')
output, _ = self.run_test(['jpeginfo_test1.jpg'])
self.assertRegex(output,
r'jpeginfo_test1.jpg\s+2100\s+x\s+1500\s+24bit\s+'
r'P\s+Exif,IPTC,XMP,ICC,Adobe,UNKNOWN\s+320159')

def test_check_mode(self):
"""test checking image integrity"""
output, res = self.run_test(['-c','jpeginfo_test2.jpg'], check=False)
self.assertEqual(0, res)
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_progressive(self):
"""test progressive mode detection"""
output, _ = self.run_test(['jpeginfo_test1.jpg'])
self.assertRegex(output, r'bit\s+P\s+')

def test_nonprogressive(self):
"""test non-progressive mode detection"""
output, _ = self.run_test(['jpeginfo_test2.jpg'])
self.assertRegex(output, r'bit\s+N\s')

def test_grayscale(self):
"""test grayscale image detection"""
output, _ = self.run_test(['jpeginfo_test3.jpg'])
self.assertRegex(output, r'\s8bit\s')

def test_md5(self):
"""test image MD5 checksum"""
output, _ = self.run_test(['--md5', 'jpeginfo_test1.jpg'])
self.assertIn('536c217b027d44cc2e4a0ad8e6e531fe', output)

def test_sha256(self):
"""test image SHA2-256 checksum"""
output, _ = self.run_test(['--sha256', 'jpeginfo_test1.jpg'])
self.assertIn('9a36209da080e187a2f749ec4ed0db3e73bcebc689ca060d929bdc7d1384edac', output)

def test_sha512(self):
"""test image SHA2-512 checksum"""
output, _ = self.run_test(['--sha512', 'jpeginfo_test1.jpg'])
self.assertIn('4d5dc047caf3cbd84eec91dce3c14e938d8d3f730b152eefb72c8c3ebfa65e91'
'46bd304b15e009df6f74e7397435a10f375c5453a60e32c9aca738051c36e211', output)

def test_comments(self):
"""test image comments"""
output, _ = self.run_test(['-C', 'jpeginfo_test2.jpg'])
self.assertIn('This is a test comment.', output)


if __name__ == '__main__':
unittest.main()


# eof :-)

0 comments on commit 145b83e

Please sign in to comment.