Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Aug 19, 2024
1 parent 29f01e9 commit 64fba1e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
10 changes: 5 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,28 @@
sys.path.insert(1, str(package_dir))


@pytest.fixture()
@pytest.fixture
def test_data_path() -> Path:
p = _this_dir / "test_data"
assert p.is_dir()
return p


@pytest.fixture()
@pytest.fixture
def test_trajectories_path(test_data_path) -> Path:
p = test_data_path / "trajectories"
assert p.is_dir()
return p


@pytest.fixture()
@pytest.fixture
def test_data_sources_path(test_data_path) -> Path:
p = test_data_path / "data_sources"
assert p.is_dir()
return p


@pytest.fixture()
@pytest.fixture
def test_trajectory_path(test_trajectories_path) -> Path:
traj = (
test_trajectories_path
Expand All @@ -46,6 +46,6 @@ def test_trajectory_path(test_trajectories_path) -> Path:
return traj


@pytest.fixture()
@pytest.fixture
def test_trajectory(test_trajectory_path):
return json.loads(test_trajectory_path.read_text())
24 changes: 12 additions & 12 deletions tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@ def swe_env_context(env_args):
env.close()


@pytest.mark.slow()
@pytest.mark.slow
def test_init_swe_env(test_env_args):
with swe_env_context(test_env_args) as env:
env.reset()


@pytest.mark.slow()
@pytest.mark.slow
def test_init_swe_env_conservative_clone(test_env_args):
with mock.patch.dict("os.environ", {"SWE_AGENT_CLONE_METHOD": "full"}):
with swe_env_context(test_env_args) as env:
env.reset()


@pytest.mark.slow()
@pytest.mark.slow
def test_init_swe_env_non_persistent(test_env_args):
test_env_args = dataclasses.replace(test_env_args, container_name=None)
with swe_env_context(test_env_args) as env:
env.reset()


@pytest.mark.slow()
@pytest.mark.slow
def test_init_swe_env_cached_task_image(test_env_args):
test_env_args = dataclasses.replace(test_env_args, cache_task_images=True, container_name=None)
start = time.perf_counter()
Expand All @@ -105,7 +105,7 @@ def test_init_swe_env_cached_task_image(test_env_args):
client.images.remove(image.id)


@pytest.mark.slow()
@pytest.mark.slow
def test_execute_setup_script(tmp_path, test_env_args):
test_script = "echo 'hello world'"
script_path = Path(tmp_path / "test_script.sh")
Expand All @@ -115,7 +115,7 @@ def test_execute_setup_script(tmp_path, test_env_args):
env.reset()


@pytest.mark.slow()
@pytest.mark.slow
def test_execute_environment(tmp_path, test_env_args, capsys):
test_env = {
"python": "3.6",
Expand All @@ -134,7 +134,7 @@ def test_execute_environment(tmp_path, test_env_args, capsys):
assert "Cloned python conda environment" not in out


@pytest.mark.slow()
@pytest.mark.slow
def test_execute_environment_default(test_env_args):
env_config_paths = (CONFIG_DIR / "environment_setup").iterdir()
assert env_config_paths
Expand All @@ -151,7 +151,7 @@ def test_execute_environment_default(test_env_args):
env.reset()


@pytest.mark.slow()
@pytest.mark.slow
def test_execute_environment_clone_python(tmp_path, test_env_args, capsys):
"""This should clone the existing python 3.10 conda environment for speedup"""
test_env = {
Expand All @@ -171,7 +171,7 @@ def test_execute_environment_clone_python(tmp_path, test_env_args, capsys):
assert "Cloned python conda environment" in out


@pytest.mark.slow()
@pytest.mark.slow
def test_open_pr(test_env_args):
test_env_args = dataclasses.replace(
test_env_args,
Expand All @@ -183,21 +183,21 @@ def test_open_pr(test_env_args):
env.open_pr(_dry_run=True, trajectory=[])


@pytest.mark.slow()
@pytest.mark.slow
def test_interrupt_close(test_env_args):
with swe_env_context(test_env_args) as env:
env.reset()
env.interrupt()


@pytest.mark.slow()
@pytest.mark.slow
def test_communicate_old(test_env_args):
with mock.patch.dict("os.environ", {"SWE_AGENT_COMMUNICATE_METHOD": "processes"}):
with swe_env_context(test_env_args) as env:
env.reset()


@pytest.mark.slow()
@pytest.mark.slow
def test_env_with_hook(test_env_args):
with swe_env_context(test_env_args) as env:
env.add_hook(EnvHook())
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from sweagent.agent.models import GroqModel, ModelArguments, OpenAIModel, TogetherModel


@pytest.fixture()
@pytest.fixture
def openai_mock_client():
model = Mock()
response = Mock()
Expand All @@ -21,7 +21,7 @@ def openai_mock_client():
return model


@pytest.fixture()
@pytest.fixture
def mock_together_response():
return {
"choices": [{"text": "<human>Hello</human>"}],
Expand Down
12 changes: 6 additions & 6 deletions tests/test_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
from sweagent import CONFIG_DIR


@pytest.fixture()
@pytest.fixture
def swe_agent_test_repo_clone(tmp_path):
local_repo_path = tmp_path / "test-repo"
clone_cmd = ["git", "clone", "https://github.com/swe-agent/test-repo", local_repo_path]
subprocess.run(clone_cmd, check=True)
return local_repo_path


@pytest.fixture()
@pytest.fixture
def swe_agent_test_repo_traj(test_trajectories_path) -> Path:
p = (
test_trajectories_path
Expand All @@ -28,14 +28,14 @@ def swe_agent_test_repo_traj(test_trajectories_path) -> Path:
return p


@pytest.fixture()
@pytest.fixture
def swe_agent_test_repo_local_problem_stmt(swe_agent_test_repo_clone) -> Path:
problem_stmt = swe_agent_test_repo_clone / "problem_statements" / "1.md"
assert problem_stmt.is_file()
return problem_stmt


@pytest.mark.slow()
@pytest.mark.slow
@pytest.mark.parametrize("problem_statement_source", ["github", "local"])
def test_model_replay_github_repo(
tmpdir,
Expand Down Expand Up @@ -64,7 +64,7 @@ def test_model_replay_github_repo(
main(**vars(args), forward_args=remaining_args)


@pytest.mark.slow()
@pytest.mark.slow
def test_model_replay_from_json(test_trajectories_path, test_data_sources_path):
traj_path = (
test_trajectories_path
Expand Down Expand Up @@ -96,7 +96,7 @@ def test_run_cli_help():
subprocess.run(args, check=True)


@pytest.mark.slow()
@pytest.mark.slow
@pytest.mark.parametrize("problem_statement_source", ["github", "local"])
def test_model_replay_local_repo(swe_agent_test_repo_clone, swe_agent_test_repo_traj, problem_statement_source):
local_repo_path = swe_agent_test_repo_clone
Expand Down
22 changes: 11 additions & 11 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from sweagent.environment.swe_env import EnvironmentArguments, SWEEnv


@pytest.mark.slow()
@pytest.mark.slow
def test_run_cli_help():
args = [
"python",
Expand All @@ -27,7 +27,7 @@ def test_run_cli_help():
subprocess.run(args, check=True)


@pytest.fixture()
@pytest.fixture
def open_pr_hook_init_for_sop():
hook = OpenPRHook()
hook._token = os.environ.get("GITHUB_TOKEN", "")
Expand All @@ -37,7 +37,7 @@ def open_pr_hook_init_for_sop():
return hook


@pytest.fixture()
@pytest.fixture
def info_dict():
return {
"submission": "asdf",
Expand Down Expand Up @@ -100,7 +100,7 @@ def on_instance_start(self, *, index: int, instance: dict[str, Any]):
raise ValueError(msg)


@pytest.fixture()
@pytest.fixture
def test_script_args():
return ScriptArguments(
suffix="",
Expand Down Expand Up @@ -128,7 +128,7 @@ def test_script_args():
)


@pytest.mark.slow()
@pytest.mark.slow
def test_exception_raised(test_script_args: ScriptArguments):
assert test_script_args.raise_exceptions
main = Main(test_script_args)
Expand All @@ -137,7 +137,7 @@ def test_exception_raised(test_script_args: ScriptArguments):
main.main()


@pytest.mark.slow()
@pytest.mark.slow
class CreateFakeLogFile(MainHook):
"""Testing the skip functionality"""

Expand All @@ -153,21 +153,21 @@ def on_instance_start(self, *, index: int, instance: dict[str, Any]):
(self._traj_dir / f"{instance_id}.traj").write_text(json.dumps(dct))


@pytest.mark.slow()
@pytest.mark.slow
def test_existing_corrupted_args(test_script_args: ScriptArguments):
main = Main(test_script_args)
main.add_hook(CreateFakeLogFile())
main.main()


@pytest.mark.slow()
@pytest.mark.slow
def test_main_hook(test_script_args: ScriptArguments):
main = Main(test_script_args)
main.add_hook(MainHook())
main.main()


@pytest.mark.slow()
@pytest.mark.slow
def test_agent_with_hook(test_script_args: ScriptArguments):
main = Main(test_script_args)
main.agent.add_hook(AgentHook())
Expand All @@ -177,15 +177,15 @@ def test_agent_with_hook(test_script_args: ScriptArguments):
PERSISTENT_CONTAINER_NAME = "sweagent-test-persistent-container"


@pytest.fixture()
@pytest.fixture
def _cleanup_persistent_container():
yield
client = docker.from_env()
container = client.containers.get(PERSISTENT_CONTAINER_NAME)
container.remove(force=True)


@pytest.mark.slow()
@pytest.mark.slow
@pytest.mark.usefixtures("_cleanup_persistent_container")
def test_agent_persistent_container(test_script_args: ScriptArguments, capsys):
test_script_args = dataclasses.replace(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from sweagent.api.server import app, socketio


@pytest.fixture()
@pytest.fixture
def client():
with app.test_client() as client:
with app.app_context():
yield client


@pytest.fixture()
@pytest.fixture
def socket_client():
client = SocketIOTestClient(app, socketio)
yield client
Expand Down

0 comments on commit 64fba1e

Please sign in to comment.