test_docs.py
Go to the documentation of this file.
1 """
2 Unit test for documentation generation
3 Author: Matthew Sklar, Varun Agrawal
4 Date: May 2019
5 """
6 import filecmp
7 import os
8 from os import path
9 import shutil
10 import sys
11 import unittest
12 import xml.etree.ElementTree as ET
13 
14 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
15 
16 import docs.parser.parse_doxygen_xml as parser
17 from docs.docs import ClassDoc, Doc, Docs, FreeDoc
18 
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)
24 
25 a = ET.Element('a')
26 b = ET.SubElement(a, 'b')
27 c = ET.SubElement(b, 'c')
28 d = ET.SubElement(b, 'd')
29 d2 = ET.SubElement(d, 'd')
30 
31 
32 class TestDocument(unittest.TestCase):
33  """Test class for document generation utilities."""
34  DIR_NAME = path.dirname(__file__)
35 
36  DOC_DIR = 'doc-test-files'
37  OUTPUT_XML_DIR = 'actual/xml'
38  EXPECTED_XML_DIR = 'expected/xml'
39 
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))
43 
44  @unittest.skip("DOC_DIR_PATH doesn't exist")
45  def test_generate_xml(self):
46  """Test parse_xml.generate_xml"""
47  if path.exists(self.OUTPUT_XML_DIR_PATH):
48  shutil.rmtree(self.OUTPUT_XML_DIR_PATH, ignore_errors=True)
49 
50  parser.generate_xml(self.DOC_DIR_PATH,
52  quiet=True)
53 
54  self.assertTrue(os.path.isdir(self.OUTPUT_XML_DIR_PATH))
55 
56  xml_path = self.OUTPUT_XML_DIR_PATH
57  if path.exists(xml_path):
58  shutil.rmtree(xml_path)
59  parser.generate_xml(self.DOC_DIR_PATH,
61  quiet=True)
62 
63  dircmp = filecmp.dircmp(self.OUTPUT_XML_DIR_PATH,
65 
66  self.assertTrue(not dircmp.diff_files and not dircmp.funny_files)
67 
68  @unittest.skip("DOC_DIR_PATH doesn't exist")
69  def test_parse(self):
70  """Test the parsing of the XML generated by Doxygen."""
71  docs = parser.ParseDoxygenXML(self.DOC_DIR_PATH,
72  self.OUTPUT_XML_DIR_PATH).run()
73 
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()
78 
79  self.assertEqual(ET.tostring(actual_tree_root),
80  ET.tostring(expected_tree_root))
81 
82 
83 class TestDocTemplate(unittest.TestCase):
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)
89 
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)
95 
96  CLASS_DOCS = {
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,
102  }
103 
104  FREE_DOCS = {
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,
110  }
111 
112  # ClassDoc
113  def test_class_doc(self):
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)
120 
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)
128 
129  def test_class_doc_eq(self):
130  """Test ClassDoc.__eq__"""
131  doc1 = ClassDoc(ET.ElementTree(a))
132  doc2 = ClassDoc(ET.ElementTree(d))
133  doc3 = ClassDoc(ET.ElementTree(d2))
134 
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)
141 
142  # FreeDoc
143  def test_free_doc(self):
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)
150 
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)
158 
159  def test_free_doc_eq(self):
160  """Test FreeDoc.__eq__"""
161  doc1 = FreeDoc(ET.ElementTree(a))
162  doc2 = FreeDoc(ET.ElementTree(d))
163  doc3 = FreeDoc(ET.ElementTree(d2))
164 
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)
171 
172  # Docs
173  def test_docs(self):
174  """Test Docs template constructor"""
175  docs = Docs(self.CLASS_DOCS, self.FREE_DOCS)
176 
177  self.assertIs(docs.class_docs, self.CLASS_DOCS)
178  self.assertIs(docs.free_docs, self.FREE_DOCS)
179 
181  docs = Docs(self.CLASS_DOCS, self.FREE_DOCS)
182 
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))
186 
188  docs = Docs(self.CLASS_DOCS, self.FREE_DOCS)
189 
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))
193 
195  docs = Docs(self.CLASS_DOCS, self.FREE_DOCS)
196  class_doc_keys = list(self.CLASS_DOCS)
197  docs_list = docs.get_class_docs_keys_list()
198 
199  self.assertEqual(len(self.CLASS_DOCS), len(docs_list))
200 
201  for key in class_doc_keys:
202  self.assertIn(key, docs_list)
203 
205  docs = Docs(self.CLASS_DOCS, self.FREE_DOCS)
206  free_doc_keys = list(self.FREE_DOCS)
207  docs_list = docs.get_free_docs_keys_list()
208 
209  self.assertEqual(len(self.FREE_DOCS), len(docs_list))
210 
211  for key in free_doc_keys:
212  self.assertIn(key, docs_list)
213 
215  docs = Docs(self.CLASS_DOCS, self.FREE_DOCS)
216  docs_list = docs.get_class_docs_values_list()
217 
218  self.assertEqual(len(self.CLASS_DOCS), len(docs_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)
224 
226  docs = Docs(self.CLASS_DOCS, self.FREE_DOCS)
227  docs_list = docs.get_free_docs_values_list()
228 
229  self.assertEqual(len(self.FREE_DOCS), len(docs_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)
235 
236 
237 if __name__ == "__main__":
238  unittest.main()
def test_class_doc_get_tree(self)
Definition: test_docs.py:121
def test_generate_xml(self)
Definition: test_docs.py:45
def test_free_doc_get_tree(self)
Definition: test_docs.py:151
def test_get_free_docs_keys_list(self)
Definition: test_docs.py:204
def test_get_class_docs_values_list(self)
Definition: test_docs.py:214
def test_get_free_docs(self)
Definition: test_docs.py:187
def test_parse(self)
Definition: test_docs.py:69
def test_get_class_docs_keys_list(self)
Definition: test_docs.py:194
Definition: pytypes.h:1301
def test_get_free_docs_values_list(self)
Definition: test_docs.py:225
def test_get_class_docs(self)
Definition: test_docs.py:180
size_t len(handle h)
Definition: pytypes.h:1514
void run(Expr &expr, Dev &dev)
Definition: TensorSyclRun.h:33


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:46:03