py500 / README.md
lbaf23's picture
Update README.md
edb811a verified
---
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)