Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,33 @@ __pycache__/
.pytest_cache/
release_notes.txt
.venv/
venv/
venv/

# Testing
.coverage
htmlcov/
coverage.xml
.tox/
.nox/

# Claude Code
.claude/*

# Build artifacts
build/
dist/
*.egg-info/
.eggs/

# Virtual environments
env/
ENV/

# IDE files
*.swp
*.swo
*~

# OS generated files
Thumbs.db
ehthumbs.db
282 changes: 282 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

88 changes: 88 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
[tool.poetry]
name = "helm-charts"
version = "0.1.0"
description = "Helm charts project with Python testing infrastructure"
authors = ["Your Name <[email protected]>"]
readme = "README.md"
package-mode = false

[tool.poetry.dependencies]
python = "^3.8"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.0"
pytest-cov = "^4.1.0"
pytest-mock = "^3.11.1"

[tool.poetry.scripts]
test = "pytest:main"
tests = "pytest:main"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py", "*_test.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
addopts = [
"--strict-markers",
"--strict-config",
"--verbose",
"--cov=.",
"--cov-report=term-missing",
"--cov-report=html:htmlcov",
"--cov-report=xml:coverage.xml",
"--cov-fail-under=0",
]
markers = [
"unit: Unit tests",
"integration: Integration tests",
"slow: Slow tests",
]
filterwarnings = [
"error",
"ignore::UserWarning",
"ignore::DeprecationWarning",
]

[tool.coverage.run]
source = ["."]
omit = [
"*/tests/*",
"*/test_*",
"*/__pycache__/*",
"*/venv/*",
"*/.venv/*",
"*/env/*",
"*/build/*",
"*/dist/*",
"*/htmlcov/*",
"*/charts/*",
"*/manifests/*",
"*/scripts/*",
]

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"if self.debug:",
"if settings.DEBUG",
"raise AssertionError",
"raise NotImplementedError",
"if 0:",
"if __name__ == .__main__.:",
"class .*\\bProtocol\\):",
"@(abc\\.)?abstractmethod",
]
show_missing = true
precision = 2

[tool.coverage.html]
directory = "htmlcov"

[tool.coverage.xml]
output = "coverage.xml"
Empty file added tests/__init__.py
Empty file.
111 changes: 111 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
"""
Shared pytest fixtures and configuration for the test suite.
"""
import os
import tempfile
import shutil
from pathlib import Path
from typing import Generator, Dict, Any

import pytest


@pytest.fixture
def temp_dir() -> Generator[Path, None, None]:
"""Create a temporary directory for test files."""
temp_path = Path(tempfile.mkdtemp())
try:
yield temp_path
finally:
shutil.rmtree(temp_path, ignore_errors=True)


@pytest.fixture
def temp_file(temp_dir: Path) -> Path:
"""Create a temporary file in the temp directory."""
temp_file_path = temp_dir / "test_file.txt"
temp_file_path.write_text("test content")
return temp_file_path


@pytest.fixture
def mock_env_vars() -> Generator[Dict[str, str], None, None]:
"""Mock environment variables with cleanup."""
original_env = dict(os.environ)
test_env = {
"TEST_MODE": "true",
"DEBUG": "false",
"LOG_LEVEL": "INFO"
}
os.environ.update(test_env)
try:
yield test_env
finally:
os.environ.clear()
os.environ.update(original_env)


@pytest.fixture
def sample_config() -> Dict[str, Any]:
"""Sample configuration data for tests."""
return {
"version": "1.0.0",
"debug": False,
"database": {
"host": "localhost",
"port": 5432,
"name": "test_db"
},
"features": {
"feature_a": True,
"feature_b": False
}
}


@pytest.fixture
def sample_yaml_content() -> str:
"""Sample YAML content for testing."""
return """
apiVersion: v1
kind: ConfigMap
metadata:
name: test-config
namespace: default
data:
config.yaml: |
test: true
value: 42
"""


@pytest.fixture
def sample_json_content() -> str:
"""Sample JSON content for testing."""
return '{"test": true, "value": 42, "items": [1, 2, 3]}'


