Download task_024/tests/validate_mutated_input.py from Lego-X/UXInteract: direct link, hf CLI and curl.
- Browser
- Download file 1.9 kB
-
https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_024/tests/validate_mutated_input.py
- Command line
-
hf download hf://datasets/Lego-X/UXInteract/task_024/tests/validate_mutated_input.py
-
curl -L -o validate_mutated_input.py https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_024/tests/validate_mutated_input.py
1.9 kB
| """Rerun in an isolated copy with changed rows to reject fixture hardcoding.""" | |
| import csv | |
| import os | |
| import pathlib | |
| import shutil | |
| import subprocess | |
| import sys | |
| import tempfile | |
| source = pathlib.Path.cwd() | |
| tests = pathlib.Path(__file__).parent | |
| with tempfile.TemporaryDirectory(prefix='titanic-runtime-') as temporary: | |
| work = pathlib.Path(temporary) / 'candidate' | |
| shutil.copytree(source, work, ignore=shutil.ignore_patterns('logs', 'tests', '__pycache__', 'node_modules', '.git')) | |
| with (work / 'titanic.csv').open(newline='', encoding='utf-8-sig') as handle: | |
| rows = list(csv.DictReader(handle)) | |
| fields = list(rows[0]) | |
| for row in rows[:3]: | |
| row['survived'] = str(1 - int(row['survived'])) | |
| additional = {**rows[0], 'fare': '88.125', 'age': '41', 'sex': 'male', 'survived': '0', 'sibsp': '2', 'parch': '1'} | |
| rows.append(additional) | |
| rows.reverse() | |
| with (work / 'titanic.csv').open('w', newline='', encoding='utf-8') as handle: | |
| writer = csv.DictWriter(handle, fieldnames=fields) | |
| writer.writeheader() | |
| writer.writerows(rows) | |
| for output in ('report.html', 'titanic_clean.csv'): | |
| (work / output).unlink(missing_ok=True) | |
| progress = pathlib.Path(temporary) / 'progress.log' | |
| with progress.open('w', encoding='utf-8') as handle: | |
| subprocess.run([sys.executable, 'solve.py'], cwd=work, check=True, timeout=60, | |
| stdout=handle, stderr=subprocess.STDOUT) | |
| env = {**os.environ, 'TITANIC_PROGRESS_LOG': str(progress), 'TITANIC_SCREENSHOT': 'titanic-report-mutated'} | |
| for validator in ('validate_outputs.py', 'validate_enhancement.py'): | |
| subprocess.run([sys.executable, str(tests / validator)], cwd=work, env=env, check=True, timeout=20) | |
| subprocess.run(['node', str(tests / 'validate_aaav_dynamic.js')], cwd=work, env=env, check=True, timeout=30) | |
| print('mutated-input rerun passed') | |