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))
45 """Test parse_xml.generate_xml"""
56 if path.exists(xml_path):
57 shutil.rmtree(xml_path)
65 self.assertTrue(
not dircmp.diff_files
and not dircmp.funny_files)
68 """Test the parsing of the XML generated by Doxygen."""
72 for class_name
in docs.get_class_docs_keys_list():
73 actual_tree_root = docs.get_class_docs(
74 class_name).get_tree().getroot()
75 expected_tree_root = ET.parse(class_name).getroot()
77 self.assertEqual(ET.tostring(actual_tree_root),
78 ET.tostring(expected_tree_root))
82 class_doc_root = ClassDoc(tree_root)
83 class_doc_left = ClassDoc(tree_left)
84 class_doc_right = ClassDoc(tree_right)
85 class_doc_leaf = ClassDoc(tree_leaf)
86 class_doc_recursive = ClassDoc(tree_recursive)
88 free_doc_root = ClassDoc(tree_root)
89 free_doc_left = ClassDoc(tree_left)
90 free_doc_right = ClassDoc(tree_right)
91 free_doc_leaf = ClassDoc(tree_leaf)
92 free_doc_recursive = ClassDoc(tree_recursive)
95 'Class_Root': tree_root,
96 'Class_Left': tree_left,
97 'Class_Right': tree_right,
98 'Class_Leaf': tree_leaf,
99 'Class_Recursive': tree_recursive,
103 'Free_Root': tree_root,
104 'Free_Left': tree_left,
105 'Free_Right': tree_right,
106 'Free_Leaf': tree_leaf,
107 'Free_Recursive': tree_recursive,
112 """Test the constructor in ClassDoc"""
120 """Test the get_tree() method is ClassDoc"""
128 """Test ClassDoc.__eq__"""
129 doc1 = ClassDoc(ET.ElementTree(a))
130 doc2 = ClassDoc(ET.ElementTree(d))
131 doc3 = ClassDoc(ET.ElementTree(d2))
133 self.assertEqual(doc1, doc1)
134 self.assertEqual(doc2, doc2)
135 self.assertNotEqual(doc2, doc3)
136 self.assertEqual(
None,
None)
137 self.assertNotEqual(doc1, doc2)
138 self.assertNotEqual(doc1,
None)
142 """Test the constructor in FreeDoc"""
150 """Test the get_tree() method is FreeDoc"""
158 """Test FreeDoc.__eq__"""
159 doc1 = FreeDoc(ET.ElementTree(a))
160 doc2 = FreeDoc(ET.ElementTree(d))
161 doc3 = FreeDoc(ET.ElementTree(d2))
163 self.assertEqual(doc1, doc1)
164 self.assertEqual(doc2, doc2)
165 self.assertNotEqual(doc2, doc3)
166 self.assertEqual(
None,
None)
167 self.assertNotEqual(doc1, doc2)
168 self.assertNotEqual(doc1,
None)
172 """Test Docs template constructor"""
175 self.assertIs(docs.class_docs, self.
CLASS_DOCS)
176 self.assertIs(docs.free_docs, self.
FREE_DOCS)
183 docs.get_class_docs(doc_name))
190 docs.get_free_docs(doc_name))
195 docs_list = docs.get_class_docs_keys_list()
199 for key
in class_doc_keys:
200 self.assertIn(key, docs_list)
205 docs_list = docs.get_free_docs_keys_list()
209 for key
in free_doc_keys:
210 self.assertIn(key, docs_list)
214 docs_list = docs.get_class_docs_values_list()
217 self.assertIn(tree_root, docs_list)
218 self.assertIn(tree_left, docs_list)
219 self.assertIn(tree_right, docs_list)
220 self.assertIn(tree_leaf, docs_list)
221 self.assertIn(tree_recursive, docs_list)
225 docs_list = docs.get_free_docs_values_list()
228 self.assertIn(tree_root, docs_list)
229 self.assertIn(tree_left, docs_list)
230 self.assertIn(tree_right, docs_list)
231 self.assertIn(tree_leaf, docs_list)
232 self.assertIn(tree_recursive, docs_list)
235 if __name__ ==
"__main__":