Debian Codegraph @

hitch/story/dirty-load.story

raw
1 Dirty load:
2 docs: restrictions/loading-dirty-yaml
3 based on: strictyaml
4 description: |
5 StrictYAML refuses to parse flow style and node anchors
6 by default, but since there have since been
7 [some requests](https://github.com/crdoconnor/strictyaml/issues/38)
8 to parse flow style, this now allowed with the "dirty_load" method.
9 If allow_flow_style is True, Map indentation is not checked for
10 consistency, as the indentation level is dependent on the map key length.
11 given:
12 setup: |
13 from strictyaml import Map, Int, MapPattern, Seq, Str, Any, dirty_load
14
15 schema = Map({"foo": Map({"a": Any(), "b": Any(), "c": Any()}), "y": MapPattern(Str(), Str()), "z": Seq(Str())})
16 variations:
17 Flow style mapping:
18 given:
19 yaml_snippet: |
20 foo: { a: 1, b: 2, c: 3 }
21 y: {}
22 z: []
23 steps:
24 - Run: |
25 assert dirty_load(yaml_snippet, schema, allow_flow_style=True) == {"foo": {"a": "1", "b": "2", "c": "3"}, "y": {}, "z": []}