diff --git a/test_myunzip.py b/test_myunzip.py new file mode 100644 index 0000000000000000000000000000000000000000..3b456c2493d7d786eca28129a751542a33d5dcad --- /dev/null +++ b/test_myunzip.py @@ -0,0 +1,59 @@ +import unittest +import os +import filecmp +import shutil +import subprocess + + +EXEC_NAME = './myunzip0' + +class TestMyUnzip0(unittest.TestCase): + + def test_uncompressed(self): + subprocess.run([EXEC_NAME, 'tests/resources/uncompressed.zip']) + + # Check that the correct file was extracted + self.assertTrue(os.path.exists('tests/resources/uncompressed.txt')) + + # Check correct output + self.assertTrue(filecmp.cmp('tests/resources/uncompressed.txt', + 'tests/resources/uncompressed_expected.txt')) + + # Remove output + os.remove('tests/resources/uncompressed.txt') + + def test_compressed(self): + subprocess.run([EXEC_NAME, 'tests/resources/compressed.zip']) + + # Check that we extracted a DEFLATE stream + self.assertTrue(os.path.exists('tests/resources/compressed.txt.deflate')) + + # Check correct output + self.assertTrue(filecmp.cmp('tests/resources/compressed_expected.deflate', + 'tests/resources/compressed.txt.deflate')) + + # Remove output + os.remove('tests/resources/compressed.txt.deflate') + + def test_make_directories(self): + """ + Suppose the zip file was created by invoking: + # zip example.zip directory/to/example_file + Then, suppose when we unzip example.zip, the relative directory + directory/to does not exist. This directory should be created + before unzipping. + """ + subprocess.run([EXEC_NAME, 'tests/resources/directory_test.zip']) + + # Check that we made the directories. + self.assertTrue(os.path.exists('tests/resources/a/b/c.txt')) + + # Check output + self.assertTrue(filecmp.cmp('tests/resources/directory_expected.txt', + 'tests/resources/a/b/c.txt')) + + # Remove output + shutil.rmtree('tests/resources/a') + +if __name__ == '__main__': + unittest.main() diff --git a/tests/__pycache__/test_inflate.cpython-38.pyc b/tests/__pycache__/test_inflate.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fe971620a0a9bf9ee4e03d2050c0aa70bac4c1c5 Binary files /dev/null and b/tests/__pycache__/test_inflate.cpython-38.pyc differ diff --git a/tests/__pycache__/test_myunzip.cpython-38.pyc b/tests/__pycache__/test_myunzip.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..367bbd5adc744963c7773f90e0a3e61e58ecb700 Binary files /dev/null and b/tests/__pycache__/test_myunzip.cpython-38.pyc differ diff --git a/tests/__pycache__/test_myunzip0.cpython-38.pyc b/tests/__pycache__/test_myunzip0.cpython-38.pyc index 57fcf59b5c9612017570bfcaa29b4c847018b212..f361907b2c51dfe5707d5a2e37e3a42b8a2faa51 100644 Binary files a/tests/__pycache__/test_myunzip0.cpython-38.pyc and b/tests/__pycache__/test_myunzip0.cpython-38.pyc differ diff --git a/tests/resources/directory_expected.txt b/tests/resources/directory_expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..ecf0d7d9ea29237f255fa71250dc19495178c366 --- /dev/null +++ b/tests/resources/directory_expected.txt @@ -0,0 +1 @@ +Directory test file. diff --git a/tests/resources/directory_test.zip b/tests/resources/directory_test.zip new file mode 100644 index 0000000000000000000000000000000000000000..e9063bf806b82b6938bfa3fbffb67dd79c37d81f Binary files /dev/null and b/tests/resources/directory_test.zip differ diff --git a/tests/test_inflate.py b/tests/test_inflate.py new file mode 100644 index 0000000000000000000000000000000000000000..23829e2558eee0ec2c038732104d5aa075e371e1 --- /dev/null +++ b/tests/test_inflate.py @@ -0,0 +1,26 @@ +import unittest +import os +import filecmp +import shutil +import subprocess + + +EXEC_NAME = './inflate' + +class TestInflate(unittest.TestCase): + + def test_inflate(self): + subprocess.run([EXEC_NAME, 'tests/resources/compressed_expected.deflate']) + + # Check that we extracted the correct file + self.assertTrue(os.path.exists('tests/resources/compressed_expected')) + + # Check correct output (the DEFLATE stream should be decoded). + self.assertTrue(filecmp.cmp('tests/resources/compressed_expected', + 'tests/resources/compressed_expected.txt')) + + # Remove output + os.remove('tests/resources/compressed_expected') + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_myunzip.py b/tests/test_myunzip.py new file mode 100644 index 0000000000000000000000000000000000000000..1e65d82d3a5a54f13046999ee499c5033c138b3e --- /dev/null +++ b/tests/test_myunzip.py @@ -0,0 +1,59 @@ +import unittest +import os +import filecmp +import shutil +import subprocess + + +EXEC_NAME = './myunzip' + +class TestMyUnzip(unittest.TestCase): + + def test_uncompressed(self): + subprocess.run([EXEC_NAME, 'tests/resources/uncompressed.zip']) + + # Check that the correct file was extracted + self.assertTrue(os.path.exists('tests/resources/uncompressed.txt')) + + # Check correct output + self.assertTrue(filecmp.cmp('tests/resources/uncompressed.txt', + 'tests/resources/uncompressed_expected.txt')) + + # Remove output + os.remove('tests/resources/uncompressed.txt') + + def test_compressed(self): + subprocess.run([EXEC_NAME, 'tests/resources/compressed.zip']) + + # Check that we extracted the correct file + self.assertTrue(os.path.exists('tests/resources/compressed.txt')) + + # Check correct output (the DEFLATE stream should be decoded). + self.assertTrue(filecmp.cmp('tests/resources/compressed_expected.txt', + 'tests/resources/compressed.txt')) + + # Remove output + os.remove('tests/resources/compressed.txt') + + def test_make_directories(self): + """ + Suppose the zip file was created by invoking: + # zip example.zip directory/to/example_file + Then, suppose when we unzip example.zip, the relative directory + directory/to does not exist. This directory should be created + before unzipping. + """ + subprocess.run([EXEC_NAME, 'tests/resources/directory_test.zip']) + + # Check that we made the directories. + self.assertTrue(os.path.exists('tests/resources/a/b/c.txt')) + + # Check output + self.assertTrue(filecmp.cmp('tests/resources/directory_expected.txt', + 'tests/resources/a/b/c.txt')) + + # Remove output + shutil.rmtree('tests/resources/a') + +if __name__ == '__main__': + unittest.main() diff --git a/tests/test_myunzip0.py b/tests/test_myunzip0.py index 6b29fff5ef2fdaeebf4607d153b56ecd45e3a3a9..59c6114d6bfa4016a2ee455d6196bcb95ca01a74 100644 --- a/tests/test_myunzip0.py +++ b/tests/test_myunzip0.py @@ -1,12 +1,13 @@ import unittest import os import filecmp +import shutil import subprocess EXEC_NAME = './myunzip0' -class TestMyUnzip0(unittest.TestCase): +class TestMyUnzip(unittest.TestCase): def test_uncompressed(self): subprocess.run([EXEC_NAME, 'tests/resources/uncompressed.zip']) @@ -24,15 +25,35 @@ class TestMyUnzip0(unittest.TestCase): def test_compressed(self): subprocess.run([EXEC_NAME, 'tests/resources/compressed.zip']) - # Check that we extracted a DEFLATE stream + # Check that the correct DEFLATE stream was extracted. self.assertTrue(os.path.exists('tests/resources/compressed.txt.deflate')) - # Check correct output + # Check correct output. self.assertTrue(filecmp.cmp('tests/resources/compressed_expected.deflate', 'tests/resources/compressed.txt.deflate')) # Remove output os.remove('tests/resources/compressed.txt.deflate') + def test_make_directories(self): + """ + Suppose the zip file was created by invoking: + # zip example.zip directory/to/example_file + Then, suppose when we unzip example.zip, the relative directory + directory/to does not exist. This directory should be created + before unzipping. + """ + subprocess.run([EXEC_NAME, 'tests/resources/directory_test.zip']) + + # Check that we made the directories. + self.assertTrue(os.path.exists('tests/resources/a/b/c.txt')) + + # Check output + self.assertTrue(filecmp.cmp('tests/resources/directory_expected.txt', + 'tests/resources/a/b/c.txt')) + + # Remove output + shutil.rmtree('tests/resources/a') + if __name__ == '__main__': unittest.main()