Skip to content

Commit abd42d9

Browse files
committed
Test replay of batch mode
1 parent 39388f0 commit abd42d9

File tree

8 files changed

+844
-0
lines changed

8 files changed

+844
-0
lines changed

sweagent/environment/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,9 @@ def instance_from_dict(instances):
519519
return ib.build()
520520

521521
def postproc_instance_list(instances):
522+
if isinstance(instances, dict):
523+
msg = "Expected a list of instances, got a dictionary."
524+
raise ValueError(msg)
522525
return [instance_from_dict(x) for x in instances]
523526

524527

tests/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ def test_trajectories_path(test_data_path) -> Path:
2626
return p
2727

2828

29+
@fixture
30+
def test_data_sources_path(test_data_path) -> Path:
31+
p = test_data_path / "data_sources"
32+
assert p.is_dir()
33+
return p
34+
35+
2936
@fixture
3037
def test_trajectory(test_trajectories_path):
3138
traj_dir = test_trajectories_path / "gpt4__klieret__swe-agent-test-repo__default_from_url__t-0.00__p-0.95__c-3.00__install-1" / "klieret__swe-agent-test-repo-i1.traj"

tests/test_data/data_sources/swe-bench-dev-easy_first_only.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"model_name_or_path": "gpt4__swe-bench-dev-easy_first_only__default__t-0.00__p-0.95__c-3.00__install-1", "instance_id": "pydicom__pydicom-1458", "model_patch": "\ndiff --git a/pydicom/pixel_data_handlers/numpy_handler.py b/pydicom/pixel_data_handlers/numpy_handler.py\nindex 8e8d319ae..6a1221b72 100644\n--- a/pydicom/pixel_data_handlers/numpy_handler.py\n+++ b/pydicom/pixel_data_handlers/numpy_handler.py\n@@ -285,9 +285,10 @@ def get_pixeldata(ds: \"Dataset\", read_only: bool = False) -> \"np.ndarray\":\n )\n \n required_elements = [\n- 'BitsAllocated', 'Rows', 'Columns', 'PixelRepresentation',\n- 'SamplesPerPixel', 'PhotometricInterpretation'\n+ 'BitsAllocated', 'Rows', 'Columns', 'SamplesPerPixel', 'PhotometricInterpretation'\n ]\n+ if 'PixelData' in ds:\n+ required_elements.append('PixelRepresentation')\n missing = [elem for elem in required_elements if elem not in ds]\n if missing:\n raise AttributeError(\n"}

tests/test_data/trajectories/gpt4__swe-bench-dev-easy_first_only__default__t-0.00__p-0.95__c-3.00__install-1/args.yaml

Lines changed: 536 additions & 0 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
diff --git a/pydicom/pixel_data_handlers/numpy_handler.py b/pydicom/pixel_data_handlers/numpy_handler.py
3+
index 8e8d319ae..6a1221b72 100644
4+
--- a/pydicom/pixel_data_handlers/numpy_handler.py
5+
+++ b/pydicom/pixel_data_handlers/numpy_handler.py
6+
@@ -285,9 +285,10 @@ def get_pixeldata(ds: "Dataset", read_only: bool = False) -> "np.ndarray":
7+
)
8+
9+
required_elements = [
10+
- 'BitsAllocated', 'Rows', 'Columns', 'PixelRepresentation',
11+
- 'SamplesPerPixel', 'PhotometricInterpretation'
12+
+ 'BitsAllocated', 'Rows', 'Columns', 'SamplesPerPixel', 'PhotometricInterpretation'
13+
]
14+
+ if 'PixelData' in ds:
15+
+ required_elements.append('PixelRepresentation')
16+
missing = [elem for elem in required_elements if elem not in ds]
17+
if missing:
18+
raise AttributeError(

tests/test_data/trajectories/gpt4__swe-bench-dev-easy_first_only__default__t-0.00__p-0.95__c-3.00__install-1/pydicom__pydicom-1458.traj

Lines changed: 257 additions & 0 deletions
Large diffs are not rendered by default.

tests/test_replay.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,27 @@ def test_model_replay_github_repo(swe_agent_test_repo_traj, problem_statement_so
4848
main(**vars(args), forward_args=remaining_args)
4949

5050

51+
@pytest.mark.slow
52+
def test_model_replay_from_json(test_trajectories_path, test_data_sources_path):
53+
traj_path = test_trajectories_path / "gpt4__swe-bench-dev-easy_first_only__default__t-0.00__p-0.95__c-3.00__install-1" / "pydicom__pydicom-1458.traj"
54+
assert traj_path.is_file()
55+
data_path = test_data_sources_path / "swe-bench-dev-easy_first_only.json"
56+
assert data_path.is_file()
57+
args = [
58+
"--traj_path",
59+
str(traj_path),
60+
"--data_path",
61+
str(data_path),
62+
"--config_file",
63+
"config/default.yaml",
64+
"--raise_exceptions",
65+
]
66+
args, remaining_args = get_args(args)
67+
main(**vars(args), forward_args=remaining_args)
68+
69+
70+
71+
5172
def test_run_cli_help():
5273
args = [
5374
"python",

0 commit comments

Comments
 (0)