|
""" |
|
Tests for successful installation of the package. |
|
""" |
|
import shutil |
|
import subprocess |
|
import sys |
|
import venv |
|
|
|
from pathlib import Path |
|
|
|
import pytest |
|
|
|
|
|
VENV_DIR = "./venv_test_installation" |
|
|
|
|
|
@pytest.fixture(scope="module", autouse=True) |
|
def venv_setup_teardown(): |
|
""" |
|
A pytest fixture that sets up and tears down a virtual environment for testing. |
|
This fixture is automatically used for all tests in this module. |
|
|
|
The fixture: |
|
- Creates a virtual environment. |
|
- Installs Poetry in the virtual environment. |
|
- Installs dependencies using Poetry. |
|
- Cleans up by removing the virtual environment after tests are completed. |
|
""" |
|
try: |
|
|
|
venv.create(VENV_DIR, with_pip=True, clear=True) |
|
|
|
|
|
subprocess.run( |
|
[f"{VENV_DIR}/bin/python", "-m", "pip", "install", "poetry"], check=True |
|
) |
|
|
|
|
|
subprocess.run([f"{VENV_DIR}/bin/poetry", "install"], cwd=".", check=True) |
|
|
|
|
|
yield |
|
except Exception as e: |
|
|
|
pytest.skip(f"Could not create venv or install dependencies: {str(e)}") |
|
finally: |
|
|
|
shutil.rmtree(VENV_DIR) |
|
|
|
|
|
def test_installation(): |
|
""" |
|
Test to ensure that the package can be installed using Poetry in the virtual environment. |
|
""" |
|
|
|
poetry_executable = ( |
|
f"{VENV_DIR}/bin/poetry" |
|
if sys.platform != "win32" |
|
else f"{VENV_DIR}/Scripts/poetry.exe" |
|
) |
|
|
|
|
|
result = subprocess.run([poetry_executable, "install"], capture_output=True) |
|
|
|
|
|
assert ( |
|
result.returncode == 0 |
|
), f"Install via poetry failed: {result.stderr.decode()}" |
|
|
|
|
|
def test_cli_execution(): |
|
""" |
|
Test to verify that the command-line interface (CLI) of the package works as expected. |
|
This test assumes that the 'gpt-engineer' command is available and operational after installation. |
|
""" |
|
|
|
result = subprocess.run( |
|
args=["gpt-engineer", "--help"], capture_output=True, text=True |
|
) |
|
|
|
|
|
assert ( |
|
result.returncode == 0 |
|
), f"gpt-engineer command failed with message: {result.stderr}" |
|
|
|
|
|
def test_installed_main_execution(tmp_path): |
|
tmp_path = Path(tmp_path) |
|
p = tmp_path / "projects/example" |
|
p.mkdir(parents=True) |
|
(p / "prompt").write_text("make a program that prints the outcome of 4+4") |
|
proc = subprocess.Popen( |
|
["gpte_test_application", str(p)], |
|
stdin=subprocess.PIPE, |
|
stdout=subprocess.PIPE, |
|
text=True, |
|
cwd=tmp_path, |
|
) |
|
|
|
inputs = "Y\nn" |
|
output, _ = proc.communicate(inputs) |
|
|
|
assert "8" in output |
|
|