Esempio n. 1
0
 def testNonDefaultConstructor(self):
     severity_choices = self.test_alarm.getSeverityChoices()
     test_severity = ""
     status_choices = self.test_alarm.getStatusChoices()
     test_status = ""
     test_message = "test message"
     if len(severity_choices) > 0:
         test_severity = severity_choices[len(severity_choices) % 3]
     if len(status_choices) > 0:
         test_status = status_choices[len(status_choices) % 3]
     self.test_alarm = Alarm(test_severity, test_status, test_message)
     self.assertEqual(self.test_alarm.getMessage(), test_message)
     self.assertEqual(self.test_alarm.getStatus(), test_status)
     self.assertEqual(self.test_alarm.getSeverity(), test_severity)
    def testNTMultiChannel(self):
        result = self.gatherv3data.get()
        self.assertTrue(result, "Connection failed with message:  " + self.gatherv3data.getMessage())
        pvstructure = self.gatherv3data.getPVStructure()
        ntmultichannel = NTMultiChannel(pvstructure)

        alarm = Alarm()
        ntmultichannel.getAlarm(alarm)
        self.assertIn(alarm.getStatus(), alarm.getStatusChoices())
        self.assertIn(alarm.getSeverity(), alarm.getSeverityChoices())

        time_stamp = TimeStamp()
        ntmultichannel.getTimeStamp(time_stamp)
        self.assertEqual(3, len(str(time_stamp).split(':')))  # Time stamp format test

        channel_count = ntmultichannel.getNumberChannel()

        self.assertEqual(channel_count, len(self.names))

        test_val_list = (0, 1, 'zero', 'one', 10, 'string value', 1.9, (), (), (), (), (), ())
        self.assertEqual(ntmultichannel.getValue(), test_val_list)

        self.assertEqual(ntmultichannel.getChannelName(), self.names)

        test_connected_list = (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        self.assertEqual(ntmultichannel.getIsConnected(), test_connected_list)

        test_severity_list = (3, 0, 3, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3)
        self.assertEqual(ntmultichannel.getSeverity(), test_severity_list)

        test_status_list = (3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3)
        self.assertEqual(ntmultichannel.getStatus(), test_status_list)

        test_message_list = ('UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM')
        self.assertEqual(ntmultichannel.getMessage(), test_message_list)

        test_dbrtype_list = (0, 5, 0, 0, 5, 0, 6, 4, 0, 1, 5, 2, 6)
        self.assertEqual(ntmultichannel.getDbrType(), test_dbrtype_list)

        test_secondspastepoch_list = (631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000, 631152000)
        self.assertEqual(ntmultichannel.getSecondsPastEpoch(), test_secondspastepoch_list)

        test_nanoseconds_list = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
        self.assertEqual(ntmultichannel.getNanoseconds(), test_nanoseconds_list)

        test_usertag_list = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
        self.assertEqual(ntmultichannel.getUserTag(), test_usertag_list)

        self.assertEqual(type(ntmultichannel.getDescriptor()), StringType)
    def ntnv_asserts(self, function, params):

        alarm = Alarm()
        time_stamp = TimeStamp()
        ntnv = NTNameValue(function, params)
        self.channelRPC.issueRequest(ntnv.getNTNameValue(), False)
        response = self.channelRPC.waitResponse()
        self.assertNotEqual(response, None, "ChannelRPC connection failure.")
        result = NTMultiChannel(response)
        result.getAlarm(alarm)
        result.getTimeStamp(time_stamp)
        self.assertEqual(3, len(str(time_stamp).split(":")))  # Timestamp string format test

        self.assertIn(alarm.getStatus(), alarm.getStatusChoices())
        self.assertIn(alarm.getSeverity(), alarm.getSeverityChoices())
Esempio n. 4
0
 def testGetAlarm(self):
     test_alarm = Alarm()
     test_message = "test message"
     test_alarm.setMessage(test_message)
     self.test_nttable.getAlarm(test_alarm)
     self.assertEqual(test_alarm.getMessage(), test_message, "Alarm.message returned an unexpected value: " + str(test_alarm.getMessage()) + " expected " + str(test_message))
     self.assertEqual(test_alarm.getSeverity(), "NONE", "Alarm.severity returned an unexpected value: " + str(test_alarm.getSeverity()) + " expected NONE ")
     self.assertEqual(test_alarm.getStatus(), "NONE", "Alarm.status returned an unexpected value: " + str(test_alarm.getStatus()) + " expected NONE ")
Esempio n. 5
0
 def testGetAlarm(self):
     test_alarm = Alarm()
     test_message = "test message"
     test_alarm.setMessage(test_message)
     test_ntscalar = NTScalar("double")
     test_ntscalar.getAlarm(test_alarm)
     self.assertEqual(test_alarm.getMessage(), test_message)
     self.assertEqual(test_alarm.getSeverity(), "NONE")
     self.assertEqual(test_alarm.getStatus(), "NONE")
Esempio n. 6
0
def __clientRPC(function, params):
    alarm = Alarm()
    timeStamp = TimeStamp()

    ntnv = NTNameValue(function, params)

    # now do issue + wait
    channelRPC = ChannelRPC("masarService")
    channelRPC.issueConnect()
    if not channelRPC.waitConnect(1.0):
        print "error when waiting connection.", channelRPC.getMessage()
        exit(1)
    channelRPC.issueRequest(ntnv.getNTNameValue(), False)
    result = channelRPC.waitResponse()
    if result is None:
        print channelRPC.getMessage()
        exit(1)
#    print "problem to get nttable using getNTTable()"
    if function in ["retrieveSnapshot", "getLiveMachine", "saveSnapshot"]:
        result = NTMultiChannel(result)
    elif function in [
            "retrieveServiceEvents", "retrieveServiceConfigs",
            "retrieveServiceConfigProps"
    ]:
        result = NTTable(result)
        label = result.getLabels()
        print "label", label
        print result.getPVStructure()
    elif function == "updateSnapshotEvent":
        result = NTScalar(result)


#    print "Problem above"
#     print result

    result.getAlarm(alarm)
    # print alarm

    result.getTimeStamp(timeStamp)
    # print timeStamp

    # numberValues = result.getNumberValues()
    # print "numberValues", numberValues

    #
    #    i = 0
    #    while i < numberValues :
    #        value = nttable.getValue(i)
    #        print "value",label[i],value
    #        i += 1
    return result
Esempio n. 7
0
def __clientRPC(function, params):
    alarm = Alarm()
    timeStamp = TimeStamp()

    ntnv = NTNameValue(function,params)
    
    # now do issue + wait
    channelRPC = ChannelRPC("masarService","record[process=true]field()")
    channelRPC.issueConnect()
    if not channelRPC.waitConnect(1.0) :
        print channelRPC.getMessage()
        exit(1)
    channelRPC.issueRequest(ntnv.getNTNameValue(),False)
    result = channelRPC.waitRequest()
    if(result==None) :
        print channelRPC.getMessage()
        exit(1)
    nttable = NTTable(result)
    print nttable
    
    nttable.getAlarm(alarm.getAlarmPy())
#    print alarm;
    
    nttable.getTimeStamp(timeStamp.getTimeStampPy())
#    print timeStamp;
    
#    numberValues = nttable.getNumberValues()
#    print "numberValues",numberValues
#    
#    label = nttable.getLabel()
#    print "label",label
#    
#    i = 0
#    while i < numberValues :
#        value = nttable.getValue(i)
#        print "value",label[i],value
#        i += 1
    return nttable
Esempio n. 8
0
 def testNonDefaultConstructor(self):
     severity_choices = self.test_alarm.getSeverityChoices()
     test_severity = ""
     status_choices = self.test_alarm.getStatusChoices()
     test_status = ""
     test_message = "test message"
     if len(severity_choices) > 0:
         test_severity = severity_choices[len(severity_choices)%3]
     if len(status_choices) > 0:
         test_status = status_choices[len(status_choices)%3]
     self.test_alarm = Alarm(test_severity, test_status, test_message)
     self.assertEqual(self.test_alarm.getMessage(), test_message)
     self.assertEqual(self.test_alarm.getStatus(), test_status)
     self.assertEqual(self.test_alarm.getSeverity(), test_severity)
Esempio n. 9
0
 def testGetAlarm(self):
     test_alarm = Alarm()
     test_message = "test message"
     test_alarm.setMessage(test_message)
     test_ntscalar = NTScalar("double")
     test_ntscalar.getAlarm(test_alarm)
     self.assertEqual(test_alarm.getMessage(), test_message)
     self.assertEqual(test_alarm.getSeverity(), "NONE")
     self.assertEqual(test_alarm.getStatus(), "NONE")
Esempio n. 10
0
    def ntnv_asserts(self, function, params):

        alarm = Alarm()
        time_stamp = TimeStamp()
        ntnv = NTNameValue(function, params)
        self.channelRPC.issueRequest(ntnv.getNTNameValue(), False)
        response = self.channelRPC.waitResponse()
        self.assertNotEqual(response, None, "ChannelRPC connection failure.")
        result = NTMultiChannel(response)
        result.getAlarm(alarm)
        result.getTimeStamp(time_stamp)
        self.assertEqual(3, len(
            str(time_stamp).split(":")))  # Timestamp string format test

        self.assertIn(alarm.getStatus(), alarm.getStatusChoices())
        self.assertIn(alarm.getSeverity(), alarm.getSeverityChoices())
Esempio n. 11
0
 def setUp(self):
     self.test_alarm = Alarm()
Esempio n. 12
0
# testnameValue.py
#

import time

from masarclient.ntscalar import NTScalar as NTScalar
from masarclient.alarm import Alarm as Alarm
from masarclient.timeStamp import TimeStamp as TimeStamp
from masarclient.control import Control as Control
from masarclient.display import Display as Display

timeStamp = TimeStamp()
alarm = Alarm()
control = Control()
display = Display()

scalar = NTScalar("double")
print scalar

newscalar = scalar.getNTScalar()
print newscalar
print "getTimeStamp"
scalar.getTimeStamp(timeStamp)
print timeStamp
print "getAlarm"
scalar.getAlarm(alarm)
print alarm
print "getControl"
scalar.getControl(control)
print control
print "getDisplay"
Esempio n. 13
0
# testAlarm.py
#
# Copyright - See the COPYRIGHT that is included with this distribution.
# EPICS pvService is distributed subject to a Software License Agreement
#    found in file LICENSE that is included with this distribution.
# Author Marty Kraimer 2011.07
from masarclient.alarm import Alarm as Alarm

alarm = Alarm()
print alarm

statusChoices = alarm.getStatusChoices()
severityChoices = alarm.getSeverityChoices()
print "statusChoices"
print statusChoices
print "severityChoices"
print severityChoices
alarm.setStatus(statusChoices[7])
alarm.setSeverity(severityChoices[3])
alarm.setMessage("test message")
print "alarm"
print "message " + alarm.getMessage()
print "status " + alarm.getStatus()
print "severity " + alarm.getSeverity()
print alarm

print "all done"
Esempio n. 14
0
# testAlarm.py
#
# Copyright - See the COPYRIGHT that is included with this distribution.
# EPICS pvService is distributed subject to a Software License Agreement
#    found in file LICENSE that is included with this distribution.
# Author Marty Kraimer 2011.07
from masarclient.alarm import Alarm as Alarm

alarm = Alarm()
print alarm

statusChoices = alarm.getStatusChoices()
severityChoices = alarm.getSeverityChoices()
print "statusChoices"
print statusChoices
print "severityChoices"
print severityChoices
alarm.setStatus(statusChoices[7])
alarm.setSeverity(severityChoices[3])
alarm.setMessage("test message")
print "alarm"
print "message " + alarm.getMessage()
print "status " + alarm.getStatus()
print "severity " + alarm.getSeverity()
print alarm


print "all done"

Esempio n. 15
0
    def testNTMultiChannel(self):
        result = self.gatherv3data.get()
        self.assertTrue(
            result, "Connection failed with message:  " +
            self.gatherv3data.getMessage())
        pvstructure = self.gatherv3data.getPVStructure()
        ntmultichannel = NTMultiChannel(pvstructure)

        alarm = Alarm()
        ntmultichannel.getAlarm(alarm)
        self.assertIn(alarm.getStatus(), alarm.getStatusChoices())
        self.assertIn(alarm.getSeverity(), alarm.getSeverityChoices())

        time_stamp = TimeStamp()
        ntmultichannel.getTimeStamp(time_stamp)
        self.assertEqual(3, len(
            str(time_stamp).split(':')))  # Time stamp format test

        channel_count = ntmultichannel.getNumberChannel()

        self.assertEqual(channel_count, len(self.names))

        test_val_list = (0, 1, 'zero', 'one', 10, 'string value', 1.9, (), (),
                         (), (), (), ())
        self.assertEqual(ntmultichannel.getValue(), test_val_list)

        self.assertEqual(ntmultichannel.getChannelName(), self.names)

        test_connected_list = (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        self.assertEqual(ntmultichannel.getIsConnected(), test_connected_list)

        test_severity_list = (3, 0, 3, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3)
        self.assertEqual(ntmultichannel.getSeverity(), test_severity_list)

        test_status_list = (3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3)
        self.assertEqual(ntmultichannel.getStatus(), test_status_list)

        test_message_list = ('UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM',
                             'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM',
                             'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM',
                             'UDF_ALARM', 'UDF_ALARM', 'UDF_ALARM',
                             'UDF_ALARM')
        self.assertEqual(ntmultichannel.getMessage(), test_message_list)

        test_dbrtype_list = (0, 5, 0, 0, 5, 0, 6, 4, 0, 1, 5, 2, 6)
        self.assertEqual(ntmultichannel.getDbrType(), test_dbrtype_list)

        test_secondspastepoch_list = (631152000, 631152000, 631152000,
                                      631152000, 631152000, 631152000,
                                      631152000, 631152000, 631152000,
                                      631152000, 631152000, 631152000,
                                      631152000)
        self.assertEqual(ntmultichannel.getSecondsPastEpoch(),
                         test_secondspastepoch_list)

        test_nanoseconds_list = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
        self.assertEqual(ntmultichannel.getNanoseconds(),
                         test_nanoseconds_list)

        test_usertag_list = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
        self.assertEqual(ntmultichannel.getUserTag(), test_usertag_list)

        self.assertEqual(type(ntmultichannel.getDescriptor()), StringType)
Esempio n. 16
0
class TestAlarm(unittest.TestCase):
    '''
    Create test values for each test. Uses default constructor values.
    '''
    def setUp(self):
        self.test_alarm = Alarm()

    '''
    Test to confirm all of the status choices are of the string type.
    '''

    def testStatusChoices(self):
        status_choices = self.test_alarm.getStatusChoices()
        for status in status_choices:
            self.assertIsInstance(status, str)

    '''
    Test to confirm all of the severity choices are of the string type
    '''

    def testSeverityChoices(self):
        severity_choices = self.test_alarm.getSeverityChoices()
        for severity in severity_choices:
            self.assertIsInstance(severity, str)

    '''
    Tests both default value assignment and getter operation for Status
    '''

    def testGetStatus(self):
        self.assertEqual(self.test_alarm.getStatus(), "NONE")

    '''
    Tests both default value assignment and getter operation for Severity
    '''

    def testGetSeverity(self):
        self.assertEqual(self.test_alarm.getSeverity(), "NONE")

    '''
    Tests both default value assignment and getter operation for Message
    '''

    def testGetMessage(self):
        self.assertEqual(self.test_alarm.getMessage(), "")

    '''
    Tests setter for status, also requires at least 1 status returned by getStatusChoices
    '''

    def testSetStatus(self):
        status_choices = self.test_alarm.getStatusChoices()
        status_index = len(
            status_choices) - 1  # Test status will be the last in the list
        self.assertGreaterEqual(status_index, 0)
        self.test_alarm.setStatus(
            status_choices[status_index]
        )  # Index may need to be changed if choices change
        self.assertEqual(self.test_alarm.getStatus(),
                         status_choices[status_index])

    '''
    Tests setter for severity, also requires at least 1 severity returned by getSeverityChoices
    '''

    def testSetSeverity(self):
        severity_choices = self.test_alarm.getSeverityChoices()
        severity_index = len(
            severity_choices) - 1  # Test severity will be the last in the list
        self.assertGreaterEqual(severity_index, 0)
        self.test_alarm.setSeverity(
            severity_choices[severity_index]
        )  # Index may need to be changed if choices change
        self.assertEqual(self.test_alarm.getSeverity(),
                         severity_choices[severity_index])

    '''
    Tests setter for message, requires getMessage
    '''

    def testSetMessage(self):
        test_message = "test message"
        self.test_alarm.setMessage(test_message)
        self.assertEqual(self.test_alarm.getMessage(), test_message)

    '''
    Test non-default constructor value assignment. Full use test.
    '''

    def testNonDefaultConstructor(self):
        severity_choices = self.test_alarm.getSeverityChoices()
        test_severity = ""
        status_choices = self.test_alarm.getStatusChoices()
        test_status = ""
        test_message = "test message"
        if len(severity_choices) > 0:
            test_severity = severity_choices[len(severity_choices) % 3]
        if len(status_choices) > 0:
            test_status = status_choices[len(status_choices) % 3]
        self.test_alarm = Alarm(test_severity, test_status, test_message)
        self.assertEqual(self.test_alarm.getMessage(), test_message)
        self.assertEqual(self.test_alarm.getStatus(), test_status)
        self.assertEqual(self.test_alarm.getSeverity(), test_severity)

    if __name__ == '__main__':
        unittest.main()
Esempio n. 17
0
 def setUp(self):
     self.test_alarm = Alarm()
Esempio n. 18
0
class TestAlarm(unittest.TestCase):

    '''
    Create test values for each test. Uses default constructor values.
    '''
    def setUp(self):
        self.test_alarm = Alarm()

    '''
    Test to confirm all of the status choices are of the string type.
    '''
    def testStatusChoices(self):
        status_choices = self.test_alarm.getStatusChoices()
        for status in status_choices:
            self.assertIsInstance(status, str)

    '''
    Test to confirm all of the severity choices are of the string type
    '''
    def testSeverityChoices(self):
        severity_choices = self.test_alarm.getSeverityChoices()
        for severity in severity_choices:
            self.assertIsInstance(severity,str)

    '''
    Tests both default value assignment and getter operation for Status
    '''
    def testGetStatus(self):
        self.assertEqual(self.test_alarm.getStatus(), "NONE")

    '''
    Tests both default value assignment and getter operation for Severity
    '''
    def testGetSeverity(self):
        self.assertEqual(self.test_alarm.getSeverity(), "NONE")

    '''
    Tests both default value assignment and getter operation for Message
    '''
    def testGetMessage(self):
        self.assertEqual(self.test_alarm.getMessage(), "")

    '''
    Tests setter for status, also requires at least 1 status returned by getStatusChoices
    '''
    def testSetStatus(self):
        status_choices = self.test_alarm.getStatusChoices()
        status_index = len(status_choices)-1  # Test status will be the last in the list
        self.assertGreaterEqual(status_index, 0)
        self.test_alarm.setStatus(status_choices[status_index])  # Index may need to be changed if choices change
        self.assertEqual(self.test_alarm.getStatus(),  status_choices[status_index])

    '''
    Tests setter for severity, also requires at least 1 severity returned by getSeverityChoices
    '''
    def testSetSeverity(self):
        severity_choices = self.test_alarm.getSeverityChoices()
        severity_index = len(severity_choices)-1  # Test severity will be the last in the list
        self.assertGreaterEqual(severity_index, 0)
        self.test_alarm.setSeverity(severity_choices[severity_index])  # Index may need to be changed if choices change
        self.assertEqual(self.test_alarm.getSeverity(), severity_choices[severity_index])

    '''
    Tests setter for message, requires getMessage
    '''
    def testSetMessage(self):
        test_message = "test message"
        self.test_alarm.setMessage(test_message)
        self.assertEqual(self.test_alarm.getMessage(), test_message)

    '''
    Test non-default constructor value assignment. Full use test.
    '''
    def testNonDefaultConstructor(self):
        severity_choices = self.test_alarm.getSeverityChoices()
        test_severity = ""
        status_choices = self.test_alarm.getStatusChoices()
        test_status = ""
        test_message = "test message"
        if len(severity_choices) > 0:
            test_severity = severity_choices[len(severity_choices)%3]
        if len(status_choices) > 0:
            test_status = status_choices[len(status_choices)%3]
        self.test_alarm = Alarm(test_severity, test_status, test_message)
        self.assertEqual(self.test_alarm.getMessage(), test_message)
        self.assertEqual(self.test_alarm.getStatus(), test_status)
        self.assertEqual(self.test_alarm.getSeverity(), test_severity)

    if __name__ == '__main__':
        unittest.main()