@@ -10,10 +10,7 @@ def test_with_resource(self):
10
10
Adding a resource to the registry then allows re-retrieving it.
11
11
"""
12
12
13
- resource = Resource (
14
- contents = {"foo" : "bar" },
15
- specification = Specification .OPAQUE ,
16
- )
13
+ resource = Resource .opaque (contents = {"foo" : "bar" })
17
14
uri = "urn:example"
18
15
registry = Registry ().with_resource (uri = uri , resource = resource )
19
16
assert registry [uri ] is resource
@@ -23,7 +20,7 @@ def test_with_resources(self):
23
20
Adding multiple resources to the registry is like adding each one.
24
21
"""
25
22
26
- one = Resource (contents = {}, specification = Specification . OPAQUE )
23
+ one = Resource . opaque (contents = {})
27
24
two = Resource (contents = {"foo" : "bar" }, specification = DRAFT202012 )
28
25
registry = Registry ().with_resources (
29
26
[
@@ -53,11 +50,7 @@ def test_with_contents_and_default_specification(self):
53
50
[(uri , {"foo" : "bar" })],
54
51
default_specification = Specification .OPAQUE ,
55
52
)
56
- expected = Resource (
57
- contents = {"foo" : "bar" },
58
- specification = Specification .OPAQUE ,
59
- )
60
- assert registry [uri ] == expected
53
+ assert registry [uri ] == Resource .opaque ({"foo" : "bar" })
61
54
62
55
def test_len (self ):
63
56
total = 5
@@ -75,25 +68,19 @@ def test_iter(self):
75
68
assert set (registry ) == {str (i ) for i in range (8 )}
76
69
77
70
def test_crawl_still_has_top_level_resource (self ):
78
- resource = Resource (
79
- contents = {"foo" : "bar" },
80
- specification = Specification .OPAQUE ,
81
- )
71
+ resource = Resource .opaque ({"foo" : "bar" })
82
72
uri = "urn:example"
83
73
registry = Registry ().with_resources ([(uri , resource )]).crawl ()
84
74
assert registry [uri ] is resource
85
75
86
76
def test_contents (self ):
87
- resource = Resource (
88
- contents = {"foo" : "bar" },
89
- specification = Specification .OPAQUE ,
90
- )
77
+ resource = Resource .opaque ({"foo" : "bar" })
91
78
uri = "urn:example"
92
79
registry = Registry ().with_resources ([(uri , resource )])
93
80
assert registry .contents (uri ) == {"foo" : "bar" }
94
81
95
82
def test_init (self ):
96
- one = Resource (contents = {}, specification = Specification . OPAQUE )
83
+ one = Resource . opaque (contents = {})
97
84
two = Resource (contents = {"foo" : "bar" }, specification = DRAFT202012 )
98
85
registry = Registry (
99
86
{
@@ -115,7 +102,7 @@ def test_dict_conversion(self):
115
102
So continuing to use the registry works.
116
103
"""
117
104
118
- one = Resource (contents = {}, specification = Specification . OPAQUE )
105
+ one = Resource . opaque (contents = {})
119
106
two = Resource (contents = {"foo" : "bar" }, specification = DRAFT202012 )
120
107
registry = Registry (
121
108
{"http://example.com/1" : one },
@@ -128,7 +115,7 @@ def test_dict_conversion(self):
128
115
)
129
116
130
117
def test_combine (self ):
131
- one = Resource (contents = {}, specification = Specification . OPAQUE )
118
+ one = Resource . opaque (contents = {})
132
119
two = Resource (contents = {"foo" : "bar" }, specification = DRAFT202012 )
133
120
three = Resource (contents = {"baz" : "quux" }, specification = DRAFT202012 )
134
121
@@ -170,10 +157,7 @@ def test_from_contents_with_no_discernible_information_and_default(self):
170
157
{"foo" : "bar" },
171
158
default_specification = Specification .OPAQUE ,
172
159
)
173
- assert resource == Resource (
174
- contents = {"foo" : "bar" },
175
- specification = Specification .OPAQUE ,
176
- )
160
+ assert resource == Resource .opaque (contents = {"foo" : "bar" })
177
161
178
162
def test_from_contents_unneeded_default (self ):
179
163
schema = {"$schema" : "https://json-schema.org/draft/2020-12/schema" }
@@ -189,22 +173,16 @@ def test_from_contents_unneeded_default(self):
189
173
def test_non_mapping_from_contents (self ):
190
174
resource = Resource .from_contents (
191
175
True ,
192
- default_specification = Specification .OPAQUE ,
193
- )
194
- assert resource == Resource (
195
- contents = True ,
196
- specification = Specification .OPAQUE ,
176
+ default_specification = DRAFT202012 ,
197
177
)
178
+ assert resource == Resource (contents = True , specification = DRAFT202012 )
198
179
199
180
def test_from_contents_with_fallback (self ):
200
181
resource = Resource .from_contents (
201
182
{"foo" : "bar" },
202
183
default_specification = Specification .OPAQUE ,
203
184
)
204
- assert resource == Resource (
205
- contents = {"foo" : "bar" },
206
- specification = Specification .OPAQUE ,
207
- )
185
+ assert resource == Resource .opaque (contents = {"foo" : "bar" })
208
186
209
187
def test_id_delegates_to_specification (self ):
210
188
specification = Specification (id_of = lambda contents : "urn:fixedID" )
@@ -215,28 +193,26 @@ def test_id_delegates_to_specification(self):
215
193
assert resource .id () == "urn:fixedID"
216
194
217
195
def test_pointer_to_mapping (self ):
218
- resource = Resource (
219
- contents = {"foo" : "baz" },
220
- specification = Specification .OPAQUE ,
221
- )
196
+ resource = Resource .opaque (contents = {"foo" : "baz" })
222
197
resolver = Registry ().resolver ()
223
198
assert resource .pointer ("/foo" , resolver = resolver ).contents == "baz"
224
199
225
200
def test_pointer_to_array (self ):
226
- resource = Resource (
227
- contents = {"foo" : {"bar" : [3 ]}},
228
- specification = Specification .OPAQUE ,
229
- )
201
+ resource = Resource .opaque (contents = {"foo" : {"bar" : [3 ]}})
230
202
resolver = Registry ().resolver ()
231
203
assert resource .pointer ("/foo/bar/0" , resolver = resolver ).contents == 3
232
204
205
+ def test_opaque (self ):
206
+ contents = {"foo" : "bar" }
207
+ assert Resource .opaque (contents ) == Resource (
208
+ contents = contents ,
209
+ specification = Specification .OPAQUE ,
210
+ )
211
+
233
212
234
213
class TestResolver :
235
214
def test_lookup_exact_uri (self ):
236
- resource = Resource (
237
- contents = {"foo" : "baz" },
238
- specification = Specification .OPAQUE ,
239
- )
215
+ resource = Resource .opaque (contents = {"foo" : "baz" })
240
216
resolver = Registry ({"http://example.com/1" : resource }).resolver ()
241
217
resolved = resolver .lookup ("http://example.com/1" )
242
218
assert resolved .contents == resource .contents
0 commit comments