Beispiel #1
0
    def _test_array_callback(self, arrayname, array_type, length, element_type):
        """ Helper function to subscribe to a PV array and check it
        receives at least one subscription callback w/ specified type,
        length & uniform element type. Checks separately for normal,
        TIME & CTRL subscription variants. Returns the array or fails
        an assertion."""
        results = {}
        for form in [ 'normal', 'time', 'ctrl' ]:
            chid = ca.create_channel(arrayname,connect=True)
            cb, uarg, eventID = ca.create_subscription(chid, use_time=form=='time', use_ctrl=form=='ctrl', callback=onChanges)

            CHANGE_DAT.pop(arrayname, None)
            timeout=0
            # wait up to 6 seconds, if no callback probably due to simulator.py
            # not running...
            while timeout<120 and not arrayname in CHANGE_DAT:
                time.sleep(0.05)
                timeout = timeout+1
            val = CHANGE_DAT.get(arrayname, None)
            ca.clear_subscription(eventID)
            self.assertIsNot(val, None)
            self.assertEqual(type(val), array_type)
            self.assertEqual(len(val), length)
            self.assertEqual(type(val[0]), element_type)
            self.assertTrue(all( type(e)==element_type for e in val))
            results[form] = val
        return results
Beispiel #2
0
    def _test_array_callback(self, arrayname, array_type, length, element_type):
        """ Helper function to subscribe to a PV array and check it
        receives at least one subscription callback w/ specified type,
        length & uniform element type. Checks separately for normal,
        TIME & CTRL subscription variants. Returns the array or fails
        an assertion."""
        results = {}
        for form in [ 'normal', 'time', 'ctrl' ]:
            chid = ca.create_channel(arrayname,connect=True)
            cb, uarg, eventID = ca.create_subscription(chid, use_time=form=='time', use_ctrl=form=='ctrl', callback=onChanges)

            CHANGE_DAT.pop(arrayname, None)
            timeout=0
            # wait up to 6 seconds, if no callback probably due to simulator.py
            # not running...
            while timeout<120 and not arrayname in CHANGE_DAT:
                time.sleep(0.05)
                timeout = timeout+1
            val = CHANGE_DAT.get(arrayname, None)
            ca.clear_subscription(eventID)
            self.assertIsNot(val, None)
            self.assertEqual(type(val), array_type)
            self.assertEqual(len(val), length)
            self.assertEqual(type(val[0]), element_type)
            self.assertTrue(all( type(e)==element_type for e in val))
            results[form] = val
        return results
Beispiel #3
0
    def test_subscription_double(self):
        pvn = pvnames.updating_pv1
        chid = ca.create_channel(pvn,connect=True)
        cb, uarg, eventID = ca.create_subscription(chid, callback=onChanges)

        start_time = time.time()
        global CHANGE_DAT
        while time.time()-start_time < 5.0:
            time.sleep(0.01)
            if CHANGE_DAT.get(pvn, None) is not None:
                break
        val = CHANGE_DAT.get(pvn, None)
        ca.clear_subscription(eventID)
        self.assertIsNot(val, None)
Beispiel #4
0
    def test_subscription_double(self):
        pvn = pvnames.updating_pv1
        chid = ca.create_channel(pvn,connect=True)
        cb, uarg, eventID = ca.create_subscription(chid, callback=onChanges)

        start_time = time.time()
        global CHANGE_DAT
        while time.time()-start_time < 5.0:
            time.sleep(0.01)
            if CHANGE_DAT.get(pvn, None) is not None:
                break
        val = CHANGE_DAT.get(pvn, None)
        ca.clear_subscription(eventID)
        self.assertNotEqual(val, None)
Beispiel #5
0
    def test_subscription_custom(self):
        pvn = pvnames.updating_pv1
        chid = ca.create_channel(pvn, connect=True)

        global change_count
        change_count = 0

        def my_callback(pvname=None, value=None, **kws):
            write( ' Custom Callback  %s  value=%s' %(pvname, str(value)))
            global change_count
            change_count = change_count + 1

        cb, uarg, eventID = ca.create_subscription(chid, callback=my_callback)

        start_time = time.time()
        while time.time()-start_time < 2.0:
            time.sleep(0.01)

        ca.clear_subscription(eventID)
        time.sleep(0.2)
        self.assertTrue(change_count > 2)
Beispiel #6
0
    def test_subscription_custom(self):
        pvn = pvnames.updating_pv1
        chid = ca.create_channel(pvn, connect=True)

        global change_count
        change_count = 0

        def my_callback(pvname=None, value=None, **kws):
            write( ' Custom Callback  %s  value=%s' %(pvname, str(value)))
            global change_count
            change_count = change_count + 1

        cb, uarg, eventID = ca.create_subscription(chid, callback=my_callback)

        start_time = time.time()
        while time.time()-start_time < 2.0:
            time.sleep(0.01)

        ca.clear_subscription(eventID)
        time.sleep(0.2)
        self.assertTrue(change_count > 2)