@pytest.fixture(autouse=True)
def reset_working_directory():
"""Ensure tests start with a clean working directory state."""
original_cwd = os.getcwd()
yield
os.chdir(original_cwd)


@pytest.fixture(scope="session")
def project_root() -> Path:
"""Get the project root directory."""
return Path(__file__).parent.parent


@pytest.fixture
def charts_dir(project_root: Path) -> Path:
"""Get the charts directory."""
return project_root / "charts"


@pytest.fixture
def manifests_dir(project_root: Path) -> Path:
"""Get the manifests directory."""
return project_root / "manifests"
Empty file added tests/integration/__init__.py
Empty file.
113 changes: 113 additions & 0 deletions tests/test_infrastructure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
"""
Validation tests to ensure the testing infrastructure is working correctly.
"""
import os
import sys
from pathlib import Path

import pytest


class TestInfrastructure:
"""Test suite to validate the testing infrastructure setup."""

def test_pytest_is_working(self):
"""Test that pytest is working correctly."""
assert True

def test_fixtures_are_available(self, temp_dir, sample_config):
"""Test that custom fixtures are working."""
assert temp_dir.exists()
assert temp_dir.is_dir()
assert isinstance(sample_config, dict)
assert "version" in sample_config

def test_temp_file_fixture(self, temp_file):
"""Test the temp_file fixture."""
assert temp_file.exists()
assert temp_file.read_text() == "test content"

def test_project_structure_fixtures(self, project_root, charts_dir, manifests_dir):
"""Test project structure fixtures."""
assert project_root.exists()
assert project_root.name in ["workspace", "helm-charts"]
assert charts_dir.exists() or not charts_dir.parent.exists()
assert manifests_dir.exists() or not manifests_dir.parent.exists()

@pytest.mark.unit
def test_unit_marker(self):
"""Test that unit marker works."""
assert True

@pytest.mark.integration
def test_integration_marker(self):
"""Test that integration marker works."""
assert True

@pytest.mark.slow
def test_slow_marker(self):
"""Test that slow marker works."""
assert True

def test_environment_variables(self, mock_env_vars):
"""Test environment variable mocking."""
assert os.getenv("TEST_MODE") == "true"
assert os.getenv("DEBUG") == "false"
assert "TEST_MODE" in mock_env_vars

def test_sample_data_fixtures(self, sample_yaml_content, sample_json_content):
"""Test sample data fixtures."""
assert "apiVersion: v1" in sample_yaml_content
assert "kind: ConfigMap" in sample_yaml_content
assert '"test": true' in sample_json_content
assert '"value": 42' in sample_json_content

def test_python_version(self):
"""Test that Python version is compatible."""
version_info = sys.version_info
assert version_info.major == 3
assert version_info.minor >= 8

def test_coverage_will_work(self):
"""Test that coverage reporting will work by creating some code to cover."""
def sample_function(x, y):
if x > y:
return x + y
else:
return x - y

result = sample_function(5, 3)
assert result == 8

result = sample_function(2, 5)
assert result == -3


class TestProjectStructure:
"""Test the project structure and files."""

def test_pyproject_toml_exists(self, project_root):
"""Test that pyproject.toml exists."""
pyproject_file = project_root / "pyproject.toml"
assert pyproject_file.exists()

def test_tests_directory_structure(self, project_root):
"""Test the tests directory structure."""
tests_dir = project_root / "tests"
assert tests_dir.exists()
assert (tests_dir / "__init__.py").exists()
assert (tests_dir / "conftest.py").exists()
assert (tests_dir / "unit").exists()
assert (tests_dir / "unit" / "__init__.py").exists()
assert (tests_dir / "integration").exists()
assert (tests_dir / "integration" / "__init__.py").exists()

def test_gitignore_has_testing_entries(self, project_root):
"""Test that .gitignore includes testing-related entries."""
gitignore_file = project_root / ".gitignore"
if gitignore_file.exists():
content = gitignore_file.read_text()
assert ".coverage" in content
assert "htmlcov/" in content
assert "coverage.xml" in content
assert ".claude/*" in content
Empty file added tests/unit/__init__.py
Empty file.