def test_protocol_complex1_2(): l = """ in:next_episode ; ( out:no_more_episodes | (out:episode_start ; (in:next_image ; (out:image | out:no_more_images))*) ) """ seq = [InputReceived("next_episode"), OutputProduced("episode_start"), InputReceived("next_image"), OutputProduced("image"), ] assert_seq(l, seq, (NeedMore, Enough), Enough)
def test_protocol_complex1_3v(): l0 = """ out:episode_start ; (in:next_image ; (out:image | out:no_more_images))* """ seq = [OutputProduced("episode_start")] assert_seq(l0, seq, (Enough,), Enough)
def write(self, topic, data, timing=None, with_schema=False): if topic not in self.protocol.outputs: msg = f'Output channel "{topic}" not found in protocol; know {sorted(self.protocol.outputs)}.' raise Exception(msg) # logger.info(f'Writing output "{topic}".') klass = self.protocol.outputs[topic] if isinstance(klass, type): check_isinstance(data, klass) event = OutputProduced(topic) res = self.pc.push(event) if isinstance(res, Unexpected): msg = f'Unexpected output {topic}: {res}' logger.error(msg) return klass = self.protocol.outputs[topic] if isinstance(data, dict): data = ipce_to_object(data, {}, {}, expect_type=klass) if timing is None: timing = self.last_timing s = time.time() hostname = socket.gethostname() if timing.received is None: # XXX time1 = timestamp_from_seconds(s) else: time1 = timing.received.time processed = TimeSpec(time=time1, time2=timestamp_from_seconds(s), frame='epoch', clock=hostname) timing.processed[self.node_name] = processed # timing = TimingInfo(acquired=acquired, processed=processed) m = {} m[FIELD_COMPAT] = [CUR_PROTOCOL] m[FIELD_TOPIC] = self.tout.get(topic, topic) m[FIELD_DATA] = object_to_ipce(data, {}, with_schema=with_schema) timing.received = None m[FIELD_TIMING] = object_to_ipce(timing, {}, with_schema=False) self._write_raw(m) logger_interaction.debug(f'Written output "{topic}".')
def test_proto_image_source(): l0 = protocol_image_source.language seq = [OutputProduced("next_image")] assert_seq(l0, seq, (Unexpected, ), Unexpected)
def test_proto07(): seq = [OutputProduced("a"), OutputProduced("b")] assert_seq("out:a ; out:b", seq, (NeedMore, Enough), Enough)
def test_proto06(): seq = [OutputProduced("b")] assert_seq("in:a", seq, (Unexpected,), Unexpected)
def test_proto_out1(): seq = [OutputProduced("a")] assert_seq("out:a", seq, (Enough,), Enough)
def test_proto_zoom_02(): seq = [OutputProduced("a")] assert_seq("out:a ?", seq, (Enough,), Enough)
def test_proto_zoom_03(): seq = [OutputProduced("a"), OutputProduced("a")] assert_seq("out:a ?", seq, (Enough, Unexpected), Unexpected)
def test_proto_oom_03(): seq = [OutputProduced("a"), OutputProduced("a")] assert_seq("out:a +", seq, (Enough, Enough), Enough)
def test_proto_either_05(): seq = [OutputProduced("b"), OutputProduced("a")] assert_seq("(out:a ; out:b) | (out:b ; out:a) ", seq, (NeedMore, Enough,), Enough)
def test_proto_either_03(): seq = [OutputProduced("c")] assert_seq("out:a | out:b | out:c ", seq, (Enough,), Enough)
def test_proto10(): seq = [OutputProduced("a"), OutputProduced("b"), OutputProduced("c")] assert_seq("out:a ; out:b", seq, (NeedMore, Enough, Unexpected), Unexpected)
def test_proto09(): seq = [OutputProduced("a")] assert_seq("out:a ; out:b", seq, (NeedMore,), NeedMore)