def test_ctor(self): ldr = loader.SchemaLoader() assert len(set(ldr.iterURIs())) == 0 ldr = loader.SchemaLoader(locs) uris = set(ldr.iterURIs()) assert len(uris) == 2 assert "uri:nist.gov/goober" in uris assert "http://mgi.nist.gov/goof" in uris
def test_ctor(self): ldr = loader.SchemaHandler(loader.SchemaLoader()) assert not ldr._strict ldr = loader.SchemaHandler(loader.SchemaLoader(locs)) assert not ldr._strict ldr = loader.SchemaHandler(locs, True) assert ldr._strict ldr = loader.SchemaHandler(loader.SchemaLoader(locs), strict=False) assert not ldr._strict
def test_locate(self): ldr = loader.SchemaLoader(locs) assert ldr.locate("uri:nist.gov/goober") == \ "http://www.ivoa.net/xml/goober" assert ldr.locate("http://mgi.nist.gov/goof") == "goof.xml" with pytest.raises(KeyError): ldr.locate("ivo://ivoa.net/rofr")
def test_call(self): ldr = loader.SchemaLoader() ldr.add_location("uri:nist.gov/goober", schemafile) schema = ldr("uri:nist.gov/goober") assert schema assert "$schema" in schema assert "id" in schema
def test_strict(self): ldr = loader.SchemaLoader(locs) hdlr = loader.SchemaHandler(ldr, strict=True) assert hdlr["uri"] is ldr assert hdlr["http"] is ldr with pytest.raises(KeyError): assert hdlr["https"] is ldr
def test_add(self): ldr = loader.SchemaLoader() assert len(set(ldr.iterURIs())) == 0 ldr.add_locations(locs) uris = set(ldr.iterURIs()) assert len(uris) == 2 assert ldr.locate("uri:nist.gov/goober") == \ "http://www.ivoa.net/xml/goober" assert ldr.locate("http://mgi.nist.gov/goof") == "goof.xml" ldr = loader.SchemaLoader() ldr.add_location("uri:nist.gov/goober", "goober.json") assert len(set(ldr.iterURIs())) == 1 assert ldr.locate("uri:nist.gov/goober") == "goober.json" ldr.add_location("http://mgi.nist.gov/goof", "http://www.ivoa.net/xml/goober") assert len(set(ldr.iterURIs())) == 2 assert ldr.locate("http://mgi.nist.gov/goof") == \ "http://www.ivoa.net/xml/goober"
def test_compat(self): ldr = loader.SchemaLoader(locs) ldr.add_location("https://data.nist.gov/od/dm/enhanced-json-schema/v0.1", schemafile) hdlr = loader.SchemaHandler(ldr) assert "uri" in hdlr assert "http" in hdlr assert "https" in hdlr assert len(hdlr) == 3 assert hdlr["uri"] is ldr assert hdlr["http"] is ldr assert hdlr["ftp"] is ldr # not strict schema = hdlr["https"]("https://data.nist.gov/od/dm/enhanced-json-schema/v0.1") assert isinstance(schema, dict) assert "$schema" in schema assert "id" in schema assert schema["id"] == "https://data.nist.gov/od/dm/enhanced-json-schema/v0.1"