Beispiel #1
0
 def get(self):
     modename = self.get_argument("mode", None)
     if modename:
         apvs = dict(controller.list_by_mode(modename))
     else:
         apvs = dict(controller.list_subscribed())
     self.win(apvs)
Beispiel #2
0
    def test_list_subscribed_only(self):
        controller.subscribe('DEFAULT.PV', SubscriptionMode.Monitor(delta=0.01)).wait()
        controller.subscribe('FOO.PV', SubscriptionMode.Monitor(delta=0.123)).wait()
        controller.subscribe('BAR.PV', SubscriptionMode.Scan(period=123.1) ).wait()

        subscribed = dict(controller.list_subscribed())
        self.assertItemsEqual(subscribed.keys(), ['BAR.PV', 'DEFAULT.PV', 'FOO.PV'])

        controller.unsubscribe('FOO.PV').wait()
        
        subscribed = dict(controller.list_subscribed())
        self.assertItemsEqual(subscribed.keys(), ['BAR.PV', 'DEFAULT.PV'])

        # yet 'FOO.PV' is still present in the archive
        arched = dict(controller.list_archived(False))
        self.assertItemsEqual(arched.keys(), ['FOO.PV'])
Beispiel #3
0
    def test_munsubscribe(self):
        controller.subscribe('DEFAULT.PV', SubscriptionMode.Monitor(delta=0.01))
        controller.subscribe('FOO.PV', SubscriptionMode.Monitor(delta=0.123))
        controller.subscribe('BAR.PV', SubscriptionMode.Scan(period=123.1) )
        
        pvs = dict(controller.list_subscribed())
        self.assertEqual( sorted(pvs), ['BAR.PV', 'DEFAULT.PV', 'FOO.PV'])

        futures = controller.munsubscribe(pvs)
        [ fut.wait() for fut in futures]
        
        pvs = dict(controller.list_subscribed())
        self.assertEqual(pvs, {})

        # munsubscribe providing the wrong type or argument (not a sequence)
        self.assertRaises(TypeError, controller.munsubscribe, 'foobar')
Beispiel #4
0
    def test_subscribe(self, mode = None):
        mode = mode or SubscriptionMode.Monitor(delta=0.01)
        futures = [ controller.subscribe(pv, mode) for pv in self.pvs ]
        results = [fut.get() for fut in futures]
        
        self.assertTrue(all(results))

        pvs = dict(controller.list_subscribed())
        for pv in self.pvs:
            self.assertIn(pv, pvs)
Beispiel #5
0
    def test_msubscribe(self ):
        mode_choices = [SubscriptionMode.Monitor(delta=0.01), SubscriptionMode.Scan(period=1)]
        modes = [random.choice(mode_choices) for _ in self.pvs]
        futures = controller.msubscribe( self.pvs, modes )

        results = [ fut.get() for fut in futures ]
        
        self.assertTrue(all(results))
        pvs = dict(controller.list_subscribed())
        for pv in self.pvs:
            self.assertIn(pv, pvs)
Beispiel #6
0
    def test_load_config(self):
        pvnames = ('DEFAULT.PV', 'FOO.PV', 'BAR.PV')
        
        futures = []
        futures.append(controller.subscribe('DEFAULT.PV', SubscriptionMode.Monitor(delta=0.01)))
        futures.append(controller.subscribe('FOO.PV',  SubscriptionMode.Monitor(0.123)))
        futures.append(controller.subscribe('BAR.PV', SubscriptionMode.Scan(123.1)))

        [ fut.wait() for fut in futures ]

        cfg = controller.save_config()

        futures = controller.munsubscribe([pvname for pvname, _ in controller.list_subscribed()])
        [ fut.wait() for fut in futures ]

        logger.info("Trying to load:\n%s", cfg)

        futures = controller.load_config(cfg)
        results = [ fut.get() for fut in futures ]

        pvnames = [pvname for pvname, _ in controller.list_subscribed()]

        self.assertIn('DEFAULT.PV', pvnames)
        self.assertIn('FOO.PV', pvnames)
        self.assertIn('BAR.PV', pvnames)

        av = controller.get_apv('DEFAULT.PV')
        self.assertEqual( av.name, 'DEFAULT.PV' )
        self.assertEqual( av.mode.name, SubscriptionMode.Monitor.name )
        self.assertEqual( av.mode.delta, 0.01 )

        av = controller.get_apv('FOO.PV')
        self.assertEqual( av.name, 'FOO.PV' )
        self.assertEqual( av.mode.name, SubscriptionMode.Monitor.name )
        self.assertEqual( av.mode.delta, 0.123 )

        av = controller.get_apv('BAR.PV')
        self.assertEqual( av.name, 'BAR.PV' )
        self.assertEqual( av.mode.name, SubscriptionMode.Scan.name )
        self.assertEqual( av.mode.period, 123.1 )
Beispiel #7
0
    def test_list_pvs_simple(self):
        def just_the_name(list_of_pairs):
            return map(operator.itemgetter(0), list_of_pairs)

        controller.subscribe('DEFAULT.PV', SubscriptionMode.Monitor(delta=0.01)).wait()
        controller.subscribe('FOO.PV', SubscriptionMode.Monitor(delta=0.123)).wait()
        controller.subscribe('BAR.PV', SubscriptionMode.Scan(period=123.1) ).wait()
        
        pvs = just_the_name(controller.list_subscribed())
        self.assertItemsEqual( pvs, ['BAR.PV', 'DEFAULT.PV', 'FOO.PV'])

        scan_pvs = just_the_name(controller.list_by_mode(SubscriptionMode.Scan.name))
        self.assertEqual( scan_pvs, ['BAR.PV'])

        monitor_pvs = just_the_name(controller.list_by_mode(SubscriptionMode.Monitor.name))
        self.assertEqual( monitor_pvs, ['DEFAULT.PV', 'FOO.PV'])
Beispiel #8
0
 def delete(self):
     # unsubscribe from all
     pvs = [pvname for pvname, _ in controller.list_subscribed()]
     futures = controller.munsubscribe(pvs)
     results = dict((pvname, f.get(TIMEOUT)) for pvname, f in zip(pvs, futures))
     self.win(results)
Beispiel #9
0
 def get(self):
     limit = self.get_argument("limit", 1)
     pvnames = [pvname for pvname, _ in controller.list_subscribed()]
     statuses = [controller.get_statuses(pvname, limit) for pvname in pvnames]
     self.win(statuses)