async def test_load_imports(self): """Tests the fetch_object_async function with the imports load strategy set to load.""" error_count = 0 corpus = TestHelper.get_local_corpus(self.tests_subpath, 'test_imports_load_strategy') def callback(status_level: CdmStatusLevel, message: str): nonlocal error_count if message.index('Unable to resolve the reference') != -1: error_count += 1 else: self.fail(message) corpus.set_event_callback(callback, CdmStatusLevel.ERROR) # load with strict validation. res_opt = ResolveOptions() res_opt.imports_load_strategy = ImportsLoadStrategy.LOAD await corpus.fetch_object_async('local:/doc.cdm.json', res_opt=res_opt) self.assertEqual(1, error_count) error_count = 0 corpus = TestHelper.get_local_corpus(self.tests_subpath, 'test_imports_load_strategy') def callback1(status_level: CdmStatusLevel, message: str): nonlocal error_count if status_level == CdmStatusLevel.WARNING and message.index('Unable to resolve the reference') != -1: error_count += 1 else: self.fail(message) corpus.set_event_callback(callback1, CdmStatusLevel.WARNING) # load with strict validation and shallow validation. res_opt = ResolveOptions() res_opt.imports_load_strategy = ImportsLoadStrategy.LOAD res_opt.shallow_validation = True await corpus.fetch_object_async('local:/doc.cdm.json', res_opt=res_opt) self.assertEqual(1, error_count)
def _copy_resolve_options(res_opt: 'ResolveOptions') -> 'ResolveOptions': from cdm.utilities import ResolveOptions # pylint: disable=redefined-outer-name res_opt_copy = ResolveOptions() res_opt_copy.wrt_doc = res_opt.wrt_doc res_opt_copy._relationship_depth = res_opt._relationship_depth res_opt_copy._localize_references_for = res_opt._localize_references_for res_opt_copy._indexing_doc = res_opt._indexing_doc res_opt_copy.shallow_validation = res_opt.shallow_validation res_opt_copy._resolved_attribute_limit = res_opt._resolved_attribute_limit if res_opt.directives: res_opt_copy.directives = res_opt.directives.copy() return res_opt_copy