import shutil import tempfile from pathlib import Path import pytest from prometheus.docker.user_defined_container import UserDefinedContainer @pytest.fixture def temp_project_dir(): # Create a temporary directory with some test files temp_dir = Path(tempfile.mkdtemp()) test_file = temp_dir / "test.txt" test_file.write_text("test content") yield temp_dir # Cleanup shutil.rmtree(temp_dir) @pytest.fixture def container(temp_project_dir): return UserDefinedContainer( temp_project_dir, "/app", "FROM python:3.9\nWORKDIR /app\nCOPY . /app/", None, ["pip install -r requirements.txt", "python setup.py build"], ["pytest tests/"], ) def test_initialization(container, temp_project_dir): """Test that the container is initialized correctly""" assert isinstance(container.tag_name, str) assert container.tag_name.startswith("prometheus_user_defined_container_") assert container.project_path != temp_project_dir assert (container.project_path / "test.txt").exists() def test_get_dockerfile_content(container): dockerfile_content = container.get_dockerfile_content() assert dockerfile_content # Check for key elements in the Dockerfile assert "FROM python:3.9" in dockerfile_content assert "WORKDIR /app" in dockerfile_content assert "COPY . /app/" in dockerfile_content