summaryrefslogtreecommitdiff
path: root/tests/test_ext_inheritance.py
diff options
context:
space:
mode:
authorMr. Senko <atodorov@mrsenko.com>2016-01-21 11:13:29 +0200
committerMr. Senko <atodorov@mrsenko.com>2017-06-05 21:52:21 +0300
commit72e70b1b361a649f1e81ed4ed29cbb8a31024563 (patch)
tree5e125a081a5d41afeed6a138e714450f5d5fcd01 /tests/test_ext_inheritance.py
parent5e2d4ca77b0d940d07d21de7272221b06b3b933c (diff)
downloadsphinx-git-72e70b1b361a649f1e81ed4ed29cbb8a31024563.tar.gz
Add tests for sphinx.ext.inheritance_diagram
Diffstat (limited to 'tests/test_ext_inheritance.py')
-rw-r--r--tests/test_ext_inheritance.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/test_ext_inheritance.py b/tests/test_ext_inheritance.py
new file mode 100644
index 000000000..ce4b50a56
--- /dev/null
+++ b/tests/test_ext_inheritance.py
@@ -0,0 +1,67 @@
+# -*- coding: utf-8 -*-
+"""
+ test_inheritance
+ ~~~~~~~~~~~~~~~~
+
+ Tests for :mod:`sphinx.ext.inheritance_diagram` module.
+
+ :copyright: Copyright 2015 by the Sphinx team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+import os
+import pytest
+from sphinx.ext.inheritance_diagram import InheritanceDiagram
+
+@pytest.mark.sphinx(buildername="html", testroot="inheritance")
+@pytest.mark.usefixtures('if_graphviz_found')
+def test_inheritance_diagram(app, status, warning):
+ # monkey-patch InheritaceDiagram.run() so we can get access to its
+ # results.
+ orig_run = InheritanceDiagram.run
+ graphs = {}
+
+ def new_run(self):
+ result = orig_run(self)
+ node = result[0]
+ source = os.path.basename(node.document.current_source).replace(".rst", "")
+ graphs[source] = node['graph']
+ return result
+
+ InheritanceDiagram.run = new_run
+
+ try:
+ app.builder.build_all()
+ finally:
+ InheritanceDiagram.run = orig_run
+
+ assert app.statuscode == 0
+
+ html_warnings = warning.getvalue()
+ assert html_warnings == ""
+
+ # note: it is better to split these asserts into separate test functions
+ # but I can't figure out how to build only a specific .rst file
+
+ # basic inheritance diagram showing all classes
+ for cls in graphs['basic_diagram'].class_info:
+ # use in b/c traversing order is different sometimes
+ assert cls in [
+ ('dummy.test.A', 'dummy.test.A', [], None),
+ ('dummy.test.F', 'dummy.test.F', ['dummy.test.C'], None),
+ ('dummy.test.C', 'dummy.test.C', ['dummy.test.A'], None),
+ ('dummy.test.E', 'dummy.test.E', ['dummy.test.B'], None),
+ ('dummy.test.D', 'dummy.test.D', ['dummy.test.B', 'dummy.test.C'], None),
+ ('dummy.test.B', 'dummy.test.B', ['dummy.test.A'], None)
+ ]
+
+ # inheritance diagram using :parts: 1 option
+ for cls in graphs['diagram_w_parts'].class_info:
+ assert cls in [
+ ('A', 'dummy.test.A', [], None),
+ ('F', 'dummy.test.F', ['C'], None),
+ ('C', 'dummy.test.C', ['A'], None),
+ ('E', 'dummy.test.E', ['B'], None),
+ ('D', 'dummy.test.D', ['B', 'C'], None),
+ ('B', 'dummy.test.B', ['A'], None)
+ ]