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