Skip to content

Commit ff3d509

Browse files
ag-eitiltSam May
authored and
Sam May
committed
DOCS: Use actual TOML rather than a strawman
The example file looks to have been machine-generated and (being generous) written to an old version of the standard, and does not present an accurate counter-example to the YAML. This updates it to be (closer to) TOML as it might actually be written. *Actual* actual TOML would very likely not include story/test names as the keys and instead simply something like `[map.variations.one-key]", with the full `"Mappings with defined keys (Map)"`, etc., names being defined as data-pairs within that, but I consider that a wart of the schema rather than of the language used.
1 parent dfd93f9 commit ff3d509

File tree

1 file changed

+86
-112
lines changed

1 file changed

+86
-112
lines changed

hitch/story/map.toml

+86-112
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,115 @@
11
["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"
2+
docs = "compound/mapping"
3+
"based on" = "strictyaml"
4+
description = """
5+
Mappings of one value to another are represented by : in YAML \
6+
and parsed as python dicts.
57
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"
8+
Using StrictYAML's 'Map' you can validate that a mapping \
9+
contains the right keys and the right *type* of values.
910
10-
["Mappings with defined keys (Map)".variations]
11+
Note: for mappings where you don't know the exact names of \
12+
the keys in advance but you do know the type, use MapPattern."""
1113

12-
["Mappings with defined keys (Map)".variations."one key mapping"]
14+
given.setup = """
15+
from collections import OrderedDict
16+
from strictyaml import Map, Int, load, as_document
17+
from collections import OrderedDict
18+
from ensure import Ensure
1319
14-
["Mappings with defined keys (Map)".variations."one key mapping".given]
15-
yaml_snippet = "x: 1"
20+
schema = Map({"a": Int(), "b": Int(), "c": Int()})
1621
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"
22+
schema_2 = Map({u"â": Int(), "b": Int(), "c": Int()})"""
23+
given.yaml_snippet = "â: 1\nb: 2\nc: 3"
1924

20-
["Mappings with defined keys (Map)".variations."key value"]
25+
["Mappings with defined keys (Map)".variations."one key mapping"]
26+
given.yaml_snippet = "x: 1"
27+
[["Mappings with defined keys (Map)".variations."one key mapping".steps]]
28+
Run = """Ensure(load(yaml_snippet, Map({"x": Int()})).data).equals(OrderedDict([('x', 1)]))"""
2129

2230
[["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"]
31+
Run = "Ensure(load(yaml_snippet, schema_2)[u'â']).equals(1)"
2632

2733
[["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"]
34+
Run.code = "load(yaml_snippet, schema_2)['keynotfound']"
35+
Run.raises.message = "'keynotfound'"
3636

3737
[["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."
38+
Run.code = "load(yaml_snippet, schema_2).text"
39+
["Mappings with defined keys (Map)".variations."cannot use .text".steps.Run.raises.type]
40+
"in python 3" = "builtins.TypeError"
41+
"in python 2" = "exceptions.TypeError"
42+
["Mappings with defined keys (Map)".variations."cannot use .text".steps.Run.raises.message]
43+
"in python 3" = "YAML(OrderedDict([('â', 1), ('b', 2), ('c', 3)])) is a mapping, has no text value."
44+
"in python 2" = "YAML(OrderedDict([(u'\\xe2', 1), ('b', 2), ('c', 3)])) is a mapping, has no text value."
5145

5246
["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)"
47+
given.yaml_snippet = "a: 1\nb: 2\nâ: 3"
48+
[["Mappings with defined keys (Map)".variations."parse snippet where key is not found in schema".steps]]
49+
Run.code = "load(yaml_snippet, schema)"
50+
Run.raises.type = "strictyaml.exceptions.YAMLValidationError"
51+
Run.raises.message = """
52+
while parsing a mapping
53+
unexpected key not in schema 'â'
54+
in "<unicode string>", line 3, column 1:
55+
"\\xE2": '3'
56+
^ (line: 3)"""
6557

6658
["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"]
59+
given.yaml_snippet = "- 1\n- 2\n- 3"
60+
[["Mappings with defined keys (Map)".variations."sequence not expected when parsing".steps]]
61+
Run.code = "load(yaml_snippet, schema)"
62+
Run.raises.type = "strictyaml.exceptions.YAMLValidationError"
63+
Run.raises.message = """
64+
when expecting a mapping
65+
in "<unicode string>", line 1, column 1:
66+
- '1'
67+
^ (line: 1)
68+
found a sequence
69+
in "<unicode string>", line 3, column 1:
70+
- '3'
71+
^ (line: 3)"""
8172

8273
[["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"]
74+
Run.code = "as_document([1, 2, 3], schema)"
75+
Run.raises.type = "strictyaml.exceptions.YAMLSerializationError"
76+
Run.raises.message = "Expected a dict, found '[1, 2, 3]'"
9277

9378
[["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."
79+
Run.code = "as_document({}, schema)"
80+
Run.raises.type = "strictyaml.exceptions.YAMLSerializationError"
81+
Run.raises.message = """
82+
Expected a non-empty dict, found an empty dict.
83+
Use EmptyDict validator to serialize empty dicts."""
10184

10285
["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)"
86+
given.yaml_snippet = "a: 1\nb: 2\nc: 3\nd: 4"
87+
[["Mappings with defined keys (Map)".variations."Unexpected key".steps]]
88+
Run.code = "load(yaml_snippet, schema)"
89+
Run.raises.type = "strictyaml.exceptions.YAMLValidationError"
90+
Run.raises.message = """
91+
while parsing a mapping
92+
unexpected key not in schema 'd'
93+
in "<unicode string>", line 4, column 1:
94+
d: '4'
95+
^ (line: 4)"""
11596

11697
["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)"
98+
given.yaml_snippet = "a: 1"
99+
[["Mappings with defined keys (Map)".variations."required key not found".steps]]
100+
Run.code = "load(yaml_snippet, schema)"
101+
Run.raises.type = "strictyaml.exceptions.YAMLValidationError"
102+
Run.raises.message = """
103+
while parsing a mapping
104+
required key(s) 'b', 'c' not found
105+
in "<unicode string>", line 1, column 1:
106+
a: '1'
107+
^ (line: 1)"""
129108

130109
["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]
110+
given.yaml_snippet = "a: 1\nb: 2\nc: 3"
111+
[["Mappings with defined keys (Map)".variations.iterator.steps]]
112+
Run = """assert [item for item in load(yaml_snippet, schema)] == ["a", "b", "c"]"""
139113

140114
[["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"
115+
Run = """assert as_document(OrderedDict([(u", 1), ("b", 2), ("c", 3)]), schema_2).as_yaml() == yaml_snippet"""

0 commit comments

Comments
 (0)