|
7 | 7 | import datetime |
8 | 8 | from typing import Any |
9 | 9 |
|
10 | | -# Aliases for converting TOML compliance format [1] to BurntSushi format [2] |
11 | | -# [1] https://github.com/toml-lang/compliance/blob/db7c3211fda30ff9ddb10292f4aeda7e2e10abc4/docs/json-encoding.md # noqa: E501 |
12 | | -# [2] https://github.com/BurntSushi/toml-test/blob/4634fdf3a6ecd6aaea5f4cdcd98b2733c2694993/README.md # noqa: E501 |
13 | | -_aliases = { |
14 | | - "boolean": "bool", |
15 | | - "offset datetime": "datetime", |
16 | | - "local datetime": "datetime-local", |
17 | | - "local date": "date-local", |
18 | | - "local time": "time-local", |
19 | | -} |
20 | | - |
21 | 10 |
|
22 | 11 | def convert(obj): |
23 | 12 | if isinstance(obj, str): |
@@ -53,31 +42,25 @@ def convert(obj): |
53 | 42 | def normalize(obj: Any) -> Any: |
54 | 43 | """Normalize test objects. |
55 | 44 |
|
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 | | - """ |
| 45 | + This normalizes primitive values (e.g. floats).""" |
62 | 46 | if isinstance(obj, list): |
63 | 47 | return [normalize(item) for item in obj] |
64 | 48 | if isinstance(obj, dict): |
65 | 49 | if "type" in obj and "value" in obj: |
66 | 50 | type_ = obj["type"] |
67 | | - norm_type = _aliases.get(type_, type_) |
68 | 51 | value = obj["value"] |
69 | | - if norm_type == "float": |
| 52 | + if type_ == "float": |
70 | 53 | norm_value = _normalize_float_str(value) |
71 | | - elif norm_type in {"datetime", "datetime-local"}: |
| 54 | + elif type_ in {"datetime", "datetime-local"}: |
72 | 55 | norm_value = _normalize_datetime_str(value) |
73 | | - elif norm_type == "time-local": |
| 56 | + elif type_ == "time-local": |
74 | 57 | norm_value = _normalize_localtime_str(value) |
75 | 58 | else: |
76 | 59 | norm_value = value |
77 | 60 |
|
78 | | - if norm_type == "array": |
| 61 | + if type_ == "array": |
79 | 62 | return [normalize(item) for item in value] |
80 | | - return {"type": norm_type, "value": norm_value} |
| 63 | + return {"type": type_, "value": norm_value} |
81 | 64 | return {k: normalize(v) for k, v in obj.items()} |
82 | 65 | raise AssertionError("Burntsushi fixtures should be dicts/lists only") |
83 | 66 |
|
|
0 commit comments