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 ")
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")
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())
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())
# 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"
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()
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()
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)