[pytango] 85/98: Mock _tango module to generate the documentation
Sandor Bodo-Merle
sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:17:48 UTC 2017
This is an automated email from the git hooks/post-receive script.
sbodomerle-guest pushed a commit to tag v9.2.0
in repository pytango.
commit 6a59f13ee9cc1fc28fb4ce2b083ffc41761d9a13
Author: Vincent Michel <vincent.michel at maxlab.lu.se>
Date: Mon Aug 15 18:09:48 2016 +0200
Mock _tango module to generate the documentation
---
doc/conf.py | 30 +++++++++----------
doc/mock_tango_extension.py | 70 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 85 insertions(+), 15 deletions(-)
diff --git a/doc/conf.py b/doc/conf.py
index f4d0efd..0db5714 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -13,17 +13,21 @@ import sys
import os
import re
-# tango imports
-import tango
-from tango import Release
-
-print("Building documentation for PyTango {0}".format(Release.version_long))
-print("Using PyTango from: {0}".format(os.path.dirname(tango.__file__)))
-
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
-#sys.path.append(os.path.abspath('sphinxext'))
+sys.path.append(os.path.abspath('../'))
+sys.path.append(os.path.abspath('./'))
+
+
+# Import tango
+try:
+ import tango
+except ImportError:
+ from mock_tango_extension import tango
+from tango import Release
+print("Building documentation for PyTango {0}".format(Release.version_long))
+print("Using PyTango from: {0}".format(os.path.dirname(tango.__file__)))
needs_sphinx = "1.0"
@@ -35,12 +39,8 @@ extensions = ['sphinx.ext.pngmath',
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
- 'sphinx.ext.todo']
-
-# disable until graphviz works in pyhon 3
-if sys.hexversion < 0x03000000:
- extensions.append('sphinx.ext.graphviz')
-
+ 'sphinx.ext.todo',
+ 'sphinx.ext.graphviz']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
@@ -256,7 +256,7 @@ intersphinx_mapping = {
'http://api.mongodb.org/python/current/' : None,
'http://packages.python.org/CouchDB/' : None,
'http://pycassa.github.com/pycassa/' : None,
- 'http://docs.sqlalchemy.org/en/rel_0_7/' : None,
+ 'http://docs.sqlalchemy.org/en/latest/' : None,
}
todo_include_todos = True
diff --git a/doc/mock_tango_extension.py b/doc/mock_tango_extension.py
new file mode 100644
index 0000000..3b8c1d2
--- /dev/null
+++ b/doc/mock_tango_extension.py
@@ -0,0 +1,70 @@
+__all__ = ['tango']
+
+# Imports
+import sys
+from mock import MagicMock
+
+
+# Extension mock class
+class ExtensionMock(MagicMock):
+ __doc__ = None
+ __mro__ = ()
+
+ @property
+ def __name__(self):
+ return self._mock_name.split('.')[-1]
+
+ def __getattr__(self, name):
+ # Limit device class discovery
+ if name == 'Device_6Impl':
+ raise AttributeError
+ # Emulate device class inheritance
+ if name == '__base__':
+ return {
+ 'Device_5Impl': _tango.Device_4Impl,
+ 'Device_4Impl': _tango.Device_3Impl,
+ 'Device_3Impl': _tango.Device_2Impl,
+ 'Device_2Impl': _tango.DeviceImpl,
+ 'DeviceImpl': object}[self.__name__]
+ # Regular mock behavior
+ return MagicMock.__getattr__(self, name)
+
+ def __setattr__(self, name, value):
+ # Ignore unsupported magic methods
+ if name in ["__init__", "__getattr__", "__setattr__"]:
+ return
+ # Hook in tango.base_types to patch document_enum
+ if name == '__getinitargs__' and self.__name__ == 'AttributeInfo':
+ import tango.base_types
+ tango.base_types.__dict__['__document_enum'] = document_enum
+ # Regular mock behavior
+ MagicMock.__setattr__(self, name, value)
+
+
+# Remove all public methods
+for name in dir(ExtensionMock):
+ if not name.startswith('_') and \
+ callable(getattr(ExtensionMock, name)):
+ setattr(ExtensionMock, name, None)
+
+
+# Patched version of document_enum
+def document_enum(klass, enum_name, desc, append=True):
+ getattr(klass, enum_name).__doc__ = desc
+
+
+# Patch the extension module
+_tango = ExtensionMock(name='_tango')
+_tango.constants.TgLibVers = "9.2.2"
+_tango._get_tango_lib_release.return_value = 922
+
+
+# Patch modules
+sys.modules['tango._tango'] = _tango
+sys.modules['tango.constants'] = _tango.constants
+print('Mocking tango._tango extension module')
+
+# Try to import
+import tango
+import tango.futures
+import tango.gevent
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/pytango.git
More information about the debian-science-commits
mailing list