Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.apo.nmsu.edu/Telescopes/TCC/html/wrapper_test_case_8py_source.html
Дата изменения: Tue Sep 15 02:25:37 2015
Дата индексирования: Sun Apr 10 04:10:05 2016
Кодировка:

Поисковые слова: п п п п п р п р п р п р п р п р п р п
lsst.tcc: python/tcc/base/wrapperTestCase.py Source File
lsst.tcc  1.2.2-3-g89ecb63
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
wrapperTestCase.py
Go to the documentation of this file.
1 from __future__ import division, absolute_import
2 """!A base class that trial's unittest TestCase objects can inherit from
3 """
4 from twisted.internet import reactor
5 
6 from tcc.actor import TCC35mDispatcherWrapper
7 from tcc.base import AxisStateValDict, RotTypeNameDict
8 from tcc.parse import CoordCmdNameDict
9 from tcc.msg import CoordSysNameKeyDict, RotTypeEnumKeyDict
10 
11 class WrapperTestCase(object):
12 
13  def setUp(self):
14  """!Set up a test
15  """
16  self.dw = TCC35mDispatcherWrapper()
17  return self.dw.readyDeferred
18 
19  def tearDown(self):
20  """!Tear down a test
21  """
22  delayedCalls = reactor.getDelayedCalls()
23  for call in delayedCalls:
24  call.cancel()
25  return self.dw.close()
26 
27  @property
28  def dispatcher(self):
29  """!Return the actor dispatcher that talks to the mirror controller
30  """
31  return self.dw.dispatcher
32 
33  @property
34  def actor(self):
35  """!Return the tcc actor
36  """
37  return self.dw.actorWrapper.actor
38 
39  @property
40  def model(self):
41  """!Return the tcc model
42  """
43  return self.dw.dispatcher.model
44 
45  @property
46  def cmdQueue(self):
47  """!return the cmdQueue on the dispatcher wrapper
48  """
49  return self.dw.cmdQueue
50 
51  @property
52  def isMoving(self):
53  return self.actor.obj.isMoving()
54 
55  def checkCmdFail(self, cmdVar, shouldFail=False):
56  """!Check that the cmdVar didFail == shouldFail
57  """
58  if shouldFail:
59  self.assertTrue(cmdVar.didFail)
60  else:
61  self.assertFalse(cmdVar.didFail)
62  return cmdVar
63 
64  def checkTrackResult(self, cmdVar, axisCmdState,
65  coordSysName=None, coordSysDate=None,
66  pos=None,
67  rotType=None,
68  rotAngle=None,
69  checkActor=True,
70  ):
71  """!Check the result of a track command
72 
73  Warning: does not yet check pos or rotAngle
74 
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
88  """
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]))
95  if checkActor:
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)
99 
100  def checkAxisCmdState(self, cmdVar, axisCmdState, checkActor=True):
101  """!Check commanded axis state from axisCmdState keyword and optionally obj.axisCmdState
102 
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
106  """
107  # use last reported value; if no value ever reported then assume axes are halted
108  lastReportedState = tuple(str(val) for val in self.model.axisCmdState)
109  self.assertEqual(tuple(axisCmdState), lastReportedState)
110  if checkActor:
111  self.assertEqual(tuple(axisCmdState), tuple(AxisStateValDict[val] for val in self.actor.obj.axisCmdState))
112 
113  def checkUserSys(self, cmdVar, coordSysName, coordSysDate, checkActor=True):
114  """!Check that the coordinate system is as specified
115 
116  Checks by comparing keywords output by the TCC and optionally be examining
117  the TCC actor directly,
118 
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
124 
125  Compare to ObjSys keyword (which shows obj.userSys),
126  and also compare directly to the actor's obj block.
127  """
128  desUserSysBlockName = CoordCmdNameDict[coordSysName.lower()]
129  desObjSysKeyName = CoordSysNameKeyDict[desUserSysBlockName]
130 
131  # check obsSys keyword
132  objSysKeyName, objSysDate = self.model.objSys[:]
133  self.assertEqual(desObjSysKeyName, objSysKeyName)
134  if coordSysDate is None:
135  coordSysDate = {
136  "fk5": 2000,
137  "fk4": 1950,
138  }.get(desUserSysBlockName, 0)
139  self.assertAlmostEqual(objSysDate, coordSysDate)
140 
141  # check obj.userSys in actor
142  if checkActor:
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 cmdQueue
return the cmdQueue on the dispatcher wrapper