diff --git a/cat_win/tests/resources/test.zip b/cat_win/tests/resources/test.zip new file mode 100644 index 00000000..c3226db6 Binary files /dev/null and b/cat_win/tests/resources/test.zip differ diff --git a/cat_win/tests/test_zipviewer.py b/cat_win/tests/test_zipviewer.py new file mode 100644 index 00000000..0c50b3c7 --- /dev/null +++ b/cat_win/tests/test_zipviewer.py @@ -0,0 +1,33 @@ +from unittest.mock import patch +from unittest import TestCase +import os + +from cat_win.tests.mocks.std import StdOutMock +from cat_win.util.zipviewer import display_zip +# import sys +# sys.path.append('../cat_win') +test_file_dir = os.path.join(os.path.dirname(__file__), 'texts') +test_file_path = os.path.join(test_file_dir, 'test.txt') +test_zip_file_dir = os.path.join(os.path.dirname(__file__), 'resources') +test_zip_file_path = os.path.join(test_zip_file_dir, 'test.zip') + + +class TestZipviewer(TestCase): + maxDiff = None + + def test_display_zip_bad_file(self): + self.assertEqual(display_zip('', lambda x: x), False) + self.assertEqual(display_zip(test_file_path, lambda x: x), False) + + def test_display_zip(self): + self.assertEqual(display_zip(test_zip_file_path, lambda x: x), True) + + def test_display_zip_output(self): + expected_output = f"The file '{test_zip_file_path}' has been detected to be a zip-file. " + expected_output += 'The archive contains the following files:\n' + expected_output += 'FileName FileSize CompressedFileSize\n' + expected_output += 'test.txt 189 145\n' + expected_output += 'test_empty.txt 0 0\n' + with patch('cat_win.cat.sys.stdout', new=StdOutMock()) as fake_out: + display_zip(test_zip_file_path, lambda x: x) + self.assertEqual(fake_out.getvalue(), expected_output)