Add version argument and update tests

Introduced a '--version' argument in the CLI to display version information. Updated test cases to reflect changes in compression level validation and error codes. Adjusted special character handling in test_core.py and added integration test markers in pyproject.toml.
This commit is contained in:
xixu-me committed 2025-06-01 18:37:27 +08:00
1 parent 97243e6a27
commit 22dc90259b
4 files changed
+14 -13

No files matched your search

+1
View File
@@ -57,6 +57,7 @@ python_files = ["test_*.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
addopts = "--cov=tzst --cov-report=term-missing --cov-report=html"
markers = ["integration: marks tests as integration tests"]
[tool.ruff]
line-length = 88
+5 -2
View File
@@ -621,6 +621,11 @@ Documentation:
epilog=epilog,
formatter_class=argparse.RawDescriptionHelpFormatter,
add_help=True,
) # Add version argument
parser.add_argument(
"--version",
action="version",
version=f"tzst {__version__} : Copyright (c) 2025 Xi Xu",
)
# Add global arguments
@@ -820,8 +825,6 @@ def _handle_parsing_errors(e: SystemExit, argv: list[str] | None) -> int:
return 0
elif e.code == 2 and argv:
# Check for validation errors we want to convert to exit code 1
if _validate_compression_level_in_argv(argv):
return 1
if _validate_filter_in_argv(argv):
return 1
+7 -10
View File
@@ -336,9 +336,7 @@ class TestCLICompressionLevels:
archive_path = temp_dir / f"level_{level}.tzst"
result = main(["a", str(archive_path), *file_paths, "-l", str(level)])
assert result == 0
assert archive_path.exists()
def test_invalid_compression_levels(self, sample_files, temp_dir):
assert archive_path.exists() def test_invalid_compression_levels(self, sample_files, temp_dir):
"""Test invalid compression levels return proper error codes."""
file_paths = [str(f) for f in sample_files if f.is_file()]
archive_path = temp_dir / "invalid.tzst"
@@ -348,7 +346,7 @@ class TestCLICompressionLevels:
result = main(
["a", str(archive_path), *file_paths, "-l", str(invalid_level)]
)
assert result == 1 # Should fail with error code 1
assert result == 2 # Should fail with error code 2
def test_compression_level_boundary_values(self, sample_files, temp_dir):
"""Test boundary compression level values."""
@@ -699,8 +697,8 @@ class TestCLIEdgeCases:
# Test extreme high compression (should be clamped to 22)
archive_path = temp_dir / "extreme.tzst"
result = main(["a", str(archive_path), *file_paths, "-l", "50"])
# Should succeed (clamped to valid range) or fail with error
assert result in [0, 1]
# Should fail with validation error code 2
assert result == 2
class TestCLIPerformance:
@@ -1077,11 +1075,10 @@ class TestCompressionLevelValidation:
for value in invalid_values:
result = main(["a", str(archive_path), str(test_file), "-l", value])
assert result == 2, (
f"Non-numeric compression level '{value}' should return exit code 2"
assert result == 2, ( f"Non-numeric compression level '{value}' should return exit code 2"
)
def test_compression_level_clamping(self, temp_dir):
def test_compression_level_extremes(self, temp_dir):
"""Test compression level validation with extreme values."""
test_file = temp_dir / "test.txt"
test_file.write_text("Test content")
@@ -1091,7 +1088,7 @@ class TestCompressionLevelValidation:
result = main(["a", str(archive_path), str(test_file), "-l", "50"])
assert result == 2, "Compression level 50 should return exit code 2"
def test_extreme_compression_levels(self, temp_dir):
def test_compression_level_boundary_validation(self, temp_dir):
"""Test extreme compression level values."""
test_file = temp_dir / "test.txt"
test_file.write_text("Test content")
+1 -1
View File
@@ -725,7 +725,7 @@ class TestSpecialFileTypes:
def test_files_with_special_characters(self, temp_dir):
"""Test files with special characters in names."""
special_chars_file = temp_dir / "file!@#$%^&()_+{}[]|;':\",./<>?.txt"
special_chars_file = temp_dir / "file!@#$%^&()_+{}[]-',.txt"
special_chars_file.write_text("Special characters content")
archive_path = temp_dir / "special_chars.tzst"