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  def test_generate_xml(self):
45  """Test parse_xml.generate_xml"""
46  if path.exists(self.OUTPUT_XML_DIR_PATH):
47  shutil.rmtree(self.OUTPUT_XML_DIR_PATH, ignore_errors=True)
48 
49  parser.generate_xml(self.DOC_DIR_PATH,
51  quiet=True)
52 
53  self.assertTrue(os.path.isdir(self.OUTPUT_XML_DIR_PATH))
54 
55  xml_path = self.OUTPUT_XML_DIR_PATH
56  if path.exists(xml_path):
57  shutil.rmtree(xml_path)
58  parser.generate_xml(self.DOC_DIR_PATH,
60  quiet=True)
61 
62  dircmp = filecmp.dircmp(self.OUTPUT_XML_DIR_PATH,
64 
65  self.assertTrue(not dircmp.diff_files and not dircmp.funny_files)
66 
67  def test_parse(self):
68  """Test the parsing of the XML generated by Doxygen."""
69  docs = parser.ParseDoxygenXML(self.DOC_DIR_PATH,
70  self.OUTPUT_XML_DIR_PATH).run()
71 
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()
76 
77  self.assertEqual(ET.tostring(actual_tree_root),
78  ET.tostring(expected_tree_root))
79 
80 
81 class TestDocTemplate(unittest.TestCase):
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)
87 
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)
93 
94  CLASS_DOCS = {
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,
100  }
101 
102  FREE_DOCS = {
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,
108  }
109 
110  # ClassDoc
111  def test_class_doc(self):
112  """Test the constructor in ClassDoc"""
113  self.assertIs(self.class_doc_root.tree, tree_root)
114  self.assertIs(self.class_doc_left.tree, tree_left)
115  self.assertIs(self.class_doc_right.tree, tree_right)
116  self.assertIs(self.class_doc_leaf.tree, tree_leaf)
117  self.assertIs(self.class_doc_recursive.tree, tree_recursive)
118 
120  """Test the get_tree() method is ClassDoc"""
121  self.assertIs(self.class_doc_root.get_tree(), tree_root)
122  self.assertIs(self.class_doc_left.get_tree(), tree_left)
123  self.assertIs(self.class_doc_right.get_tree(), tree_right)
124  self.assertIs(self.class_doc_leaf.get_tree(), tree_leaf)
125  self.assertIs(self.class_doc_recursive.get_tree(), tree_recursive)
126 
127  def test_class_doc_eq(self):
128  """Test ClassDoc.__eq__"""
129  doc1 = ClassDoc(ET.ElementTree(a))
130  doc2 = ClassDoc(ET.ElementTree(d))
131  doc3 = ClassDoc(ET.ElementTree(d2))
132 
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)
139 
140  # FreeDoc
141  def test_free_doc(self):
142  """Test the constructor in FreeDoc"""
143  self.assertIs(self.free_doc_root.tree, tree_root)
144  self.assertIs(self.free_doc_left.tree, tree_left)
145  self.assertIs(self.free_doc_right.tree, tree_right)
146  self.assertIs(self.free_doc_leaf.tree, tree_leaf)
147  self.assertIs(self.free_doc_recursive.tree, tree_recursive)
148 
150  """Test the get_tree() method is FreeDoc"""
151  self.assertIs(self.free_doc_root.get_tree(), tree_root)
152  self.assertIs(self.free_doc_left.get_tree(), tree_left)
153  self.assertIs(self.free_doc_right.get_tree(), tree_right)
154  self.assertIs(self.free_doc_leaf.get_tree(), tree_leaf)
155  self.assertIs(self.free_doc_recursive.get_tree(), tree_recursive)
156 
157  def test_free_doc_eq(self):
158  """Test FreeDoc.__eq__"""
159  doc1 = FreeDoc(ET.ElementTree(a))
160  doc2 = FreeDoc(ET.ElementTree(d))
161  doc3 = FreeDoc(ET.ElementTree(d2))
162 
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)
169 
170  # Docs
171  def test_docs(self):
172  """Test Docs template constructor"""
173  docs = Docs(self.CLASS_DOCS, self.FREE_DOCS)
174 
175  self.assertIs(docs.class_docs, self.CLASS_DOCS)
176  self.assertIs(docs.free_docs, self.FREE_DOCS)
177 
179  docs = Docs(self.CLASS_DOCS, self.FREE_DOCS)
180 
181  for doc_name in self.CLASS_DOCS.keys():
182  self.assertIs(self.CLASS_DOCS.get(doc_name),
183  docs.get_class_docs(doc_name))
184 
186  docs = Docs(self.CLASS_DOCS, self.FREE_DOCS)
187 
188  for doc_name in self.FREE_DOCS.keys():
189  self.assertIs(self.FREE_DOCS.get(doc_name),
190  docs.get_free_docs(doc_name))
191 
193  docs = Docs(self.CLASS_DOCS, self.FREE_DOCS)
194  class_doc_keys = list(self.CLASS_DOCS)
195  docs_list = docs.get_class_docs_keys_list()
196 
197  self.assertEqual(len(self.CLASS_DOCS), len(docs_list))
198 
199  for key in class_doc_keys:
200  self.assertIn(key, docs_list)
201 
203  docs = Docs(self.CLASS_DOCS, self.FREE_DOCS)
204  free_doc_keys = list(self.FREE_DOCS)
205  docs_list = docs.get_free_docs_keys_list()
206 
207  self.assertEqual(len(self.FREE_DOCS), len(docs_list))
208 
209  for key in free_doc_keys:
210  self.assertIn(key, docs_list)
211 
213  docs = Docs(self.CLASS_DOCS, self.FREE_DOCS)
214  docs_list = docs.get_class_docs_values_list()
215 
216  self.assertEqual(len(self.CLASS_DOCS), len(docs_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)
222 
224  docs = Docs(self.CLASS_DOCS, self.FREE_DOCS)
225  docs_list = docs.get_free_docs_values_list()
226 
227  self.assertEqual(len(self.FREE_DOCS), len(docs_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)
233 
234 
235 if __name__ == "__main__":
236  unittest.main()
test_docs.TestDocTemplate.test_free_doc
def test_free_doc(self)
Definition: test_docs.py:141
test_docs.TestDocTemplate.test_free_doc_eq
def test_free_doc_eq(self)
Definition: test_docs.py:157
test_docs.TestDocTemplate.test_class_doc
def test_class_doc(self)
Definition: test_docs.py:111
test_docs.TestDocTemplate.free_doc_leaf
free_doc_leaf
Definition: test_docs.py:91
test_docs.TestDocument
Definition: test_docs.py:32
test_docs.TestDocument.DOC_DIR_PATH
DOC_DIR_PATH
Definition: test_docs.py:40
test_docs.TestDocument.EXPECTED_XML_DIR_PATH
EXPECTED_XML_DIR_PATH
Definition: test_docs.py:42
list
Definition: pytypes.h:2166
keys
const KeyVector keys
Definition: testRegularImplicitSchurFactor.cpp:40
test_docs.TestDocTemplate.test_class_doc_eq
def test_class_doc_eq(self)
Definition: test_docs.py:127
test_docs.TestDocTemplate.test_get_class_docs
def test_get_class_docs(self)
Definition: test_docs.py:178
test_docs.TestDocTemplate.test_get_class_docs_values_list
def test_get_class_docs_values_list(self)
Definition: test_docs.py:212
test_docs.TestDocTemplate.test_free_doc_get_tree
def test_free_doc_get_tree(self)
Definition: test_docs.py:149
test_docs.TestDocTemplate.class_doc_leaf
class_doc_leaf
Definition: test_docs.py:85
test_docs.TestDocTemplate.class_doc_left
class_doc_left
Definition: test_docs.py:83
test_docs.TestDocument.OUTPUT_XML_DIR_PATH
OUTPUT_XML_DIR_PATH
Definition: test_docs.py:41
test_docs.TestDocTemplate.free_doc_left
free_doc_left
Definition: test_docs.py:89
test_docs.TestDocTemplate.test_docs
def test_docs(self)
Definition: test_docs.py:171
test_docs.TestDocTemplate.free_doc_right
free_doc_right
Definition: test_docs.py:90
test_docs.TestDocTemplate.CLASS_DOCS
CLASS_DOCS
Definition: test_docs.py:94
test_docs.TestDocTemplate.free_doc_root
free_doc_root
Definition: test_docs.py:88
gtsam.examples.DogLegOptimizerExample.run
def run(args)
Definition: DogLegOptimizerExample.py:21
test_docs.TestDocTemplate.test_class_doc_get_tree
def test_class_doc_get_tree(self)
Definition: test_docs.py:119
test_docs.TestDocument.test_generate_xml
def test_generate_xml(self)
Definition: test_docs.py:44
test_docs.TestDocument.test_parse
def test_parse(self)
Definition: test_docs.py:67
test_docs.TestDocTemplate.free_doc_recursive
free_doc_recursive
Definition: test_docs.py:92
test_docs.TestDocTemplate.FREE_DOCS
FREE_DOCS
Definition: test_docs.py:102
test_docs.TestDocTemplate.test_get_free_docs_values_list
def test_get_free_docs_values_list(self)
Definition: test_docs.py:223
test_docs.TestDocTemplate.test_get_class_docs_keys_list
def test_get_class_docs_keys_list(self)
Definition: test_docs.py:192
test_docs.TestDocTemplate.test_get_free_docs_keys_list
def test_get_free_docs_keys_list(self)
Definition: test_docs.py:202
test_docs.TestDocTemplate.class_doc_root
class_doc_root
Definition: test_docs.py:82
len
size_t len(handle h)
Get the length of a Python object.
Definition: pytypes.h:2446
test_docs.TestDocTemplate.class_doc_recursive
class_doc_recursive
Definition: test_docs.py:86
test_docs.TestDocTemplate
Definition: test_docs.py:81
test_docs.TestDocTemplate.test_get_free_docs
def test_get_free_docs(self)
Definition: test_docs.py:185
get
Container::iterator get(Container &c, Position position)
Definition: stdlist_overload.cpp:29
test_docs.TestDocTemplate.class_doc_right
class_doc_right
Definition: test_docs.py:84


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:07:05