2 Unit test for documentation generation 3 Author: Matthew Sklar, Varun Agrawal 12 import xml.etree.ElementTree
as ET
14 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
16 import docs.parser.parse_doxygen_xml
as parser
17 from docs.docs
import ClassDoc, Doc, Docs, FreeDoc
19 tree_root = ET.Element(
'a')
20 tree_left = ET.SubElement(tree_root,
'b')
21 tree_right = ET.SubElement(tree_root, 1)
22 tree_leaf = ET.SubElement(tree_right,
None)
23 tree_recursive = ET.SubElement(tree_left, tree_left)
26 b = ET.SubElement(a,
'b')
27 c = ET.SubElement(b,
'c')
28 d = ET.SubElement(b,
'd')
29 d2 = ET.SubElement(d,
'd')
33 """Test class for document generation utilities.""" 34 DIR_NAME = path.dirname(__file__)
36 DOC_DIR =
'doc-test-files' 37 OUTPUT_XML_DIR =
'actual/xml' 38 EXPECTED_XML_DIR =
'expected/xml' 40 DOC_DIR_PATH = path.abspath(path.join(DIR_NAME, DOC_DIR))
41 OUTPUT_XML_DIR_PATH = path.abspath(path.join(DIR_NAME, OUTPUT_XML_DIR))
42 EXPECTED_XML_DIR_PATH = path.abspath(path.join(DIR_NAME, EXPECTED_XML_DIR))
44 @unittest.skip(
"DOC_DIR_PATH doesn't exist")
46 """Test parse_xml.generate_xml""" 57 if path.exists(xml_path):
58 shutil.rmtree(xml_path)
66 self.assertTrue(
not dircmp.diff_files
and not dircmp.funny_files)
68 @unittest.skip(
"DOC_DIR_PATH doesn't exist")
70 """Test the parsing of the XML generated by Doxygen.""" 74 for class_name
in docs.get_class_docs_keys_list():
75 actual_tree_root = docs.get_class_docs(
76 class_name).get_tree().getroot()
77 expected_tree_root = ET.parse(class_name).getroot()
79 self.assertEqual(ET.tostring(actual_tree_root),
80 ET.tostring(expected_tree_root))
84 class_doc_root = ClassDoc(tree_root)
85 class_doc_left = ClassDoc(tree_left)
86 class_doc_right = ClassDoc(tree_right)
87 class_doc_leaf = ClassDoc(tree_leaf)
88 class_doc_recursive = ClassDoc(tree_recursive)
90 free_doc_root = ClassDoc(tree_root)
91 free_doc_left = ClassDoc(tree_left)
92 free_doc_right = ClassDoc(tree_right)
93 free_doc_leaf = ClassDoc(tree_leaf)
94 free_doc_recursive = ClassDoc(tree_recursive)
97 'Class_Root': tree_root,
98 'Class_Left': tree_left,
99 'Class_Right': tree_right,
100 'Class_Leaf': tree_leaf,
101 'Class_Recursive': tree_recursive,
105 'Free_Root': tree_root,
106 'Free_Left': tree_left,
107 'Free_Right': tree_right,
108 'Free_Leaf': tree_leaf,
109 'Free_Recursive': tree_recursive,
114 """Test the constructor in ClassDoc""" 115 self.assertIs(self.class_doc_root.tree, tree_root)
116 self.assertIs(self.class_doc_left.tree, tree_left)
117 self.assertIs(self.class_doc_right.tree, tree_right)
118 self.assertIs(self.class_doc_leaf.tree, tree_leaf)
119 self.assertIs(self.class_doc_recursive.tree, tree_recursive)
122 """Test the get_tree() method is ClassDoc""" 123 self.assertIs(self.class_doc_root.get_tree(), tree_root)
124 self.assertIs(self.class_doc_left.get_tree(), tree_left)
125 self.assertIs(self.class_doc_right.get_tree(), tree_right)
126 self.assertIs(self.class_doc_leaf.get_tree(), tree_leaf)
127 self.assertIs(self.class_doc_recursive.get_tree(), tree_recursive)
130 """Test ClassDoc.__eq__""" 131 doc1 = ClassDoc(ET.ElementTree(a))
132 doc2 = ClassDoc(ET.ElementTree(d))
133 doc3 = ClassDoc(ET.ElementTree(d2))
135 self.assertEqual(doc1, doc1)
136 self.assertEqual(doc2, doc2)
137 self.assertNotEqual(doc2, doc3)
138 self.assertEqual(
None,
None)
139 self.assertNotEqual(doc1, doc2)
140 self.assertNotEqual(doc1,
None)
144 """Test the constructor in FreeDoc""" 145 self.assertIs(self.free_doc_root.tree, tree_root)
146 self.assertIs(self.free_doc_left.tree, tree_left)
147 self.assertIs(self.free_doc_right.tree, tree_right)
148 self.assertIs(self.free_doc_leaf.tree, tree_leaf)
149 self.assertIs(self.free_doc_recursive.tree, tree_recursive)
152 """Test the get_tree() method is FreeDoc""" 153 self.assertIs(self.free_doc_root.get_tree(), tree_root)
154 self.assertIs(self.free_doc_left.get_tree(), tree_left)
155 self.assertIs(self.free_doc_right.get_tree(), tree_right)
156 self.assertIs(self.free_doc_leaf.get_tree(), tree_leaf)
157 self.assertIs(self.free_doc_recursive.get_tree(), tree_recursive)
160 """Test FreeDoc.__eq__""" 161 doc1 = FreeDoc(ET.ElementTree(a))
162 doc2 = FreeDoc(ET.ElementTree(d))
163 doc3 = FreeDoc(ET.ElementTree(d2))
165 self.assertEqual(doc1, doc1)
166 self.assertEqual(doc2, doc2)
167 self.assertNotEqual(doc2, doc3)
168 self.assertEqual(
None,
None)
169 self.assertNotEqual(doc1, doc2)
170 self.assertNotEqual(doc1,
None)
174 """Test Docs template constructor""" 177 self.assertIs(docs.class_docs, self.
CLASS_DOCS)
178 self.assertIs(docs.free_docs, self.
FREE_DOCS)
183 for doc_name
in self.CLASS_DOCS.keys():
184 self.assertIs(self.CLASS_DOCS.get(doc_name),
185 docs.get_class_docs(doc_name))
190 for doc_name
in self.FREE_DOCS.keys():
191 self.assertIs(self.FREE_DOCS.get(doc_name),
192 docs.get_free_docs(doc_name))
197 docs_list = docs.get_class_docs_keys_list()
201 for key
in class_doc_keys:
202 self.assertIn(key, docs_list)
207 docs_list = docs.get_free_docs_keys_list()
211 for key
in free_doc_keys:
212 self.assertIn(key, docs_list)
216 docs_list = docs.get_class_docs_values_list()
219 self.assertIn(tree_root, docs_list)
220 self.assertIn(tree_left, docs_list)
221 self.assertIn(tree_right, docs_list)
222 self.assertIn(tree_leaf, docs_list)
223 self.assertIn(tree_recursive, docs_list)
227 docs_list = docs.get_free_docs_values_list()
230 self.assertIn(tree_root, docs_list)
231 self.assertIn(tree_left, docs_list)
232 self.assertIn(tree_right, docs_list)
233 self.assertIn(tree_leaf, docs_list)
234 self.assertIn(tree_recursive, docs_list)
237 if __name__ ==
"__main__":
def test_class_doc_get_tree(self)
def test_generate_xml(self)
def test_free_doc_get_tree(self)
def test_get_free_docs_keys_list(self)
def test_get_class_docs_values_list(self)
def test_get_free_docs(self)
def test_get_class_docs_keys_list(self)
def test_get_free_docs_values_list(self)
def test_class_doc_eq(self)
def test_get_class_docs(self)
void run(Expr &expr, Dev &dev)
def test_free_doc_eq(self)