[pytango] 87/98: Refactor mock_tango_extension module

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 d7a7e4f2a393e22c00684a219e02cf4515d57228
Author: Vincent Michel <vincent.michel at maxlab.lu.se>
Date:   Tue Aug 16 17:04:43 2016 +0200

    Refactor mock_tango_extension module
---
 doc/mock_tango_extension.py | 40 +++++++++++++++++++++++++++++++++++-----
 1 file changed, 35 insertions(+), 5 deletions(-)

diff --git a/doc/mock_tango_extension.py b/doc/mock_tango_extension.py
index 3b8c1d2..33a90c6 100644
--- a/doc/mock_tango_extension.py
+++ b/doc/mock_tango_extension.py
@@ -1,17 +1,48 @@
+"""Mock the tango._tango extension module.
+
+This is useful to build the documentation without building the extension.
+However this is a bit tricky since the python side relies on what the
+extension exposes. Here is the list of the mocking aspects that require
+special attention:
+- __doc__ should not contain the mock documentation
+- __mro__ is required for autodoc
+- __name__ attribute is required
+- Device_6Impl class should not be accessible
+- the __base__ attribute for Device_[X]Impl is required
+- it shoud be possible to set __init__, __getattr__ and __setattr__ methods
+- tango.base_types.__document_enum needs to be patched before it is called
+- the mocks should not have any public methods such as assert_[...]
+- _tango.constants.TgLibVers is required (e.g. '9.2.2')
+- _tango._get_tango_lib_release function is required (e.g. lambda: 922)
+- tango._tango AND tango.constants modules have to be patched
+
+Patching tango._tango using sys.modules does not seem to work for python
+version older than 3.5 (failed with 2.7 and 3.4)
+"""
+
 __all__ = ['tango']
 
 # Imports
 import sys
 from mock import MagicMock
 
+# Constants
+TANGO_VERSION = '9.2.2'
+TANGO_VERSION_INT = int(TANGO_VERSION[::2])
+
 
 # Extension mock class
 class ExtensionMock(MagicMock):
+
+    # Remove the mock documentation
     __doc__ = None
-    __mro__ = ()
+
+    # The method resolution order is required for autodoc
+    __mro__ = object,
 
     @property
     def __name__(self):
+        # __name__ is used for some objects
         return self._mock_name.split('.')[-1]
 
     def __getattr__(self, name):
@@ -55,8 +86,8 @@ def document_enum(klass, enum_name, desc, append=True):
 
 # Patch the extension module
 _tango = ExtensionMock(name='_tango')
-_tango.constants.TgLibVers = "9.2.2"
-_tango._get_tango_lib_release.return_value = 922
+_tango.constants.TgLibVers = TANGO_VERSION
+_tango._get_tango_lib_release.return_value = TANGO_VERSION_INT
 
 
 # Patch modules
@@ -64,7 +95,6 @@ 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