[pytango] 88/122: Update tango extension mock

Sandor Bodo-Merle sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:18:21 UTC 2017


This is an automated email from the git hooks/post-receive script.

sbodomerle-guest pushed a commit to tag v9.2.1
in repository pytango.

commit 20366d551aa4cd4fd99fc2902412bc24a5ecc13f
Author: Vincent Michel <vincent.michel at maxlab.lu.se>
Date:   Thu Nov 17 11:24:14 2016 +0100

    Update tango extension mock
---
 doc/mock_tango_extension.py | 71 +++++++++++++++++++++++++++++----------------
 1 file changed, 46 insertions(+), 25 deletions(-)

diff --git a/doc/mock_tango_extension.py b/doc/mock_tango_extension.py
index 33a90c6..8e528b9 100644
--- a/doc/mock_tango_extension.py
+++ b/doc/mock_tango_extension.py
@@ -4,28 +4,32 @@ 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
+
+  - __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
+  - tango.base_types.__document_method 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
+  - autodoc requires a proper inheritance for the device impl classes
 
 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
 
+__all__ = ['tango']
+
+
 # Constants
 TANGO_VERSION = '9.2.2'
 TANGO_VERSION_INT = int(TANGO_VERSION[::2])
@@ -43,32 +47,31 @@ class ExtensionMock(MagicMock):
     @property
     def __name__(self):
         # __name__ is used for some objects
+        if self._mock_name is None:
+            return ''
         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__"]:
+        if name in ["__init__", "__getattr__", "__setattr__",
+                    "__str__", "__repr__"]:
             return
-        # Hook in tango.base_types to patch document_enum
-        if name == '__getinitargs__' and self.__name__ == 'AttributeInfo':
+        # Hook as soon as possible and patch the documentation methods
+        if name == 'side_effect' and self.__name__ == 'AccessControlType':
+            import tango.utils
             import tango.base_types
+            import tango.device_server
+            tango.utils.__dict__['document_enum'] = document_enum
+            tango.utils.__dict__['document_method'] = document_method
             tango.base_types.__dict__['__document_enum'] = document_enum
-        # Regular mock behavior
+            tango.device_server.__dict__['__document_method'] = document_method
         MagicMock.__setattr__(self, name, value)
 
 
@@ -84,10 +87,28 @@ def document_enum(klass, enum_name, desc, append=True):
     getattr(klass, enum_name).__doc__ = desc
 
 
+# Patched version of document_enum
+def document_method(klass, name, doc, add=True):
+    method = lambda self: None
+    method.__doc__ = doc
+    method.__name__ = name
+    setattr(klass, name, method)
+
+
+# Use empty classes for device impl inheritance scheme
+def set_device_implementations(module):
+    module.DeviceImpl = type('DeviceImpl', (object,), {})
+    module.Device_2Impl = type('Device_2Impl', (module.DeviceImpl,), {})
+    module.Device_3Impl = type('Device_3Impl', (module.Device_2Impl,), {})
+    module.Device_4Impl = type('Device_4Impl', (module.Device_3Impl,), {})
+    module.Device_5Impl = type('Device_5Impl', (module.Device_4Impl,), {})
+
+
 # Patch the extension module
 _tango = ExtensionMock(name='_tango')
 _tango.constants.TgLibVers = TANGO_VERSION
 _tango._get_tango_lib_release.return_value = TANGO_VERSION_INT
+set_device_implementations(_tango)
 
 
 # Patch modules

-- 
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