예제 #1
0
 def testGetTimeStamp(self):
     test_timestamp = TimeStamp()
     self.test_nttable.getTimeStamp(test_timestamp)
     test_stamp = TimeStamp()
     self.assertGreaterEqual(test_timestamp._diffInt(test_stamp), 0, "Unexpected time stamp value, "
                                                                     "given time stamp is earlier than default time")
     test_stamp.getCurrent()
     self.assertLess(test_timestamp._diffInt(test_stamp), 0, "Unexpected time stamp value, "
                                                               "given time stamp is in the future")
예제 #2
0
 def testNormalize(self):
     time_stamp = TimeStamp(1, 1000000000)
     self.assertEqual(time_stamp.getNanoseconds(), 0)
     self.assertEqual(time_stamp.getSecondsPastEpoch(), 2)
     time_stamp = TimeStamp(1, 999999999)
     self.assertEqual(time_stamp.getNanoseconds(), 999999999)
     self.assertEqual(time_stamp.getSecondsPastEpoch(), 1)
     time_stamp = TimeStamp(1, -1000000000)
     self.assertEqual(time_stamp.getSecondsPastEpoch(), 0)
     self.assertEqual(time_stamp.getNanoseconds(), 0)
     time_stamp = TimeStamp(1, -999999999)
     self.assertEqual(time_stamp.getSecondsPastEpoch(), 0)
     self.assertEqual(time_stamp.getNanoseconds(), 1)
예제 #3
0
 def testNonDefaultConstructor(self):
     for test_value_seconds in range(0, 100):
         for test_value_nanoseconds in range(0, 100):
             self.test_time_stamp = TimeStamp(test_value_seconds,
                                              test_value_nanoseconds)
             self.assertEqual(self.test_time_stamp.getNanoseconds(),
                              test_value_nanoseconds)
             self.assertGreaterEqual(self.test_time_stamp.toSeconds() + .1,
                                     test_value_seconds)
             self.assertGreaterEqual(test_value_seconds,
                                     self.test_time_stamp.toSeconds() - .1)
예제 #4
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
예제 #5
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())
예제 #6
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"
예제 #7
0
 def testGetCurrent(self):
     self.test_time_stamp.getCurrent()
     self.assertGreater(self.test_time_stamp.toSeconds(), 0.0)
     test_stamp_two = TimeStamp()
     test_stamp_two.getCurrent()
     self.assertGreaterEqual(test_stamp_two, self.test_time_stamp)
예제 #8
0
 def setUp(self):
     self.test_time_stamp = TimeStamp()
예제 #9
0
    def testOperators(self):
        self.assertTrue(TimeStamp(1, 0) == TimeStamp(0, 1000000000))
        self.assertFalse(TimeStamp(1, 0) == TimeStamp(1, -1000000000))
        self.assertFalse(TimeStamp(2, 0) == TimeStamp(3, -999999999))

        self.assertTrue(TimeStamp(1, 0) != TimeStamp(1, -1000000000))
        self.assertFalse(TimeStamp(1, 1) != TimeStamp(0, 1000000001))
        self.assertFalse(TimeStamp(1, 0) != TimeStamp(2, -1000000000))

        self.assertTrue(TimeStamp(1, 0) > TimeStamp(1, -1))
        self.assertFalse(TimeStamp(0, 999999999) > TimeStamp(1, -1))
        self.assertFalse(TimeStamp(1, -1) > TimeStamp(0, 1000000000))

        self.assertTrue(TimeStamp(1, 1) < TimeStamp(2, -999999998))
        self.assertFalse(TimeStamp(0, 999999999) < TimeStamp(1, -2))
        self.assertFalse(TimeStamp(0, 999999999) < TimeStamp(1, -1))

        self.assertTrue(TimeStamp(1, 0) >= TimeStamp(2, -1000000001))
        self.assertTrue(TimeStamp(1, 0) >= TimeStamp(2, -1000000000))
        self.assertFalse(TimeStamp(2, 0) >= TimeStamp(1, 1000000001))

        self.assertTrue(TimeStamp(1, 1000000000) <= TimeStamp(1, 1000000001))
        self.assertTrue(TimeStamp(1, -1) <= TimeStamp(2, -1000000001))
        self.assertFalse(TimeStamp(1, 1000000001) <= TimeStamp(2, 0))
예제 #10
0
# testTimeStamp.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
import time
from masarclient.timeStamp import TimeStamp as TimeStamp

timeStamp = TimeStamp()
timeStamp.getCurrent()
print "secondsPastEpoch ", timeStamp.getSecondsPastEpoch()
print "epicsSecondsPastEpoch ", timeStamp.getEpicsSecondsPastEpoch()
print "nanoseconds ", timeStamp.getNanoseconds()
print "seconds ", timeStamp.toSeconds()
print "toString", timeStamp
tm = timeStamp.toSeconds()
tupletime = time.localtime(tm)
string = time.strftime("%Y %b %d %H:%M:%S", tupletime)
print string
string = time.strftime("%x", tupletime)
print string
string = time.strftime("%X", tupletime)
print string
string = time.strftime("%c %Z", tupletime)
print string
another = TimeStamp(timeStamp.getSecondsPastEpoch(),
                    timeStamp.getNanoseconds())
print "seconds ", another.toSeconds()
if not timeStamp == another:
    print "timeStamp==another failed"
예제 #11
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)
예제 #12
0
 def testGetTimeStamp(self):
     test_timestamp = TimeStamp()
     test_ntscalar = NTScalar("double")
     test_ntscalar.getTimeStamp(test_timestamp)
     self.assertEqual(3, len(
         str(test_timestamp).split(":")))  # Timestamp string format test