def test_reference_iterator_dict_with_references(): tester = { 'foo': 42, 'bar': 'baz', '$ref': 'root', 'baz': { '$ref': 'branch', 'quux': { 'fnord': False, '$ref': 'leaf', }, }, } frozen = tuple(iterators.reference_iterator(tester)) assert len(frozen) == 3, 'Found a different item count than expected!' # We have three references with their paths here, but we don't know which # order the tuple has them in. Let's go through them all: expectations = { 0: 'root', 1: 'branch', 2: 'leaf', } for key, value, path in iterators.reference_iterator(tester): assert value == expectations[len(path)]
def test_reference_iterator_dict_with_references(): tester = { "foo": 42, "bar": "baz", "$ref": "root", "baz": { "$ref": "branch", "quux": { "fnord": False, "$ref": "leaf", }, }, } frozen = tuple(iterators.reference_iterator(tester)) assert len(frozen) == 3, "Found a different item count than expected!" # We have three references with their paths here, but we don't know which # order the tuple has them in. Let's go through them all: expectations = { 0: "root", 1: "branch", 2: "leaf", } for key, value, path in iterators.reference_iterator(tester): assert value == expectations[len(path)]
def test_reference_iterator_dict_without_references(): tester = { 'foo': 42, 'bar': 'baz', 'baz': { 'quux': { 'fnord': False, }, }, } frozen = tuple(iterators.reference_iterator(tester)) assert len(frozen) == 0, 'Found items when it should not have!'
def test_reference_iterator_dict_without_references(): tester = { "foo": 42, "bar": "baz", "baz": { "quux": { "fnord": False, }, }, } frozen = tuple(iterators.reference_iterator(tester)) assert len(frozen) == 0, "Found items when it should not have!"
def _translating_iterator(self, base_url, partial, path): from prance.util.iterators import reference_iterator for _, ref_string, item_path in reference_iterator(partial): ref_url, obj_path = _url.split_url_reference(base_url, ref_string) full_path = path + item_path if ref_url.path == self.url.path: # Reference to the root document. ref_path = obj_path else: # Reference to a non-root document. ref_key = _reference_key(ref_url, obj_path) if ref_key not in self.__collected_references: self.__collected_references[ref_key] = None ref_value = self._dereference(ref_url, obj_path) self.__collected_references[ref_key] = ref_value ref_path = ['components', 'schemas', ref_key] ref_obj = _local_ref(ref_path) yield full_path, ref_obj
def test_reference_iterator_empty_dict(): tester = {} frozen = tuple(iterators.reference_iterator(tester)) assert len(frozen) == 0, 'Found items when it should not have!'