Skip to content

Commit

Permalink
Add cache test. check_exists checks cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Amstutz committed Nov 22, 2016
1 parent a747205 commit 8e32f71
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions schema_salad/ref_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ def fetch_text(self, url):
raise ValueError('Unsupported scheme in url: %s' % url)

def check_exists(self, url): # type: (unicode) -> bool
if url in self.cache:
return True

split = urlparse.urlsplit(url)
scheme, path = split.scheme, split.path

Expand Down
8 changes: 8 additions & 0 deletions schema_salad/tests/test_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ def check_exists(self, url): # type: (unicode) -> bool
with self.assertRaises(RuntimeError):
loader.resolve_ref("bar.txt")
self.assertFalse(loader.check_exists("bar.txt"))

def test_cache(self):
loader = schema_salad.ref_resolver.Loader({})
foo = "file://%s/foo.txt" % os.getcwd()
loader.cache.update({foo: "hello: foo"})
print loader.cache
self.assertEqual({"hello": "foo"}, loader.resolve_ref("foo.txt")[0])
self.assertTrue(loader.check_exists(foo))

0 comments on commit 8e32f71

Please sign in to comment.