-
-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge 1.21 changes into salad 2.0 (#68)
* Loader constructor can accept custom "Fetcher" object for fetching files and checking links. * Add test for custom fetcher feature. * Fetcher is a constructor instead of an object. Fix load_schema to update cache instead of replacing it. * Add cache test. check_exists checks cache. * Fetcher includes custom urljoin. * Fix fetcher_constructor to default to None instead of DefaultFetcher. * Adjust package dependencies to be more specific about versions. * Linting * Tweak versioning to reduce chance of future unpleasant suprises from 3rd party upgrades and clean up requirements.txt. * Bump to 2.1
- Loading branch information
Showing
5 changed files
with
167 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
requests | ||
ruamel.yaml==0.12.4 | ||
rdflib>=4.1. | ||
rdflib-jsonld>=0.3.0 | ||
mistune | ||
typing>=3.5.2 ; python_version>="2.7" | ||
avro ; python_version<"3" | ||
typing==3.5.2.2 ; python_version>="2.7" | ||
avro-python3 ; python_version>="3" | ||
CacheControl | ||
lockfile | ||
avro==1.8.1 ; python_version<"3" | ||
ruamel.yaml==0.12.4 | ||
rdflib==4.2.1 | ||
rdflib-jsonld==0.4.0 | ||
html5lib==0.9999999 | ||
mistune==0.7.3 | ||
CacheControl==0.11.7 | ||
lockfile==0.12.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import unittest | ||
import schema_salad.ref_resolver | ||
import schema_salad.main | ||
import schema_salad.schema | ||
from schema_salad.jsonld_context import makerdf | ||
import rdflib | ||
import ruamel.yaml as yaml | ||
import json | ||
import os | ||
import urlparse | ||
|
||
class TestFetcher(unittest.TestCase): | ||
def test_fetcher(self): | ||
class TestFetcher(schema_salad.ref_resolver.Fetcher): | ||
def __init__(self, a, b): | ||
pass | ||
|
||
def fetch_text(self, url): # type: (unicode) -> unicode | ||
if url == "keep:abc+123/foo.txt": | ||
return "hello: keepfoo" | ||
if url.endswith("foo.txt"): | ||
return "hello: foo" | ||
else: | ||
raise RuntimeError("Not foo.txt") | ||
|
||
def check_exists(self, url): # type: (unicode) -> bool | ||
if url.endswith("foo.txt"): | ||
return True | ||
else: | ||
return False | ||
|
||
def urljoin(self, base, url): | ||
urlsp = urlparse.urlsplit(url) | ||
if urlsp.scheme: | ||
return url | ||
basesp = urlparse.urlsplit(base) | ||
|
||
if basesp.scheme == "keep": | ||
return base + "/" + url | ||
return urlparse.urljoin(base, url) | ||
|
||
loader = schema_salad.ref_resolver.Loader({}, fetcher_constructor=TestFetcher) | ||
self.assertEqual({"hello": "foo"}, loader.resolve_ref("foo.txt")[0]) | ||
self.assertEqual({"hello": "keepfoo"}, loader.resolve_ref("foo.txt", base_url="keep:abc+123")[0]) | ||
self.assertTrue(loader.check_exists("foo.txt")) | ||
|
||
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters