Normalize test objects. This normalizes primitive values (e.g. floats), and also converts from TOML compliance format [1] to BurntSushi format [2]. [1] https://github.com/toml-lang/compliance/blob/db7c3211fda30ff9ddb10292f4aeda7e2e10abc4/docs/json-encoding.md # noqa: E501 [2] http
(obj: Any)
| 51 | |
| 52 | |
| 53 | def normalize(obj: Any) -> Any: |
| 54 | """Normalize test objects. |
| 55 | |
| 56 | This normalizes primitive values (e.g. floats), and also converts from |
| 57 | TOML compliance format [1] to BurntSushi format [2]. |
| 58 | |
| 59 | [1] https://github.com/toml-lang/compliance/blob/db7c3211fda30ff9ddb10292f4aeda7e2e10abc4/docs/json-encoding.md # noqa: E501 |
| 60 | [2] https://github.com/BurntSushi/toml-test/blob/4634fdf3a6ecd6aaea5f4cdcd98b2733c2694993/README.md # noqa: E501 |
| 61 | """ |
| 62 | if isinstance(obj, list): |
| 63 | return [normalize(item) for item in obj] |
| 64 | if isinstance(obj, dict): |
| 65 | if "type" in obj and "value" in obj: |
| 66 | type_ = obj["type"] |
| 67 | norm_type = _aliases.get(type_, type_) |
| 68 | value = obj["value"] |
| 69 | if norm_type == "float": |
| 70 | norm_value = _normalize_float_str(value) |
| 71 | elif norm_type in {"datetime", "datetime-local"}: |
| 72 | norm_value = _normalize_datetime_str(value) |
| 73 | elif norm_type == "time-local": |
| 74 | norm_value = _normalize_localtime_str(value) |
| 75 | else: |
| 76 | norm_value = value |
| 77 | |
| 78 | if norm_type == "array": |
| 79 | return [normalize(item) for item in value] |
| 80 | return {"type": norm_type, "value": norm_value} |
| 81 | return {k: normalize(v) for k, v in obj.items()} |
| 82 | raise AssertionError("Burntsushi fixtures should be dicts/lists only") |
| 83 | |
| 84 | |
| 85 | def _normalize_datetime_str(dt_str: str) -> str: |