From 88c77bd89e2c2a5f023e6638816c9153b6276d35 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 21 Dec 2021 12:08:16 -0800 Subject: [PATCH] add zipinfo tests --- tests/fixtures/osx-10.14.6/zipinfo-multi.json | 1 + tests/test_zipinfo.py | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tests/fixtures/osx-10.14.6/zipinfo-multi.json create mode 100644 tests/test_zipinfo.py diff --git a/tests/fixtures/osx-10.14.6/zipinfo-multi.json b/tests/fixtures/osx-10.14.6/zipinfo-multi.json new file mode 100644 index 00000000..1c551076 --- /dev/null +++ b/tests/fixtures/osx-10.14.6/zipinfo-multi.json @@ -0,0 +1 @@ +[{"archive":"jc1.zip","size":4116,"size_unit":"bytes","number_entries":1,"number_files":1,"bytes_uncompressed":11837,"bytes_compressed":3966,"percent_compressed":66.5,"files":[{"flags":"-rw-r--r--","zipversion":"2.1","zipunder":"unx","filesize":11837,"type":"bX","method":"defN","date":"21-Dec-08","time":"20:50","filename":"jc.1"}]},{"archive":"testzip.zip","size":8106,"size_unit":"bytes","number_entries":2,"number_files":2,"bytes_uncompressed":8539,"bytes_compressed":7651,"percent_compressed":10.4,"files":[{"flags":"-rw-r--r--","zipversion":"3.0","zipunder":"unx","filesize":197,"type":"tx","method":"defN","date":"21-Aug-03","time":"15:12","filename":"round-table.gv"},{"flags":"-rw-r--r--","zipversion":"3.0","zipunder":"unx","filesize":8342,"type":"bx","method":"defN","date":"21-Aug-03","time":"15:12","filename":"round-table.gv.pdf"}]},{"archive":"micro.zip","size":6144,"size_unit":"bytes","number_entries":8,"number_files":8,"bytes_uncompressed":22839,"bytes_compressed":4908,"percent_compressed":78.5,"files":[{"flags":"-rw-r--r--","zipversion":"2.1","zipunder":"unx","filesize":10688,"type":"bX","method":"defN","date":"19-Sep-30","time":"16:47","filename":"microsimservermac.py"},{"flags":"drwxrwxr-x","zipversion":"2.1","zipunder":"unx","filesize":0,"type":"bx","method":"stor","date":"21-Dec-20","time":"14:33","filename":"__MACOSX/"},{"flags":"-rw-r--r--","zipversion":"2.1","zipunder":"unx","filesize":176,"type":"bX","method":"defN","date":"19-Sep-30","time":"16:47","filename":"__MACOSX/._microsimservermac.py"},{"flags":"-rw-r--r--","zipversion":"2.1","zipunder":"unx","filesize":528,"type":"bX","method":"defN","date":"19-Aug-27","time":"07:46","filename":"Dockerfile"},{"flags":"-rw-r--r--","zipversion":"2.1","zipunder":"unx","filesize":10538,"type":"bX","method":"defN","date":"19-Oct-01","time":"13:22","filename":"microsimserver.py"},{"flags":"-rw-r--r--","zipversion":"2.1","zipunder":"unx","filesize":380,"type":"bX","method":"defN","date":"19-Oct-01","time":"13:22","filename":"changelog.txt"},{"flags":"-rwxr-xr-x","zipversion":"2.1","zipunder":"unx","filesize":263,"type":"bX","method":"defN","date":"19-Oct-01","time":"12:09","filename":"dockerhub.sh"},{"flags":"-rw-r--r--","zipversion":"2.1","zipunder":"unx","filesize":266,"type":"bX","method":"defN","date":"19-Oct-01","time":"12:09","filename":"__MACOSX/._dockerhub.sh"}]}] diff --git a/tests/test_zipinfo.py b/tests/test_zipinfo.py new file mode 100644 index 00000000..31d2aec4 --- /dev/null +++ b/tests/test_zipinfo.py @@ -0,0 +1,46 @@ +import os +import unittest +import json +import jc.parsers.zipinfo + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + + +class MyTests(unittest.TestCase): + + def setUp(self): + # input + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/rhel-8/zipinfo.out'), 'r', encoding='utf-8') as f: + self.rhel_8_zipinfo = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/zipinfo-multi.out'), 'r', encoding='utf-8') as f: + self.osx_10_14_6_zipinfo_multi = f.read() + + # output + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/rhel-8/zipinfo.json'), 'r', encoding='utf-8') as f: + self.rhel_8_zipinfo_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/osx-10.14.6/zipinfo-multi.json'), 'r', encoding='utf-8') as f: + self.osx_10_14_6_zipinfo_multi_json = json.loads(f.read()) + + def test_zipinfo_nodata(self): + """ + Test 'zipinfo' parser with no data + """ + self.assertEqual(jc.parsers.zipinfo.parse('', quiet=True), []) + + def test_zipinfo_rhel_8(self): + """ + Test 'zipinfo' on Red Hat 8 + """ + self.assertEqual(jc.parsers.zipinfo.parse(self.rhel_8_zipinfo, quiet=True), self.rhel_8_zipinfo_json) + + def test_zipinfo_multi_osx_10_14_6(self): + """ + Test 'zipinfo' with multiple archives on OSX 10.14.6 + """ + self.assertEqual(jc.parsers.zipinfo.parse(self.osx_10_14_6_zipinfo_multi, quiet=True), self.osx_10_14_6_zipinfo_multi_json) + + +if __name__ == '__main__': + unittest.main()