File size: 3,540 Bytes
f31a389
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
edb811a
 
 
f31a389
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2dd1efa
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
---
license: mit
---

# py500

## Human-level test oracle generation in real-world Python repositories.

Here is an example:

```json
{
    "index": 0,
    "repo_name": "black",
    "github": "https://github.com/psf/black.git",
    "version": "25.9.0",
    "install_cmd": "python -m venv .venv\nsource .venv/bin/activate\npip install -r test_requirements.txt\npip install -e .\npip install ipdb",
    "activate_cmd": "source .venv/bin/activate\nhash -r",
    "test_function_name": "test_pep_572_version_detection",
    "test_class_name": "BlackTestCase",
    "original_test_prefix": "    def test_pep_572_version_detection(self) -> None:\n        source, _ = read_data(\"cases\", \"pep_572\")\n        root = black.lib2to3_parse(source)\n        features = black.get_features_used(root)\n        self.assertIn(black.Feature.ASSIGNMENT_EXPRESSIONS, features)\n        versions = black.detect_target_versions(root)\n        self.assertIn(black.TargetVersion.PY38, versions)",
    "test_prefix": "    def test_pep_572_version_detection(self) -> None:\n        source, _ = read_data(\"cases\", \"pep_572\")\n        root = black.lib2to3_parse(source)\n        features = black.get_features_used(root)\n        self.assertIn(black.Feature.ASSIGNMENT_EXPRESSIONS, features)\n        versions = black.detect_target_versions(root)\n        <AssertPlaceHolder>",
    "test_prefix_file_path": "tests/test_black.py",
    "test_prefix_start_lineno": 243,
    "test_prefix_end_lineno": 249,
    "test_target": "tests/test_black.py::BlackTestCase::test_pep_572_version_detection",
    "ground_truth_oracle": "self.assertIn(black.TargetVersion.PY38, versions)",
    "ground_truth_oracle_lineno": 249,
    "test_setup": "",
    "test_setup_file_path": "",
    "test_setup_start_lineno": -1,
    "test_setup_end_lineno": -1,
    "focal_method": "def detect_target_versions(\n    node: Node, *, future_imports: Optional[set[str]] = None\n) -> set[TargetVersion]:\n    \"\"\"Detect the version to target based on the nodes used.\"\"\"\n    features = get_features_used(node, future_imports=future_imports)\n    return {\n        version for version in TargetVersion if features <= VERSION_TO_FEATURES[version]\n    }",
    "focal_method_file_path": "src/black/__init__.py",
    "focal_method_start_lineno": 1510,
    "focal_method_end_lineno": 1517
}
```


- Focal method
```
def detect_target_versions(
    node: Node, *, future_imports: Optional[set[str]] = None
) -> set[TargetVersion]:
    """Detect the version to target based on the nodes used."""
    features = get_features_used(node, future_imports=future_imports)
    return {
        version for version in TargetVersion if features <= VERSION_TO_FEATURES[version]
    }
```

- Test setup

```

```

- Test prefix

```
    def test_pep_572_version_detection(self) -> None:
        source, _ = read_data("cases", "pep_572")
        root = black.lib2to3_parse(source)
        features = black.get_features_used(root)
        self.assertIn(black.Feature.ASSIGNMENT_EXPRESSIONS, features)
        versions = black.detect_target_versions(root)
        <AssertPlaceHolder>
```

- Ground truth oracle
```
self.assertIn(black.TargetVersion.PY38, versions)
```

### Install

> In the script below, the `test.jsonl` file in the dataset needs to be renamed to `py500.jsonl`.


Install venv

`install.py`

### Run

Run the ground truth oracle

`run.py`

### Evaluate

Evaluate whether an oracle is same with the ground truth

`evaluate.py`


### GitHub

[AssertAgents](https://github.com/lbaf23/assertagents)