File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -151,6 +151,11 @@ def __len__(self) -> int:
151
151
"""
152
152
return len (self ._resources )
153
153
154
+ def __repr__ (self ) -> str :
155
+ size = len (self )
156
+ pluralized = "resource" if size == 1 else "resources"
157
+ return f"<Registry ({ size } { pluralized } )>"
158
+
154
159
def contents (self , uri : URI ) -> D :
155
160
"""
156
161
Retrieve the contents identified by the given URI.
Original file line number Diff line number Diff line change @@ -135,6 +135,27 @@ def test_combine(self):
135
135
],
136
136
)
137
137
138
+ def test_repr (self ):
139
+ one = Resource .opaque (contents = {})
140
+ two = Resource (contents = {"foo" : "bar" }, specification = DRAFT202012 )
141
+ registry = Registry ().with_resources (
142
+ [
143
+ ("http://example.com/1" , one ),
144
+ ("http://example.com/foo/bar" , two ),
145
+ ],
146
+ )
147
+ assert repr (registry ) == "<Registry (2 resources)>"
148
+
149
+ def test_repr_one_resource (self ):
150
+ registry = Registry ().with_resource (
151
+ uri = "http://example.com/1" ,
152
+ resource = Resource .opaque (contents = {}),
153
+ )
154
+ assert repr (registry ) == "<Registry (1 resource)>"
155
+
156
+ def test_repr_empty (self ):
157
+ assert repr (Registry ()) == "<Registry (0 resources)>"
158
+
138
159
139
160
class TestResource :
140
161
def test_from_contents_from_json_schema (self ):
You can’t perform that action at this time.
0 commit comments