Initial commit
This commit is contained in:
101
python/test_main.py
Normal file
101
python/test_main.py
Normal file
@@ -0,0 +1,101 @@
|
||||
"""
|
||||
Simple tests for gitreposetup Python implementation.
|
||||
"""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add parent directory to path for imports
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
|
||||
from main import (
|
||||
DeployType,
|
||||
License,
|
||||
decode_html_entities,
|
||||
get_config_path,
|
||||
get_license_content,
|
||||
load_config,
|
||||
)
|
||||
|
||||
|
||||
def test_config_path():
|
||||
"""Test config path generation."""
|
||||
config_path = get_config_path()
|
||||
assert ".config" in str(config_path)
|
||||
assert "GMS" in str(config_path)
|
||||
assert ".config.yaml" in str(config_path)
|
||||
print(f"✓ Config path: {config_path}")
|
||||
|
||||
|
||||
def test_load_config():
|
||||
"""Test config loading."""
|
||||
config = load_config()
|
||||
assert isinstance(config, dict)
|
||||
assert "owner" in config
|
||||
assert "license" in config
|
||||
assert config["license"] == "MIT"
|
||||
assert config["develop_branch"] == "dev"
|
||||
print("✓ Config loaded successfully")
|
||||
|
||||
|
||||
def test_license_enum():
|
||||
"""Test license enumeration."""
|
||||
assert License.MIT.value == "MIT.txt"
|
||||
assert License.GPLv3.value == "GPL-3.0.txt"
|
||||
assert License.AGPLv3.value == "AGPL-3.0.txt"
|
||||
assert License.Unlicense.value == "Unlicense.txt"
|
||||
print("✓ License enum correct")
|
||||
|
||||
|
||||
def test_deploy_type_enum():
|
||||
"""Test deploy type enumeration."""
|
||||
assert DeployType.DOCKER.value == "docker"
|
||||
assert DeployType.PYPI.value == "pypi"
|
||||
assert DeployType.CARGO.value == "cargo"
|
||||
assert DeployType.GO.value == "go"
|
||||
print("✓ DeployType enum correct")
|
||||
|
||||
|
||||
def test_decode_html_entities():
|
||||
"""Test HTML entity decoding."""
|
||||
text = "<test> & "quoted""
|
||||
decoded = decode_html_entities(text)
|
||||
assert decoded == '<test> & "quoted"'
|
||||
print("✓ HTML entities decoded")
|
||||
|
||||
|
||||
def test_license_content():
|
||||
"""Test license content generation."""
|
||||
license_content = get_license_content(License.MIT, "TestOrg")
|
||||
assert "MIT License" in license_content
|
||||
assert "2025" in license_content # Current year
|
||||
assert "TestOrg" in license_content or "Copyright" in license_content
|
||||
assert "{year}" not in license_content
|
||||
assert "{fullname}" not in license_content
|
||||
print("✓ License content generated with substitutions")
|
||||
|
||||
|
||||
def run_all_tests():
|
||||
"""Run all tests."""
|
||||
print("\n=== Running Python Implementation Tests ===\n")
|
||||
|
||||
try:
|
||||
test_config_path()
|
||||
test_load_config()
|
||||
test_license_enum()
|
||||
test_deploy_type_enum()
|
||||
test_decode_html_entities()
|
||||
test_license_content()
|
||||
|
||||
print("\n=== All tests passed! ===\n")
|
||||
return 0
|
||||
except AssertionError as e:
|
||||
print(f"\n✗ Test failed: {e}\n")
|
||||
return 1
|
||||
except Exception as e:
|
||||
print(f"\n✗ Error: {e}\n")
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(run_all_tests())
|
||||
Reference in New Issue
Block a user