from __future__ import print_function

from tests.mgnt_get_ioc_config_test import GetIOCConfigTest
from .mgnt_auto_checkout_test import AutoCheckoutTest


class MagnetScreenIOCsTest(AutoCheckoutTest):
    test_id = 'magnet_screeniocs'
    description = 'screeniocs'
    read_only = True
    deferred = False

    def __init__(self):
        super(MagnetScreenIOCsTest, self).__init__(
            pre_checkout_routines=[]
        )

    def execute(self, magnet):
        """Ensure that IOC is configured correctly in `screeniocs`.

        1. Determine the IOC node by taking the IOC name, replacing colons with hyphens, and lowercasing.
        2. Read `$EPICS_IOCS/screeniocs`.
        3. Ensure that the IOC node appears in one of the following formats:
           <IOC node>    <TS node>           <TS port>
           <IOC node>    <path to binary>    <screen host>
           <IOC node>    <IOC host>          laci             <path to binary>

        4. If IOC node is missing from `screeniocs`, FAIL, otherwise PASS.

        Args:
            magnet (dict): Information about a magnet from Oracle (Elements, Polynomial, Additional Data)

        Returns:
            None

        """
        results = GetIOCConfigTest().get_results(magnet['ioc'])
        self.data = results['data'][magnet['element']]
        self.status = results['status'][magnet['element']]
