| 1 | import json |
| 2 | import os |
| 3 | from pathlib import Path |
| 4 | from utils import run_duct_command |
| 5 | from con_duct._constants import SUFFIXES |
| 6 | from con_duct.ls import LS_FIELD_CHOICES, _flatten_dict |
| 7 | |
| 8 | |
| 9 | def test_info_fields(temp_output_dir: str) -> None: |
| 10 | """ |
| 11 | Generate the list of fields users can request when viewing info files. |
| 12 | |
| 13 | Fails when schema changes-- commit the new version and bump schema version |
| 14 | """ |
| 15 | assert ( |
| 16 | run_duct_command( |
| 17 | ["echo", "hello", "world"], |
| 18 | sample_interval=4.0, |
| 19 | report_interval=60.0, |
| 20 | output_prefix=temp_output_dir, |
| 21 | ) |
| 22 | == 0 |
| 23 | ) |
| 24 | os.remove(Path(temp_output_dir, SUFFIXES["stdout"])) |
| 25 | os.remove(Path(temp_output_dir, SUFFIXES["stderr"])) |
| 26 | os.remove(Path(temp_output_dir, SUFFIXES["usage"])) |
| 27 | |
| 28 | info_file = Path(temp_output_dir, SUFFIXES["info"]) |
| 29 | actual_info_schema = _flatten_dict(json.loads(info_file.read_text())).keys() |
| 30 | os.remove(info_file) |
| 31 | |
| 32 | assert set(actual_info_schema) == set(LS_FIELD_CHOICES) |