Skip to content

Commit

Permalink
added tests for zipviewer
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenZcience committed Sep 14, 2023
1 parent 0976202 commit 2708539
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Binary file added cat_win/tests/resources/test.zip
Binary file not shown.
33 changes: 33 additions & 0 deletions cat_win/tests/test_zipviewer.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 2708539

Please sign in to comment.