Beispiel #1
0
    def test_to_dict_two_match_events(self):
        event_a = PrimitiveEvent(timestamp=EpochNSClock.generate_timestamp())
        event_b = PrimitiveEvent(timestamp=EpochNSClock.generate_timestamp())

        match_a = MatchEvent(nfa_name=NFA_NAME_A,
                             label=LABEL_LAYER_A,
                             event=event_a)
        match_b = MatchEvent(nfa_name=NFA_NAME_A,
                             label=LABEL_LAYER_B,
                             event=event_b)

        version = RunVersion()
        version.add_level(
            BoboRun._generate_id(nfa_name=NFA_NAME_A,
                                 start_event_id=event_a.event_id))
        version_str = version.get_version_as_str()

        # match a --next--> match b
        match_a.add_pointer_next(version=version_str,
                                 label=match_b.label,
                                 event_id=match_b.event.event_id)

        # match a dict
        self.assertDictEqual(
            match_a.to_dict(), {
                MatchEvent.NFA_NAME: NFA_NAME_A,
                MatchEvent.LABEL: LABEL_LAYER_A,
                MatchEvent.EVENT: event_a.to_dict(),
                MatchEvent.NEXT_IDS: {
                    version_str: (match_b.label, match_b.event.event_id)
                },
                MatchEvent.PREVIOUS_IDS: {}
            })

        # match a <--previous-- match b
        match_b.add_pointer_previous(version=version_str,
                                     label=match_a.label,
                                     event_id=match_a.event.event_id)

        # match b dict
        self.assertDictEqual(
            match_b.to_dict(), {
                MatchEvent.NFA_NAME: NFA_NAME_A,
                MatchEvent.LABEL: LABEL_LAYER_B,
                MatchEvent.EVENT: event_b.to_dict(),
                MatchEvent.NEXT_IDS: {},
                MatchEvent.PREVIOUS_IDS: {
                    version_str: (match_a.label, match_a.event.event_id)
                }
            })
Beispiel #2
0
    def test_to_dict(self):
        # Create primitive event
        p_timestamp = EpochNSClock.generate_timestamp()
        p_event = PrimitiveEvent(timestamp=p_timestamp, data=P_DATA)
        p_hist = "p_hist"

        # Create composite event
        c_timestamp = EpochNSClock.generate_timestamp()
        c_history = BoboHistory()
        c_event = CompositeEvent(timestamp=c_timestamp,
                                 name=C_NAME,
                                 history=c_history,
                                 data=C_DATA)
        c_hist = "c_hist"

        # Create list of events for history
        events = {p_hist: [p_event], c_hist: [c_event]}

        # Create history and add events
        history = BoboHistory(events=events)

        self.assertDictEqual(history.to_dict(), {
            p_hist: [p_event.to_dict()],
            c_hist: [c_event.to_dict()]
        })
Beispiel #3
0
    def test_to_dict(self):
        p_timestamp = EpochNSClock.generate_timestamp()
        p_data = {"p_key": "p_value"}

        p_event = PrimitiveEvent(timestamp=p_timestamp, data=p_data)

        self.assertDictEqual(
            p_event.to_dict(), {
                PrimitiveEvent.TIMESTAMP: p_timestamp,
                PrimitiveEvent.DATA: p_data,
                PrimitiveEvent.EVENT_ID: p_event.event_id
            })