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