4 import pycatfile
# Ensure pycatfile.py is accessible
7 class TestPyCatFile(unittest
.TestCase
):
9 """Prepare environment for testing."""
10 # Create example files to pack
11 self
.test_files
= ['test_file1.txt', 'test_file2.txt']
12 for file_name
in self
.test_files
:
13 with
open(file_name
, 'w') as f
:
14 f
.write(f
'Contents of {file_name}\n')
16 # Name of the packed file for testing
17 self
.packed_file
= 'test_packed.cat'
20 """Clean up after tests."""
21 # Remove created test files and packed file
22 for file_name
in self
.test_files
+ [self
.packed_file
]:
25 except FileNotFoundError
:
26 pass # File was not created or has been removed already
28 def test_pack_files(self
):
29 """Test packing files into a single file."""
30 # Assuming a function PackCatFile exists for packing files
31 with
open(self
.packed_file
, 'wb') as out_file
:
32 pycatfile
.PackCatFile(
33 self
.test_files
, out_file
, compression
="none", checksum
="none", verbose
=False)
35 # Check if the packed file has been created
36 self
.assertTrue(os
.path
.exists(self
.packed_file
))
38 def test_list_packed_files(self
):
39 """Test listing contents of a packed file."""
40 # First, pack files into a single file
41 with
open(self
.packed_file
, 'wb') as out_file
:
42 pycatfile
.PackCatFile(
43 self
.test_files
, out_file
, compression
="none", checksum
="none", verbose
=False)
45 # Assuming a function CatFileListFiles exists for listing contents
46 with
open(self
.packed_file
, 'rb') as in_file
:
47 contents
= pycatfile
.CatFileListFiles(in_file
, verbose
=False)
49 # Check if the contents match the packed files
50 expected_contents
= set(self
.test_files
)
51 self
.assertEqual(set(contents
), expected_contents
)
54 if __name__
== '__main__':