Commit 3b264b70 authored by Mike Iovine's avatar Mike Iovine
Browse files

Add more tests

parent 7bd33d71
No related merge requests found
Pipeline #30640 failed with stage
in 0 seconds
Showing with 169 additions and 3 deletions
+169 -3
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()
File added
File added
No preview for this file type
Directory test file.
File added
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()
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()
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()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment