Beispiel #1
0
 def setUp(self, properties=None):
     """Start Pool DS and register extensions.
     """
     db = PyTango.Database()
     # Discover the Pool launcher script
     poolExec = whichexecutable.whichfile("Pool")
     # register Pool server
     pool_ds_name = "Pool/" + self.pool_ds_name
     pool_free_ds_name = get_free_server(PyTango.Database(),
                                         pool_ds_name)
     self._starter = ProcessStarter(poolExec, pool_free_ds_name)
     # register Pool device
     dev_name_parts = self.pool_name.split('/')
     prefix = '/'.join(dev_name_parts[0:2])
     start_from = int(dev_name_parts[2])
     self.pool_name = get_free_device(db, prefix, start_from)
     self._starter.addNewDevice(self.pool_name, klass='Pool')
     # Add properties
     if properties is not None:
         for key, values in properties.items():
             db.put_device_property(self.pool_name,
                                    {key: values})
     # start Pool server
     self._starter.startDs()
     # register extensions so the test methods can use them
     self.pool = PyTango.DeviceProxy(self.pool_name)
Beispiel #2
0
 def setUp(self, pool_name):
     """Start MacroServer DS.
     """
     try:
         db = PyTango.Database()
         # Discover the MS launcher script
         msExec = whichexecutable.whichfile("MacroServer")
         # register MS server
         ms_ds_name = "MacroServer/" + self.ms_ds_name
         ms_free_ds_name = get_free_server(db, ms_ds_name)
         self._msstarter = ProcessStarter(msExec, ms_free_ds_name)
         # register MS device
         dev_name_parts = self.ms_name.split('/')
         prefix = '/'.join(dev_name_parts[0:2])
         start_from = int(dev_name_parts[2])
         self.ms_name = get_free_device(
             db, prefix, start_from)
         self._msstarter.addNewDevice(self.ms_name, klass='MacroServer')
         # register Door device
         dev_name_parts = self.door_name.split('/')
         prefix = '/'.join(dev_name_parts[0:2])
         start_from = int(dev_name_parts[2])
         self.door_name = get_free_device(db, prefix, start_from)
         self._msstarter.addNewDevice(self.door_name, klass='Door')
         db.put_device_property(self.ms_name, {'PoolNames': pool_name})
         # start MS server
         self._msstarter.startDs()
         self.door = PyTango.DeviceProxy(self.door_name)
     except Exception, e:
         # force tearDown in order to eliminate the MacroServer
         print e
         self.tearDown()
Beispiel #3
0
def taurus_test_ds():
    """
    A pytest fixture that launches TangoSchemeTest for the test
    It provides the device name as the fixture value.

    Usage::
        from taurus.core.tango.test import taurus_test_ds

        def test_foo(taurus_test_ds):
            import taurus
            d = taurus.Device(taurus_test_ds)
            assert d["string_scalar"].rvalue == "hello world"

    """
    ds_name = 'TangoSchemeTest/unittest/temp-{:08d}'.format(
        randint(0, 99999999))

    # get path to DS and executable
    device = getResourcePath('taurus.core.tango.test.res', 'TangoSchemeTest')
    # create starter for the device server
    _starter = ProcessStarter(device, 'TangoSchemeTest/unittest')
    # register
    _starter.addNewDevice(ds_name, klass='TangoSchemeTest')
    # start device server
    _starter.startDs()

    yield ds_name
    d = PyTango.DeviceProxy(ds_name)
    d.Reset()
    _starter.stopDs(hard_kill=True)
    # remove server
    _starter.cleanDb(force=True)
Beispiel #4
0
 def setUp(self):
     """Start Pool DS and register extensions.
     """
     # Discover the Pool launcher script
     poolExec = whichexecutable.whichfile("Pool")
     # register Pool server
     pool_ds_name = "Pool/" + self.pool_ds_name
     pool_free_ds_name = get_free_server(PyTango.Database(),
                                         pool_ds_name)
     self._starter = ProcessStarter(poolExec, pool_free_ds_name)
     # register Pool device
     dev_name_parts = self.pool_name.split('/')
     prefix = '/'.join(dev_name_parts[0:2])
     start_from = int(dev_name_parts[2])
     self.pool_name = get_free_device(
         PyTango.Database(), prefix, start_from)
     self._starter.addNewDevice(self.pool_name, klass='Pool')
     # start Pool server
     self._starter.startDs()
     # register extensions so the test methods can use them
     self.pool = PyTango.DeviceProxy(self.pool_name)
Beispiel #5
0
 def setUpClass(cls):
     """ Create and run a TangoSchemeTest device server
     """
     # get path to DS and executable
     device = getResourcePath('taurus.core.tango.test.res',
                              'TangoSchemeTest')
     # create starter for the device server
     cls._starter = ProcessStarter(device, 'TangoSchemeTest/unittest')
     # register
     cls._starter.addNewDevice(cls.DEV_NAME, klass='TangoSchemeTest')
     # start device server
     cls._starter.startDs()
Beispiel #6
0
    def setUp(self):
        '''
        Requisites:
         - instantiate the widget
         - make sure that the the timeout server is ready
        '''
        # Call base class setup (instantiate the widget,...)
        BaseWidgetTestCase.setUp(self)
        # get path to DS and executable
        timeoutExec = getResourcePath('taurus.qt.qtgui.button.test.res',
                                      'Timeout')
        # create starter for the Timeout server
        self._starter = ProcessStarter(timeoutExec, 'Timeout/unittest')
        # register timeoutserver  #TODO: guarantee that devname is not in use
        devname = 'unittests/timeout/temp-1'
        self._starter.addNewDevice(devname, klass='Timeout')
        # start Timeout server
        self._starter.startDs()

        # Configure the widget
        self._widget.setModel(devname)
Beispiel #7
0
class BasePoolTestCase(object):
    """Abstract class for pool DS testing.
    """
    pool_ds_name = getattr(sardanacustomsettings, 'UNITTEST_POOL_DS_NAME')
    pool_name = getattr(sardanacustomsettings, 'UNITTEST_POOL_NAME')

    def setUp(self):
        """Start Pool DS and register extensions.
        """
        # Discover the Pool launcher script
        poolExec = whichexecutable.whichfile("Pool")
        # register Pool server
        pool_ds_name = "Pool/" + self.pool_ds_name
        pool_free_ds_name = get_free_server(PyTango.Database(),
                                            pool_ds_name)
        self._starter = ProcessStarter(poolExec, pool_free_ds_name)
        # register Pool device
        dev_name_parts = self.pool_name.split('/')
        prefix = '/'.join(dev_name_parts[0:2])
        start_from = int(dev_name_parts[2])
        self.pool_name = get_free_device(
            PyTango.Database(), prefix, start_from)
        self._starter.addNewDevice(self.pool_name, klass='Pool')
        # start Pool server
        self._starter.startDs()
        # register extensions so the test methods can use them
        self.pool = PyTango.DeviceProxy(self.pool_name)

    def tearDown(self):
        """Remove the Pool instance.
        """
        self._starter.cleanDb(force=True)
        self._starter = None
        self.pool = None
        self.pool_name = None
Beispiel #8
0
    def setUp(self, properties=None):
        """
        Start MacroServer DS.

        :param properties: dictionary with the macroserver properies.

        """
        try:
            db = PyTango.Database()
            # Discover the MS launcher script
            msExec = whichexecutable.whichfile("MacroServer")
            # register MS server
            ms_ds_name_base = "MacroServer/" + self.ms_ds_name
            self.ms_ds_name = get_free_server(db, ms_ds_name_base)
            self._msstarter = ProcessStarter(msExec, self.ms_ds_name)
            # register MS device
            dev_name_parts = self.ms_name.split('/')
            prefix = '/'.join(dev_name_parts[0:2])
            start_from = int(dev_name_parts[2])
            self.ms_name = get_free_device(db, prefix, start_from)
            self._msstarter.addNewDevice(self.ms_name, klass='MacroServer')
            # register Door device
            dev_name_parts = self.door_name.split('/')
            prefix = '/'.join(dev_name_parts[0:2])
            start_from = int(dev_name_parts[2])
            self.door_name = get_free_device(db, prefix, start_from)
            self._msstarter.addNewDevice(self.door_name, klass='Door')
            # Add properties
            if properties:
                for key, values in list(properties.items()):
                    db.put_device_property(self.ms_name, {key: values})
            # start MS server
            self._msstarter.startDs(wait_seconds=20)
            self.door = PyTango.DeviceProxy(self.door_name)
        except Exception as e:
            # force tearDown in order to eliminate the MacroServer
            print(e)
            self.tearDown()
Beispiel #9
0
class BaseMacroServerTestCase(object):
    """Abstract class for macroserver DS testing.
    """
    ms_ds_name = getattr(sardanacustomsettings, 'UNITTEST_MS_DS_NAME',
                         "unittest1")
    ms_name = getattr(sardanacustomsettings, 'UNITTEST_MS_NAME',
                      "macroserver/demo1/1")
    door_name = getattr(sardanacustomsettings, 'UNITTEST_DOOR_NAME',
                        "door/demo1/1")

    def setUp(self, properties=None):
        """
        Start MacroServer DS.

        :param properties: dictionary with the macroserver properies.

        """
        try:
            db = PyTango.Database()
            # Discover the MS launcher script
            msExec = whichexecutable.whichfile("MacroServer")
            # register MS server
            ms_ds_name_base = "MacroServer/" + self.ms_ds_name
            self.ms_ds_name = get_free_server(db, ms_ds_name_base)
            self._msstarter = ProcessStarter(msExec, self.ms_ds_name)
            # register MS device
            dev_name_parts = self.ms_name.split('/')
            prefix = '/'.join(dev_name_parts[0:2])
            start_from = int(dev_name_parts[2])
            self.ms_name = get_free_device(
                db, prefix, start_from)
            self._msstarter.addNewDevice(self.ms_name, klass='MacroServer')
            # register Door device
            dev_name_parts = self.door_name.split('/')
            prefix = '/'.join(dev_name_parts[0:2])
            start_from = int(dev_name_parts[2])
            self.door_name = get_free_device(db, prefix, start_from)
            self._msstarter.addNewDevice(self.door_name, klass='Door')
            # Add properties
            if properties:
                for key, values in properties.items():
                    db.put_device_property(self.ms_name,
                                           {key: values})
            # start MS server
            self._msstarter.startDs()
            self.door = PyTango.DeviceProxy(self.door_name)
        except Exception, e:
            # force tearDown in order to eliminate the MacroServer
            print e
            self.tearDown()
Beispiel #10
0
    def setUp(self):
        '''
        Requisites:
         - instantiate the widget
         - make sure that the the timeout server is ready
        '''
        # Call base class setup (instantiate the widget,...)
        BaseWidgetTestCase.setUp(self)
        # get path to DS and executable
        timeoutExec = getResourcePath('taurus.qt.qtgui.button.test.res',
                                      'Timeout')
        # create starter for the Timeout server
        self._starter = ProcessStarter(timeoutExec, 'Timeout/unittest')
        # register timeoutserver  #TODO: guarantee that devname is not in use
        devname = 'unittests/timeout/temp-1'
        self._starter.addNewDevice(devname, klass='Timeout')
        # start Timeout server
        self._starter.startDs()

        # Configure the widget
        self._widget.setModel(devname)
Beispiel #11
0
class BaseMacroServerTestCase(object):
    """Abstract class for macroserver DS testing.
    """
    ms_ds_name = getattr(sardanacustomsettings, 'UNITTEST_MS_DS_NAME',
                         "unittest1")
    ms_name = getattr(sardanacustomsettings, 'UNITTEST_MS_NAME',
                      "macroserver/demo1/1")
    door_name = getattr(sardanacustomsettings, 'UNITTEST_DOOR_NAME',
                        "door/demo1/1")

    def setUp(self, properties=None):
        """
        Start MacroServer DS.

        :param properties: dictionary with the macroserver properies.

        """
        try:
            db = PyTango.Database()
            # Discover the MS launcher script
            msExec = whichexecutable.whichfile("MacroServer")
            # register MS server
            ms_ds_name_base = "MacroServer/" + self.ms_ds_name
            self.ms_ds_name = get_free_server(db, ms_ds_name_base)
            self._msstarter = ProcessStarter(msExec, self.ms_ds_name)
            # register MS device
            dev_name_parts = self.ms_name.split('/')
            prefix = '/'.join(dev_name_parts[0:2])
            start_from = int(dev_name_parts[2])
            self.ms_name = get_free_device(db, prefix, start_from)
            self._msstarter.addNewDevice(self.ms_name, klass='MacroServer')
            # register Door device
            dev_name_parts = self.door_name.split('/')
            prefix = '/'.join(dev_name_parts[0:2])
            start_from = int(dev_name_parts[2])
            self.door_name = get_free_device(db, prefix, start_from)
            self._msstarter.addNewDevice(self.door_name, klass='Door')
            # Add properties
            if properties:
                for key, values in properties.items():
                    db.put_device_property(self.ms_name, {key: values})
            # start MS server
            self._msstarter.startDs()
            self.door = PyTango.DeviceProxy(self.door_name)
        except Exception, e:
            # force tearDown in order to eliminate the MacroServer
            print e
            self.tearDown()
Beispiel #12
0
    def setUp(self, properties=None):
        """
        Start MacroServer DS.

        :param properties: dictionary with the macroserver properies.

        """
        try:
            db = PyTango.Database()
            # Discover the MS launcher script
            msExec = whichexecutable.whichfile("MacroServer")
            # register MS server
            ms_ds_name_base = "MacroServer/" + self.ms_ds_name
            self.ms_ds_name = get_free_server(db, ms_ds_name_base)
            self._msstarter = ProcessStarter(msExec, self.ms_ds_name)
            # register MS device
            dev_name_parts = self.ms_name.split('/')
            prefix = '/'.join(dev_name_parts[0:2])
            start_from = int(dev_name_parts[2])
            self.ms_name = get_free_device(
                db, prefix, start_from)
            self._msstarter.addNewDevice(self.ms_name, klass='MacroServer')
            # register Door device
            dev_name_parts = self.door_name.split('/')
            prefix = '/'.join(dev_name_parts[0:2])
            start_from = int(dev_name_parts[2])
            self.door_name = get_free_device(db, prefix, start_from)
            self._msstarter.addNewDevice(self.door_name, klass='Door')
            # Add properties
            if properties:
                for key, values in properties.items():
                    db.put_device_property(self.ms_name,
                                           {key: values})
            # start MS server
            self._msstarter.startDs()
            self.door = PyTango.DeviceProxy(self.door_name)
        except Exception, e:
            # force tearDown in order to eliminate the MacroServer
            print e
            self.tearDown()
Beispiel #13
0
class TaurusCommandButtonTest2(BaseWidgetTestCase, unittest.TestCase):

    _klass = TaurusCommandButton
    initkwargs = dict(command='TimeoutCmd')

    def setUp(self):
        '''
        Requisites:
         - instantiate the widget
         - make sure that the the timeout server is ready
        '''
        # Call base class setup (instantiate the widget,...)
        BaseWidgetTestCase.setUp(self)
        # get path to DS and executable
        timeoutExec = getResourcePath('taurus.qt.qtgui.button.test.res',
                                      'Timeout')
        # create starter for the Timeout server
        self._starter = ProcessStarter(timeoutExec, 'Timeout/unittest')
        # register timeoutserver  #TODO: guarantee that devname is not in use
        devname = 'unittests/timeout/temp-1'
        self._starter.addNewDevice(devname, klass='Timeout')
        # start Timeout server
        self._starter.startDs()

        # Configure the widget
        self._widget.setModel(devname)

    def tearDown(self):
        '''Stop the timeout server and undo changes to the database'''

        self._widget.setModel(None)
        # remove timeoutserver
        self._starter.cleanDb(force=True)

    def testTimeOutError(self):
        '''Check that the timeout property works'''
        # lets use commands that take at least 200ms in returning
        self._widget.setParameters([.2])
        # With a long timeout it should work...
        self._widget.setTimeout(10)
        ret = self._widget._onClicked()
        msg = 'expected return None when timeout >> command response time'
        self.assertIsNone(ret, msg)
        #...but with a shorter timeout we expect a timeout exception
        self._widget.setTimeout(.1)
        self.assertRaises(CommunicationFailed, self._widget._onClicked)
Beispiel #14
0
class TaurusCommandButtonTest2(BaseWidgetTestCase, unittest.TestCase):

    _klass = TaurusCommandButton
    initkwargs = dict(command='TimeoutCmd')

    def setUp(self):
        '''
        Requisites:
         - instantiate the widget
         - make sure that the the timeout server is ready
        '''
        # Call base class setup (instantiate the widget,...)
        BaseWidgetTestCase.setUp(self)
        # get path to DS and executable
        timeoutExec = getResourcePath('taurus.qt.qtgui.button.test.res',
                                      'Timeout')
        # create starter for the Timeout server
        self._starter = ProcessStarter(timeoutExec, 'Timeout/unittest')
        # register timeoutserver  #TODO: guarantee that devname is not in use
        devname = 'unittests/timeout/temp-1'
        self._starter.addNewDevice(devname, klass='Timeout')
        # start Timeout server
        self._starter.startDs()

        # Configure the widget
        self._widget.setModel(devname)

    def tearDown(self):
        '''Stop the timeout server and undo changes to the database'''

        self._widget.setModel(None)
        # remove timeoutserver
        self._starter.cleanDb(force=True)

    def testTimeOutError(self):
        '''Check that the timeout property works'''
        # lets use commands that take at least 200ms in returning
        self._widget.setParameters([.2])
        # With a long timeout it should work...
        self._widget.setTimeout(10)
        ret = self._widget._onClicked()
        msg = 'expected return None when timeout >> command response time'
        self.assertIsNone(ret, msg)
        #...but with a shorter timeout we expect a timeout exception
        self._widget.setTimeout(.1)
        self.assertRaises(CommunicationFailed, self._widget._onClicked)
Beispiel #15
0
class BaseMacroServerTestCase(object):
    """Abstract class for macroserver DS testing.
    """
    ms_ds_name = getattr(sardanacustomsettings, 'UNITTEST_MS_DS_NAME',
                         "unittest1")
    ms_name = getattr(sardanacustomsettings, 'UNITTEST_MS_NAME',
                      "macroserver/demo1/1")
    door_name = getattr(sardanacustomsettings, 'UNITTEST_DOOR_NAME',
                        "door/demo1/1")

    def setUp(self, properties=None):
        """
        Start MacroServer DS.

        :param properties: dictionary with the macroserver properies.

        """
        try:
            db = PyTango.Database()
            # Discover the MS launcher script
            msExec = whichexecutable.whichfile("MacroServer")
            # register MS server
            ms_ds_name_base = "MacroServer/" + self.ms_ds_name
            self.ms_ds_name = get_free_server(db, ms_ds_name_base)
            self._msstarter = ProcessStarter(msExec, self.ms_ds_name)
            # register MS device
            dev_name_parts = self.ms_name.split('/')
            prefix = '/'.join(dev_name_parts[0:2])
            start_from = int(dev_name_parts[2])
            self.ms_name = get_free_device(db, prefix, start_from)
            self._msstarter.addNewDevice(self.ms_name, klass='MacroServer')
            # register Door device
            dev_name_parts = self.door_name.split('/')
            prefix = '/'.join(dev_name_parts[0:2])
            start_from = int(dev_name_parts[2])
            self.door_name = get_free_device(db, prefix, start_from)
            self._msstarter.addNewDevice(self.door_name, klass='Door')
            # Add properties
            if properties:
                for key, values in list(properties.items()):
                    db.put_device_property(self.ms_name, {key: values})
            # start MS server
            self._msstarter.startDs(wait_seconds=20)
            self.door = PyTango.DeviceProxy(self.door_name)
        except Exception as e:
            # force tearDown in order to eliminate the MacroServer
            print(e)
            self.tearDown()

    def tearDown(self):
        """Remove the MacroServer instance and its properties file.
        """

        self._msstarter.cleanDb(force=True)
        self._msstarter = None
        self.macroserver = None
        self.door = None

        db = PyTango.Database()
        prop = db.get_device_property(self.ms_name, "EnvironmentDb")
        ms_properties = prop["EnvironmentDb"]
        if not ms_properties:
            dft_ms_properties = os.path.join(
                MacroServerClass.DefaultEnvBaseDir,
                MacroServerClass.DefaultEnvRelDir)
            ds_inst_name = self.ms_ds_name.split("/")[1]
            ms_properties = dft_ms_properties % {
                "ds_exec_name": "MacroServer",
                "ds_inst_name": ds_inst_name
            }
        ms_properties = os.path.normpath(ms_properties)
        extensions = [".bak", ".dat", ".dir"]
        for ext in extensions:
            name = ms_properties + ext
            if not os.path.exists(name):
                continue
            try:
                os.remove(name)
            except Exception as e:
                msg = "Not possible to remove macroserver environment file"
                print(msg)
                print(("Details: %s" % e))