def test_lazy_object(self): def factory(): return [1] lazy = LazyObject(factory) lazy.append(2) self.assertEqual(1, lazy.pop())
from urllib.parse import urlparse from brainiak import triplestore, settings from brainiak.log import get_logger from brainiak.prefixes import MemorizeContext from brainiak.suggest.json_schema import SUGGEST_PARAM_SCHEMA from brainiak.type_mapper import DATATYPE_PROPERTY, OBJECT_PROPERTY, _MAP_EXPAND_XSD_TO_JSON_TYPE from brainiak.utils.cache import build_key_for_class, memoize from brainiak.utils.i18n import _ from brainiak.utils.links import assemble_url, add_link, crud_links, build_relative_class_url, append_param from brainiak.utils.resources import LazyObject from brainiak.utils.sparql import add_language_support, filter_values, get_one_value, get_super_properties, \ InstanceError, bindings_to_dict logger = LazyObject(get_logger) class SchemaNotFound(Exception): pass def get_cached_schema(query_params, include_meta=False): schema_key = build_key_for_class(query_params) class_object = memoize(query_params, get_schema, query_params, key=schema_key) if class_object is None or not class_object["body"]: msg = _(u"The class definition for {0} was not found in graph {1}") raise SchemaNotFound(