Normalize test objects. This normalizes primitive values (e.g. floats).
(obj: Any)
| 40 | |
| 41 | |
| 42 | def normalize(obj: Any) -> Any: |
| 43 | """Normalize test objects. |
| 44 | |
| 45 | This normalizes primitive values (e.g. floats).""" |
| 46 | if isinstance(obj, list): |
| 47 | return [normalize(item) for item in obj] |
| 48 | if isinstance(obj, dict): |
| 49 | if "type" in obj and "value" in obj: |
| 50 | type_ = obj["type"] |
| 51 | value = obj["value"] |
| 52 | if type_ == "float": |
| 53 | norm_value = _normalize_float_str(value) |
| 54 | elif type_ in {"datetime", "datetime-local"}: |
| 55 | norm_value = _normalize_datetime_str(value) |
| 56 | elif type_ == "time-local": |
| 57 | norm_value = _normalize_localtime_str(value) |
| 58 | else: |
| 59 | norm_value = value |
| 60 | |
| 61 | if type_ == "array": |
| 62 | return [normalize(item) for item in value] |
| 63 | return {"type": type_, "value": norm_value} |
| 64 | return {k: normalize(v) for k, v in obj.items()} |
| 65 | raise AssertionError("Burntsushi fixtures should be dicts/lists only") |
| 66 | |
| 67 | |
| 68 | def _normalize_datetime_str(dt_str: str) -> str: |
searching dependent graphs…