Debian Codegraph @

hitch/story/map.toml

raw
1 ["Mappings with defined keys (Map)"]
2 docs = "compound/mapping"
3 "based on" = "strictyaml"
4 description = "Mappings of one value to another are represented by : in YAML\nand parsed as python dicts.\n\nUsing StrictYAML's 'Map' you can validate that a mapping\ncontains the right keys and the right *type* of values.\n\nNote: for mappings where you don't know the exact names of\nthe keys in advance but you do know the type, use MapPattern.\n"
5
6 ["Mappings with defined keys (Map)".given]
7 setup = "from collections import OrderedDict\nfrom strictyaml import Map, Int, load, as_document\nfrom collections import OrderedDict\nfrom ensure import Ensure\n\nschema = Map({\"a\": Int(), \"b\": Int(), \"c\": Int()})\n\nschema_2 = Map({u\"â\": Int(), \"b\": Int(), \"c\": Int()})\n"
8 yaml_snippet = "â: 1\nb: 2\nc: 3\n"
9
10 ["Mappings with defined keys (Map)".variations]
11
12 ["Mappings with defined keys (Map)".variations."one key mapping"]
13
14 ["Mappings with defined keys (Map)".variations."one key mapping".given]
15 yaml_snippet = "x: 1"
16
17 [["Mappings with defined keys (Map)".variations."one key mapping".steps]]
18 Run = "Ensure(load(yaml_snippet, Map({\"x\": Int()})).data).equals(OrderedDict([('x', 1)]))\n"
19
20 ["Mappings with defined keys (Map)".variations."key value"]
21
22 [["Mappings with defined keys (Map)".variations."key value".steps]]
23 Run = "Ensure(load(yaml_snippet, schema_2)[u'â']).equals(1)\n"
24
25 ["Mappings with defined keys (Map)".variations."get item key not found"]
26
27 [["Mappings with defined keys (Map)".variations."get item key not found".steps]]
28
29 ["Mappings with defined keys (Map)".variations."get item key not found".steps.Run]
30 code = "load(yaml_snippet, schema_2)['keynotfound']"
31
32 ["Mappings with defined keys (Map)".variations."get item key not found".steps.Run.raises]
33 message = "'keynotfound'"
34
35 ["Mappings with defined keys (Map)".variations."cannot use .text"]
36
37 [["Mappings with defined keys (Map)".variations."cannot use .text".steps]]
38
39 ["Mappings with defined keys (Map)".variations."cannot use .text".steps.Run]
40 code = "load(yaml_snippet, schema_2).text"
41
42 ["Mappings with defined keys (Map)".variations."cannot use .text".steps.Run.raises]
43
44 ["Mappings with defined keys (Map)".variations."cannot use .text".steps.Run.raises.type]
45 "in python 3" = "builtins.TypeError"
46 "in python 2" = "exceptions.TypeError"
47
48 ["Mappings with defined keys (Map)".variations."cannot use .text".steps.Run.raises.message]
49 "in python 3" = "YAML(OrderedDict([('â', 1), ('b', 2), ('c', 3)])) is a mapping, has no text value."
50 "in python 2" = "YAML(OrderedDict([(u'\\xe2', 1), ('b', 2), ('c', 3)])) is a mapping, has no text value."
51
52 ["Mappings with defined keys (Map)".variations."parse snippet where key is not found in schema"]
53
54 ["Mappings with defined keys (Map)".variations."parse snippet where key is not found in schema".given]
55 yaml_snippet = "a: 1\nb: 2\nâ: 3 \n"
56
57 [["Mappings with defined keys (Map)".variations."parse snippet where key is not found in schema".steps]]
58
59 ["Mappings with defined keys (Map)".variations."parse snippet where key is not found in schema".steps.Run]
60 code = "load(yaml_snippet, schema)"
61
62 ["Mappings with defined keys (Map)".variations."parse snippet where key is not found in schema".steps.Run.raises]
63 type = "strictyaml.exceptions.YAMLValidationError"
64 message = "while parsing a mapping\nunexpected key not in schema 'â'\n in \"<unicode string>\", line 3, column 1:\n \"\\xE2\": '3'\n ^ (line: 3)"
65
66 ["Mappings with defined keys (Map)".variations."sequence not expected when parsing"]
67
68 ["Mappings with defined keys (Map)".variations."sequence not expected when parsing".given]
69 yaml_snippet = "- 1\n- 2\n- 3 \n"
70
71 [["Mappings with defined keys (Map)".variations."sequence not expected when parsing".steps]]
72
73 ["Mappings with defined keys (Map)".variations."sequence not expected when parsing".steps.Run]
74 code = "load(yaml_snippet, schema)"
75
76 ["Mappings with defined keys (Map)".variations."sequence not expected when parsing".steps.Run.raises]
77 type = "strictyaml.exceptions.YAMLValidationError"
78 message = "when expecting a mapping\n in \"<unicode string>\", line 1, column 1:\n - '1'\n ^ (line: 1)\nfound a sequence\n in \"<unicode string>\", line 3, column 1:\n - '3'\n ^ (line: 3)"
79
80 ["Mappings with defined keys (Map)".variations."List not expected when serializing"]
81
82 [["Mappings with defined keys (Map)".variations."List not expected when serializing".steps]]
83
84 ["Mappings with defined keys (Map)".variations."List not expected when serializing".steps.Run]
85 code = "as_document([1, 2, 3], schema)"
86
87 ["Mappings with defined keys (Map)".variations."List not expected when serializing".steps.Run.raises]
88 type = "strictyaml.exceptions.YAMLSerializationError"
89 message = "Expected a dict, found '[1, 2, 3]'"
90
91 ["Mappings with defined keys (Map)".variations."Empty dict not valid when serializing"]
92
93 [["Mappings with defined keys (Map)".variations."Empty dict not valid when serializing".steps]]
94
95 ["Mappings with defined keys (Map)".variations."Empty dict not valid when serializing".steps.Run]
96 code = "as_document({}, schema)"
97
98 ["Mappings with defined keys (Map)".variations."Empty dict not valid when serializing".steps.Run.raises]
99 type = "strictyaml.exceptions.YAMLSerializationError"
100 message = "Expected a non-empty dict, found an empty dict.\nUse EmptyDict validator to serialize empty dicts."
101
102 ["Mappings with defined keys (Map)".variations."Unexpected key"]
103
104 ["Mappings with defined keys (Map)".variations."Unexpected key".given]
105 yaml_snippet = "a: 1\nb: 2\nc: 3\nd: 4\n"
106
107 [["Mappings with defined keys (Map)".variations."Unexpected key".steps]]
108
109 ["Mappings with defined keys (Map)".variations."Unexpected key".steps.Run]
110 code = "load(yaml_snippet, schema)"
111
112 ["Mappings with defined keys (Map)".variations."Unexpected key".steps.Run.raises]
113 type = "strictyaml.exceptions.YAMLValidationError"
114 message = "while parsing a mapping\nunexpected key not in schema 'd'\n in \"<unicode string>\", line 4, column 1:\n d: '4'\n ^ (line: 4)"
115
116 ["Mappings with defined keys (Map)".variations."required key not found"]
117
118 ["Mappings with defined keys (Map)".variations."required key not found".given]
119 yaml_snippet = "a: 1\n"
120
121 [["Mappings with defined keys (Map)".variations."required key not found".steps]]
122
123 ["Mappings with defined keys (Map)".variations."required key not found".steps.Run]
124 code = "load(yaml_snippet, schema)"
125
126 ["Mappings with defined keys (Map)".variations."required key not found".steps.Run.raises]
127 type = "strictyaml.exceptions.YAMLValidationError"
128 message = "while parsing a mapping\nrequired key(s) 'b', 'c' not found\n in \"<unicode string>\", line 1, column 1:\n a: '1'\n ^ (line: 1)"
129
130 ["Mappings with defined keys (Map)".variations.iterator]
131
132 ["Mappings with defined keys (Map)".variations.iterator.given]
133 yaml_snippet = "a: 1\nb: 2\nc: 3\n"
134
135 [["Mappings with defined keys (Map)".variations.iterator.steps]]
136 Run = "assert [item for item in load(yaml_snippet, schema)] == [\"a\", \"b\", \"c\"]\n"
137
138 ["Mappings with defined keys (Map)".variations.serialize]
139
140 [["Mappings with defined keys (Map)".variations.serialize.steps]]
141 Run = "assert as_document(OrderedDict([(u\"â\", 1), (\"b\", 2), (\"c\", 3)]), schema_2).as_yaml() == yaml_snippet\n"