1 from __future__
import division, absolute_import
2 """!A base class that trial's unittest TestCase objects can inherit from
4 from twisted.internet
import reactor
6 from tcc.actor import TCC35mDispatcherWrapper
7 from tcc.base import AxisStateValDict, RotTypeNameDict
9 from tcc.msg import CoordSysNameKeyDict, RotTypeEnumKeyDict
16 self.
dw = TCC35mDispatcherWrapper()
17 return self.dw.readyDeferred
22 delayedCalls = reactor.getDelayedCalls()
23 for call
in delayedCalls:
25 return self.dw.close()
29 """!Return the actor dispatcher that talks to the mirror controller
31 return self.dw.dispatcher
35 """!Return the tcc actor
37 return self.dw.actorWrapper.actor
41 """!Return the tcc model
43 return self.dw.dispatcher.model
47 """!return the cmdQueue on the dispatcher wrapper
49 return self.dw.cmdQueue
53 return self.actor.obj.isMoving()
56 """!Check that the cmdVar didFail == shouldFail
59 self.assertTrue(cmdVar.didFail)
61 self.assertFalse(cmdVar.didFail)
65 coordSysName=
None, coordSysDate=
None,
71 """!Check the result of a track command
73 Warning: does not yet check pos or rotAngle
75 @param[in] cmdVar ignored; only present so this can be used as a cmdVar callback
76 @param[in] axisCmdState list of 3 axis state strings, such as "Halted"; see tcc.base.AxisStateValDict for values
77 @param[in] pos string of pos1, pos2[, vel1, vel2[, tai]]
78 @param[in] rotType rotation type as the full string the TCC outputs for the RotType keyword
79 (e.g. "Object"); not case sensitive
80 @param[in] rotAngle rotation angle as a float
81 @param[in] coordSysName coordinate system name as the value the TCC outputs for the ObjSys keyword
82 (e.g. "Geocentric"); not case sensitive
83 @param[in] coordSysDate coordinate system date (float), or 0 if current
84 @param[in] checkActor if True then check actor state directly, in addition to received keywords;
85 usually you should set this False if testing the state as a slew begins (reply code of ">")
86 because otherwise the test is needlessly timing-dependent and fragile:
87 the actor may have finished the slew by the time the test is performed
89 if axisCmdState
is not None:
90 self.
checkAxisCmdState(cmdVar=cmdVar, axisCmdState=axisCmdState, checkActor=checkActor)
91 if rotType
is not None:
92 desRotTypeEnum = RotTypeNameDict[rotType]
93 desRotTypeKey = RotTypeEnumKeyDict[desRotTypeEnum]
94 self.assertEqual(desRotTypeKey, str(self.model.rotType[0]))
96 self.assertEqual(desRotTypeEnum, self.dw.actor.obj.rotType)
97 if coordSysName
is not None:
98 self.
checkUserSys(cmdVar=cmdVar, coordSysName=coordSysName, coordSysDate=coordSysDate, checkActor=checkActor)
101 """!Check commanded axis state from axisCmdState keyword and optionally obj.axisCmdState
103 @param[in] cmdVar ignored; only present so this can be used as a cmdVar callback
104 @param[in] axisCmdState list of axis state strings, such as "Halted"; see tcc.base.AxisStateValDict for values
105 @param[in] checkActor if True then check actor state directly, in addition to received keywords
108 lastReportedState = tuple(str(val)
for val
in self.model.axisCmdState)
109 self.assertEqual(tuple(axisCmdState), lastReportedState)
111 self.assertEqual(tuple(axisCmdState), tuple(AxisStateValDict[val]
for val
in self.actor.obj.axisCmdState))
113 def checkUserSys(self, cmdVar, coordSysName, coordSysDate, checkActor=True):
114 """!Check that the coordinate system is as specified
116 Checks by comparing keywords output by the TCC and optionally be examining
117 the TCC actor directly,
119 @param[in] cmdVar ignored; only present so this can be used as a cmdVar callback
120 @param[in] coordSysName full TCC coordinate system name (e.g. geocentric); not case sensitive
121 @param[in] coordSysDate coordinate system date (float), or None if defaulted
122 (2000 for FK5, 1950 for FK4, 0 for all other coordinate systems)
123 @param[in] checkActor if True then check actor state directly, in addition to received keywords
125 Compare to ObjSys keyword (which shows obj.userSys),
126 and also compare directly to the actor's obj block.
128 desUserSysBlockName = CoordCmdNameDict[coordSysName.lower()]
129 desObjSysKeyName = CoordSysNameKeyDict[desUserSysBlockName]
132 objSysKeyName, objSysDate = self.model.objSys[:]
133 self.assertEqual(desObjSysKeyName, objSysKeyName)
134 if coordSysDate
is None:
138 }.get(desUserSysBlockName, 0)
139 self.assertAlmostEqual(objSysDate, coordSysDate)
143 self.assertEqual(self.actor.obj.userSys.getName(), desUserSysBlockName)
144 self.assertAlmostEqual(self.actor.obj.userSys.getDate(), coordSysDate)
def checkTrackResult
Check the result of a track command.
def checkCmdFail
Check that the cmdVar didFail == shouldFail.
def checkUserSys
Check that the coordinate system is as specified.
def dispatcher
Return the actor dispatcher that talks to the mirror controller.
def checkAxisCmdState
Check commanded axis state from axisCmdState keyword and optionally obj.axisCmdState.
def tearDown
Tear down a test.
def cmdQueue
return the cmdQueue on the dispatcher wrapper
def model
Return the tcc model.
def actor
Return the tcc actor.