[pytango] 64/122: Run server for tests for all green modes

Sandor Bodo-Merle sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:18:18 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 1feb8113717e706ebc0571646d9b768eccac9a3e
Author: Vincent Michel <vincent.michel at maxlab.lu.se>
Date:   Wed Oct 12 16:26:08 2016 +0200

    Run server for tests for all green modes
---
 test/test_server.py | 75 +++++++++++++++++++++--------------------------------
 1 file changed, 30 insertions(+), 45 deletions(-)

diff --git a/test/test_server.py b/test/test_server.py
index 7ef39b1..a163875 100644
--- a/test/test_server.py
+++ b/test/test_server.py
@@ -3,66 +3,46 @@
 import pytest
 from six import add_metaclass
 
-import tango
-from tango import DevState, AttrWriteType, utils
+from tango import GreenMode
+from tango import DevState, AttrWriteType
 from tango.server import Device, DeviceMeta
 from tango.server import command, attribute, device_property
+from tango.test_utils import DeviceTestContext
 
-from context import TangoTestContext
-
-
-# Fixtures
-
- at pytest.fixture(params=DevState.values.values())
-def state(request):
-    return request.param
-
-
- at pytest.fixture(params=utils._scalar_types)
-def type_value(request):
-    dtype = request.param
-    # Unsupported types
-    if dtype in [tango.DevInt, tango.ConstDevString,
-                 tango.DevEncoded, tango.DevUChar]:
-        pytest.xfail('Should we support those types?')
-    # Supported types
-    if dtype in utils._scalar_str_types:
-        return dtype, ['hey hey', 'my my']
-    if dtype in utils._scalar_bool_types:
-        return dtype, [False, True]
-    if dtype in utils._scalar_int_types:
-        return dtype, [1, 2]
-    if dtype in utils._scalar_float_types:
-        return dtype, [2.71, 3.14]
+# Pytest fixtures
+from tango.test_utils import state, typed_values, server_green_mode
+state, typed_values, server_green_mode
 
 
 # Test state/status
 
-def test_empty_device():
+def test_empty_device(server_green_mode):
 
     @add_metaclass(DeviceMeta)
     class TestDevice(Device):
-        pass
+        green_mode = server_green_mode
 
-    with TangoTestContext(TestDevice) as proxy:
+    with DeviceTestContext(TestDevice) as proxy:
         assert proxy.state() == DevState.UNKNOWN
         assert proxy.status() == 'The device is in UNKNOWN state.'
 
 
-def test_set_state(state):
+def test_set_state(state, server_green_mode):
     status = 'The device is in {0!s} state.'.format(state)
 
     @add_metaclass(DeviceMeta)
     class TestDevice(Device):
+        green_mode = server_green_mode
+
         def init_device(self):
             self.set_state(state)
 
-    with TangoTestContext(TestDevice) as proxy:
+    with DeviceTestContext(TestDevice) as proxy:
         assert proxy.state() == state
         assert proxy.status() == status
 
 
-def test_set_status():
+def test_set_status(server_green_mode):
 
     status = '\n'.join((
         "This is a multiline status",
@@ -71,28 +51,31 @@ def test_set_status():
 
     @add_metaclass(DeviceMeta)
     class TestDevice(Device):
+        green_mode = server_green_mode
+
         def init_device(self):
             self.set_state(DevState.ON)
             self.set_status(status)
 
-    with TangoTestContext(TestDevice) as proxy:
+    with DeviceTestContext(TestDevice) as proxy:
         assert proxy.state() == DevState.ON
         assert proxy.status() == status
 
 
 # Test commands
 
-def test_identity_command(type_value):
-    dtype, values = type_value
+def test_identity_command(typed_values, server_green_mode):
+    dtype, values = typed_values
 
     @add_metaclass(DeviceMeta)
     class TestDevice(Device):
+        green_mode = server_green_mode
 
         @command(dtype_in=dtype, dtype_out=dtype)
         def identity(self, arg):
             return arg
 
-    with TangoTestContext(TestDevice) as proxy:
+    with DeviceTestContext(TestDevice) as proxy:
         for value in values:
             expected = pytest.approx(value)
             assert proxy.identity(value) == expected
@@ -100,11 +83,12 @@ def test_identity_command(type_value):
 
 # Test attributes
 
-def test_read_write_attribute(type_value):
-    dtype, values = type_value
+def test_read_write_attribute(typed_values, server_green_mode):
+    dtype, values = typed_values
 
     @add_metaclass(DeviceMeta)
     class TestDevice(Device):
+        green_mode = server_green_mode
 
         @attribute(dtype=dtype, access=AttrWriteType.READ_WRITE)
         def attr(self):
@@ -114,7 +98,7 @@ def test_read_write_attribute(type_value):
         def attr(self, value):
             self.attr_value = value
 
-    with TangoTestContext(TestDevice) as proxy:
+    with DeviceTestContext(TestDevice) as proxy:
         for value in values:
             proxy.attr = value
             expected = pytest.approx(value)
@@ -124,13 +108,14 @@ def test_read_write_attribute(type_value):
 # Test properties
 
 @pytest.fixture
-def device_with_property(type_value):
-    dtype, values = type_value
+def device_with_property(typed_values, server_green_mode):
+    dtype, values = typed_values
     default = values[0]
     other = values[1]
 
     @add_metaclass(DeviceMeta)
     class TestDevice(Device):
+        green_mode = server_green_mode
 
         prop = device_property(dtype=dtype, default_value=default)
 
@@ -143,7 +128,7 @@ def device_with_property(type_value):
 
 def test_default_property(device_with_property):
     TestDevice, default, _ = device_with_property
-    with TangoTestContext(TestDevice) as proxy:
+    with DeviceTestContext(TestDevice) as proxy:
         expected = pytest.approx(default)
         assert proxy.get_prop() == expected
 
@@ -151,6 +136,6 @@ def test_default_property(device_with_property):
 def test_device_property(device_with_property):
     TestDevice, _, value = device_with_property
     properties = {'prop': value}
-    with TangoTestContext(TestDevice, properties=properties) as proxy:
+    with DeviceTestContext(TestDevice, properties=properties) as proxy:
         expected = pytest.approx(value)
         assert proxy.get_prop() == expected

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