from __future__ import print_function

import epics

from .mgnt_auto_checkout_test import AutoCheckoutTest


class STATMSGTest(AutoCheckoutTest):
    test_id = 'statmsg'
    description = 'STATMSG'
    read_only = True
    deferred = False

    def __init__(self):
        super(STATMSGTest, self).__init__(
            pre_checkout_routines=[]
        )

    def execute(self, magnet):
        statmsg_pv = magnet['device'] + ':STATMSG.SEVR'
        statmsg = epics.caget(statmsg_pv, as_string=True)
        if statmsg is not None:
            self.data = 'Exists'
            self.status = True
            print('PASS')

        else:
            self.data = '{} not found'.format(statmsg_pv)
            self.status = False
            print('FAIL')
