-
Notifications
You must be signed in to change notification settings - Fork 1
/
pycatfile_test.py
executable file
·55 lines (44 loc) · 2.03 KB
/
pycatfile_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import unittest
import os
from io import BytesIO
import pycatfile # Ensure pycatfile.py is accessible
class TestPyCatFile(unittest.TestCase):
def setUp(self):
"""Prepare environment for testing."""
# Create example files to pack
self.test_files = ['test_file1.txt', 'test_file2.txt']
for file_name in self.test_files:
with open(file_name, 'w') as f:
f.write(f'Contents of {file_name}\n')
# Name of the packed file for testing
self.packed_file = 'test_packed.cat'
def tearDown(self):
"""Clean up after tests."""
# Remove created test files and packed file
for file_name in self.test_files + [self.packed_file]:
try:
os.remove(file_name)
except FileNotFoundError:
pass # File was not created or has been removed already
def test_pack_files(self):
"""Test packing files into a single file."""
# Assuming a function PackCatFile exists for packing files
with open(self.packed_file, 'wb') as out_file:
pycatfile.PackCatFile(
self.test_files, out_file, compression="none", checksum="none", verbose=False)
# Check if the packed file has been created
self.assertTrue(os.path.exists(self.packed_file))
def test_list_packed_files(self):
"""Test listing contents of a packed file."""
# First, pack files into a single file
with open(self.packed_file, 'wb') as out_file:
pycatfile.PackCatFile(
self.test_files, out_file, compression="none", checksum="none", verbose=False)
# Assuming a function CatFileListFiles exists for listing contents
with open(self.packed_file, 'rb') as in_file:
contents = pycatfile.CatFileListFiles(in_file, verbose=False)
# Check if the contents match the packed files
expected_contents = set(self.test_files)
self.assertEqual(set(contents), expected_contents)
if __name__ == '__main__':
unittest.main()