def parse(self): """ Parse the RAML file and return the InternalNode hierarchy from it """ description = prp.load(self.file) root = InternalNode("", None) if '/' in description.resources: res = description.resources['/'] del description.resources['/'] if res is not None: #FIXME: this duplicate code from _parse_resource if res.methods is not None: for method in res.methods: root.add_method(method) root.set_doc(res.description) if description.resources is not None: for name in description.resources: res = description.resources[name] self._parse_resource(root, name, res) return root
def test_set_doc(self): name = "james_bond" helpstring = "RTFM" helpstring_unicode = u"RTFM" node = InternalNode(name, None) self.assertEqual(node.doc, None) node.set_doc(helpstring) self.assertEqual(node.doc, helpstring) node.set_doc(helpstring_unicode) self.assertEqual(node.doc, helpstring_unicode) node.set_doc(None) self.assertEqual(node.doc, None) with self.assertRaisesRegexp( ValueError, "bad type for doc: got int, expected string"): node.set_doc(12) self.assertEqual(node.doc, None)