Ejemplo n.º 1
0
 def test_command_service_models(self):
     testDir = pathlib.Path(__file__).parent.absolute()
     with open(f"{testDir}/command-models.json") as json_file:
         data = json.load(json_file)
         for p in data['Units']:
             assert (Units[p].name == p)
         for p in data['UTCTime']:
             t1 = UTCTime.from_str(p)
             t2 = UTCTime.from_str(str(t1))
             assert (t1 == t2)
         for p in data['CurrentState']:
             cs = CurrentState._fromDict(p)
             assert (str(cs.prefix) == "CSW.ncc.trombone")
             assert (str(cs.stateName) == "idle")
             assert (len(cs.paramSet) == 25)
             for entry in p['paramSet']:
                 for key in entry:
                     # Round-trip test
                     # (ignore time values since resolution of fractional seconds is different in Typescript!)
                     if key not in ['UTCTimeKey', 'TAITimeKey']:
                         assert (
                             entry == Parameter._fromDict(entry)._asDict())
         for p in data["CommandIssue"]:
             # Check that the CommandIssue subclass exists
             assert (p['_type'] in self.commandIssueSubclasses)
Ejemplo n.º 2
0
 def _fromDict(obj):
     """
     Returns a CurrentState for the given dict.
     """
     prefix = Prefix.from_str(obj['prefix'])
     stateName = obj['stateName']
     paramSet = list(map(lambda p: Parameter._fromDict(p), obj['paramSet']))
     return CurrentState(prefix, stateName, paramSet)
Ejemplo n.º 3
0
 def _fromDict(obj):
     """
     Returns a Event for the given dict.
     """
     typ = obj['_type']
     assert (typ in {"SystemEvent", "ObserveEvent"})
     paramSet = list(map(lambda p: Parameter._fromDict(p), obj['paramSet']))
     eventTime = EventTime._fromDict(obj['eventTime'])
     if typ == 'SystemEvent':
         return SystemEvent(obj['source'], obj['eventName'], paramSet,
                            eventTime, obj['eventId'])
     else:
         return ObserveEvent(obj['source'], obj['eventName'], paramSet,
                             eventTime, obj['eventId'])
Ejemplo n.º 4
0
 def _fromDict(obj):
     """
     Returns a ControlCommand for the given dict.
     """
     typ = obj["_type"]
     source = Prefix.from_str(obj['source'])
     commandName = CommandName(obj['commandName'])
     maybeObsId = obj['maybeObsId'] if 'maybeObsId' in obj else ""
     paramSet = list(map(lambda p: Parameter._fromDict(p), obj['paramSet']))
     assert (typ in {"Setup", "Observe"})
     if typ == 'Setup':
         return Setup(source, commandName, maybeObsId, paramSet)
     else:
         return Observe(source, commandName, maybeObsId, paramSet)