/
nedeadinside
/
backup_Task1
Обзор
Документация
Войти
/
nedeadinside
/
backup_Task1
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
test.py
96 строк
3 KB
nedeadinside
Init backup commit
14 янв 2026, 12:04
14 янв 2026, 12:04
9eeacb8
Код
Авторство
О чём код?
import tempfile import subprocess from pathlib import Path from typing import Literal def run_command(cmd): result = subprocess.run(cmd, capture_output=True, text=True) if result.returncode != 0: return False print(result.stdout) return True def test_single_file(algorithm: Literal["zst", "bz2"]): print("=== Тест 1: Один файл ===") with tempfile.TemporaryDirectory() as tmpdir: tmpdir = Path(tmpdir) test_file = tmpdir / "test1.txt" test_file.write_text("42" * int(1e6)) compressed = tmpdir / f"test1.txt.{algorithm}" print("Compress") if not run_command( ["python", "main.py", "-c", str(test_file), str(compressed), "--verbose"] ): return extracted = tmpdir / "test1_extracted.txt" print("Decompress") if not run_command( ["python", "main.py", "-d", str(compressed), str(extracted), "--verbose"] ): return original_text = test_file.read_text() extracted_text = extracted.read_text() if original_text == extracted_text: print("Correct") else: print("Incorrect") def test_directory(algorithm: Literal["zst", "bz2"]): print("=== Тест 2: Папка с файлами ===") with tempfile.TemporaryDirectory() as tmpdir: tmpdir = Path(tmpdir) data_dir = tmpdir / "data" data_dir.mkdir() (data_dir / "test1.txt").write_text("42" * int(1e6)) (data_dir / "test2.txt").write_text("43" * int(1e6)) compressed = tmpdir / f"archive.tar.{algorithm}" print("Compress") if not run_command( ["python", "main.py", "-c", str(data_dir), str(compressed), "--verbose"] ): return extracted_dir = tmpdir / "extracted_data" print("Decompress") if not run_command( [ "python", "main.py", "-d", str(compressed), str(extracted_dir), "--verbose", ] ): return test1_original = (data_dir / "test1.txt").read_text() test2_original = (data_dir / "test2.txt").read_text() test1_extracted = (extracted_dir / "data" / "test1.txt").read_text() test2_extracted = (extracted_dir / "data" / "test2.txt").read_text() if test1_original == test1_extracted and test2_original == test2_extracted: print("Correct") else: print("Incorrect") if __name__ == "__main__": print("Zstd") test_single_file("zst") test_directory("zst") print("Bz2") test_single_file("bz2") test_directory("bz2")