Skip to content

Commit e5d4730

Browse files
author
Peter Amstutz
committed
New test for scoped ref that better reflects actual desired behavior.
1 parent efbc9c4 commit e5d4730

File tree

2 files changed

+45
-35
lines changed

2 files changed

+45
-35
lines changed

schema_salad/ref_resolver.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ def resolve_all(self, document, base_url, file_base=None, toplevel=True):
382382
v = {loader.mapPredicate[idmapField]: v}
383383
else:
384384
raise validate.ValidationException(
385-
"mapSubject '%s' value '%s' is not a dict and does not have a mapPredicate", k, v)
385+
"mapSubject '%s' value '%s' is not a dict and does not have a mapPredicate" % (k, v))
386386
v[loader.idmap[idmapField]] = k
387387
ls.append(v)
388388
document[idmapField] = ls
@@ -545,16 +545,17 @@ def validate_link(self, field, link, docid):
545545
if field in self.scoped_ref_fields:
546546
split = urlparse.urlsplit(docid)
547547
sp = split.fragment.split("/")
548-
while len(sp) > 0:
549-
sp.pop()
548+
while True:
550549
sp.append(link)
551550
url = urlparse.urlunsplit(
552551
(split.scheme, split.netloc, split.path, split.query, "/".join(sp)))
553552
if url in self.idx:
554553
print link, "is", url
555554
return url
556-
else:
557-
sp.pop()
555+
sp.pop()
556+
if len(sp) == 0:
557+
break
558+
sp.pop()
558559
raise validate.ValidationException(
559560
"Field `%s` contains undefined reference to `%s`" % (field, link))
560561
elif not self.check_file(link):

tests/test_examples.py

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -109,46 +109,55 @@ def test_idmap(self):
109109
def test_scoped_ref(self):
110110
ldr = schema_salad.ref_resolver.Loader({})
111111
ldr.add_context({
112-
"ref": {
112+
"scatter": {
113113
"@type": "@id",
114114
"scopedRef": True,
115115
},
116+
"source": {
117+
"@type": "@id",
118+
"scopedRef": True,
119+
},
120+
"in": {
121+
"mapSubject": "id",
122+
"mapPredicate": "source"
123+
},
124+
"inputs": {
125+
"mapSubject": "id",
126+
"mapPredicate": "type"
127+
},
128+
"steps": {
129+
"mapSubject": "id"
130+
},
116131
"id": "@id"})
117132

118133
ra, _ = ldr.resolve_all({
119-
"id": "foo",
120-
"blurb": {
121-
"id": "bar",
122-
"blurg": {
123-
"id": "quux",
124-
"blurb": {
125-
"id": "q2"
126-
}
127-
},
128-
"blurb": {
129-
"id": "baz",
130-
"ref": ["foo", "bar", "baz", "quux", "quux/q2"]
134+
"inputs": {
135+
"inp": "string"
136+
},
137+
"steps": {
138+
"step1": {
139+
"in": {
140+
"echo_in": "inp"
141+
},
142+
"scatter": "echo_in"
131143
}
132144
}
133145
}, "http://example2.com/")
134146

135-
self.assertEquals({'id': 'http://example2.com/#foo',
136-
'blurb': {
137-
'id': 'http://example2.com/#foo/bar',
138-
"blurg": {
139-
"id": "http://example2.com/#foo/bar/quux",
140-
"blurb": {
141-
"id": "http://example2.com/#foo/bar/quux/q2"
142-
}
143-
},
144-
'blurb': {
145-
'ref': ['http://example2.com/#foo',
146-
'http://example2.com/#foo/bar',
147-
'http://example2.com/#foo/bar/baz',
148-
'http://example2.com/#foo/bar/quux',
149-
'http://example2.com/#foo/bar/quux/q2'],
150-
'id': 'http://example2.com/#foo/bar/baz'}}},
151-
ra)
147+
self.assertEquals({'inputs': [{
148+
'id': 'http://example2.com/#inp',
149+
'type': 'string'
150+
}],
151+
'steps': [{
152+
'id': 'http://example2.com/#step1',
153+
'scatter': 'http://example2.com/#step1/echo_in',
154+
'in': [{
155+
'id': 'http://example2.com/#step1/echo_in',
156+
'source': 'http://example2.com/#inp'
157+
}]
158+
}]
159+
}, ra)
160+
152161

153162
def test_examples(self):
154163
self.maxDiff = None

0 commit comments

Comments
 (0)