test_env.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import dataclasses
  2. from pathlib import Path
  3. import pytest
  4. import yaml
  5. from sweagent.environment.swe_env import EnvironmentArguments, SWEEnv
  6. # TEST_INSTANCE = {"repo": "test/test",
  7. # "instance_id": "test__test-4764",
  8. # "base_commit": "",
  9. # "patch": "",
  10. # "problem_statement": "",
  11. # "hints_text": "",
  12. # "created_at": "2023-04-16T14:24:42Z",
  13. # "version": "1.4",
  14. # "FAIL_TO_PASS": [
  15. # ],
  16. # "PASS_TO_PASS": [
  17. # ],
  18. # "environment_setup_commit": "test"
  19. # }
  20. @pytest.fixture
  21. def test_env_args():
  22. test_env_args = EnvironmentArguments(
  23. data_path="https://github.com/klieret/swe-agent-test-repo/issues/1",
  24. image_name="sweagent/swe-agent:latest",
  25. )
  26. return test_env_args
  27. @pytest.mark.slow
  28. def test_init_swe_env(test_env_args):
  29. env = SWEEnv(test_env_args)
  30. env.reset()
  31. @pytest.mark.slow
  32. def test_execute_setup_script(tmp_path, test_env_args):
  33. test_script = "echo 'hello world'"
  34. script_path = Path(tmp_path / "test_script.sh")
  35. script_path.write_text(test_script)
  36. test_env_args = dataclasses.replace(test_env_args, environment_setup=script_path)
  37. env = SWEEnv(test_env_args)
  38. env.reset()
  39. @pytest.mark.slow
  40. def test_execute_environment(tmp_path, test_env_args):
  41. test_env = {
  42. "python": "3.6",
  43. "packages": "pytest",
  44. "pip_packages": "tox",
  45. "install": "echo 'installing'",
  46. }
  47. env_config_path = Path(tmp_path / "env_config.yml")
  48. env_config_path.write_text(yaml.dump(test_env))
  49. test_env_args = dataclasses.replace(test_env_args, environment_setup=env_config_path)
  50. env = SWEEnv(test_env_args)
  51. env.reset()
  52. def test_open_pr(test_env_args):
  53. env = SWEEnv(test_env_args)
  54. env.reset()
  55. env.open_pr(_dry_run=True, trajectory=[])
  56. @pytest.mark.slow
  57. def test_interrupt_close(test_env_args):
  58. env = SWEEnv(test_env_args)
  59. env.interrupt()
  60. env.close()