-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_basic2.py
More file actions
38 lines (32 loc) · 1.37 KB
/
test_basic2.py
File metadata and controls
38 lines (32 loc) · 1.37 KB
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
from ninjazipy import BitFileExtractor, BitFileCompressor
from pathlib import Path
def test_password_protected_archive():
print("Starting password protected archive test...")
temp_path = Path(r"C:\Users\moham\Desktop\NinjaZipPyDebug")
temp_path.mkdir(parents=True, exist_ok=True)
secret = "mysecret"
file1 = temp_path / "file1.txt"
file1.write_text("Secure content")
archive_path = temp_path / "secure.7z"
compressor = BitFileCompressor()
compressor.set_password(secret)
compressor.compress_files([str(file1)], str(archive_path))
print(f"Archive created: {archive_path}")
extract_dir = temp_path / "extracted_protected"
extractor = BitFileExtractor()
extractor.set_password(secret)
extractor.extract(str(archive_path), str(extract_dir))
print(f"Extracted to: {extract_dir}")
extracted_file = extract_dir / "file1.txt"
assert extracted_file.exists(), "Extracted file does not exist"
content = extracted_file.read_text()
assert content == "Secure content", "Extracted content mismatch"
print("✅ Password protected archive test passed")
if __name__ == "__main__":
try:
test_password_protected_archive()
print("🎉 All tests passed!")
except AssertionError as e:
print(f"❌ Test assertion failed: {e}")
except Exception as e:
print(f"❌ Test failed with exception: {e}")