Пример #1
0
 def test_event_write(self):
     self.log.debug("something")
     cei_events.event("unittest", "TRIAL1", self.log)
     self.log.debug("something-else")
     events = cei_events.events_from_file(self.logfilepath)
     assert len(events) == 1
     assert events[0].source == "unittest"
     assert events[0].name == "TRIAL1"
Пример #2
0
 def test_event_write(self):
     log.debug("something")
     cei_events.event("unittest", "TRIAL1", log)
     log.debug("something-else")
     events = cei_events.events_from_file(self.logfilepath)
     assert len(events) == 1
     assert events[0].source == "unittest"
     assert events[0].name == "TRIAL1"
Пример #3
0
 def test_extra_hierarchy(self):
     # note the conflicting "hello3" key in higher level:
     innerdict = {"hello3": "hello4"}
     adict = {"hello1": "hello2", "hello5": innerdict, "hello3": "hello6"}
     cei_events.event("unittest", "TRIAL1", self.log, extra=adict)
     events = cei_events.events_from_file(self.logfilepath)
     event = events[0]
     assert event.extra["hello1"] == "hello2"
     assert event.extra["hello3"] == "hello6"
     innerdict = event.extra["hello5"]
     assert isinstance(innerdict, dict)
     assert innerdict["hello3"] == "hello4"
Пример #4
0
 def test_event_nameandsourcefilter(self):
     cei_events.event("SRC1", "NX1", self.log)
     self.log.debug("something not an event")
     cei_events.event("SRX2", "NM2", self.log)
     cei_events.event("SRC3", "XX3", self.log)
     cei_events.event("SRX4", "XX4", self.log)
     cei_events.event("SRC5", "NM5", self.log)
     self.log.debug("something not an event")
     cei_events.event("SRC6", "NM6", self.log)
     path = self.logfilepath
     events = cei_events.events_from_file(path, sourcefilter="SRC", namefilter="NM")
     assert len(events) == 2
Пример #5
0
 def test_event_namefilter2(self):
     cei_events.event("unittest", "NM1", self.log)
     self.log.debug("something not an event")
     cei_events.event("unittest", "XX2", self.log)
     cei_events.event("unittest", "NM3", self.log)
     self.log.debug("something not an event")
     cei_events.event("unittest", "XX4", self.log)
     cei_events.event("unittest", "NM5", self.log)
     cei_events.event("unittest", "XX6", self.log)
     path = self.logfilepath
     events = cei_events.events_from_file(path, namefilter="NM")
     assert len(events) == 3
Пример #6
0
 def test_event_sourcefilter2(self):
     cei_events.event("SRC1", "NM1", self.log)
     self.log.debug("something not an event")
     cei_events.event("SRX2", "NM2", self.log)
     cei_events.event("SRC3", "NM3", self.log)
     self.log.debug("something not an event")
     cei_events.event("SRX4", "NM4", self.log)
     cei_events.event("SRC5", "NM5", self.log)
     cei_events.event("SRC6", "NM6", self.log)
     path = self.logfilepath
     events = cei_events.events_from_file(path, sourcefilter="SRC")
     assert len(events) == 4
Пример #7
0
 def test_event_sourcefilter2(self):
     cei_events.event("SRC1", "NM1", log)
     log.debug("something not an event")
     cei_events.event("SRX2", "NM2", log)
     cei_events.event("SRC3", "NM3", log)
     log.debug("something not an event")
     cei_events.event("SRX4", "NM4", log)
     cei_events.event("SRC5", "NM5", log)
     cei_events.event("SRC6", "NM6", log)
     path = self.logfilepath
     events = cei_events.events_from_file(path, sourcefilter="SRC")
     assert len(events) == 4
Пример #8
0
 def test_event_namefilter2(self):
     cei_events.event("unittest", "NM1", log)
     log.debug("something not an event")
     cei_events.event("unittest", "XX2", log)
     cei_events.event("unittest", "NM3", log)
     log.debug("something not an event")
     cei_events.event("unittest", "XX4", log)
     cei_events.event("unittest", "NM5", log)
     cei_events.event("unittest", "XX6", log)
     path = self.logfilepath
     events = cei_events.events_from_file(path, namefilter="NM")
     assert len(events) == 3
Пример #9
0
    def test_manual_event_write(self):
        cruft = "some cruft %s" % cei_events.event_logtxt("unittest", "TRIAL1")
        self.log.warning(cruft)
        events = cei_events.events_from_file(self.logfilepath)
        assert len(events) == 1

        cei_events.event("unittest", "TRIAL2", self.log)
        events = cei_events.events_from_file(self.logfilepath)
        assert len(events) == 2

        cruft = "cruft2 %s" % cei_events.event_logtxt("unittest", "TRIAL3")
        self.log.warning(cruft)

        events = cei_events.events_from_file(self.logfilepath)
        assert len(events) == 3

        found = {"TRIAL1": False, "TRIAL2": False, "TRIAL3": False}
        for ev in events:
            if ev.name in found:
                found[ev.name] = True
        for val in found.values():
            assert val
Пример #10
0
    def test_manual_event_write(self):
        cruft = "some cruft %s" % cei_events.event_logtxt("unittest", "TRIAL1")
        log.warning(cruft)
        events = cei_events.events_from_file(self.logfilepath)
        assert len(events) == 1

        cei_events.event("unittest", "TRIAL2", log)
        events = cei_events.events_from_file(self.logfilepath)
        assert len(events) == 2

        cruft = "cruft2 %s" % cei_events.event_logtxt("unittest", "TRIAL3")
        log.warning(cruft)

        events = cei_events.events_from_file(self.logfilepath)
        assert len(events) == 3

        found = {"TRIAL1": False, "TRIAL2": False, "TRIAL3": False}
        for ev in events:
            if found.has_key(ev.name):
                found[ev.name] = True
        for val in found.values():
            assert val
Пример #11
0
 def test_timestamp(self):
     utc_now = datetime.datetime.utcnow()
     cei_events.event("unittest", "TRIAL1", self.log)
     events = cei_events.events_from_file(self.logfilepath)
     assert len(events) == 1
     ts = events[0].timestamp
     # It is possible that any of these values could have rolled over
     # between acquiring utc_now and recording the event.  But this is
     # unlikely enough that we'll keep this important UTC sanity check:
     assert ts.year == utc_now.year
     assert ts.month == utc_now.month
     assert ts.day == utc_now.day
     assert ts.hour == utc_now.hour
Пример #12
0
 def test_unique_keys(self):
     cei_events.event("unittest", "NAME", self.log)
     cei_events.event("unittest", "NAME", self.log)
     cei_events.event("unittest", "NAME", self.log)
     cei_events.event("unittest", "NAME", self.log)
     cei_events.event("unittest", "NAME", self.log)
     cei_events.event("unittest", "NAME", self.log)
     cei_events.event("unittest", "NAME", self.log)
     events = cei_events.events_from_file(self.logfilepath)
     assert len(events) == 7
     uniqs = {}
     for ev in events:
         uniqs[ev.timestamp] = None
     assert len(uniqs) == 7
Пример #13
0
    def test_timestamp(self):
        utc_now = datetime.datetime.utcnow()
        cei_events.event("unittest", "TRIAL1", log)
        events = cei_events.events_from_file(self.logfilepath)
        assert len(events) == 1
        ts = events[0].timestamp

        # It is possible that any of these values could have rolled over
        # between acquiring utc_now and recording the event.  But this is
        # unlikely enough that we'll keep this important UTC sanity check:
        assert ts.year == utc_now.year
        assert ts.month == utc_now.month
        assert ts.day == utc_now.day
        assert ts.hour == utc_now.hour
Пример #14
0
 def test_event_nameandsourcefilter(self):
     cei_events.event("SRC1", "NX1", log)
     log.debug("something not an event")
     cei_events.event("SRX2", "NM2", log)
     cei_events.event("SRC3", "XX3", log)
     cei_events.event("SRX4", "XX4", log)
     cei_events.event("SRC5", "NM5", log)
     log.debug("something not an event")
     cei_events.event("SRC6", "NM6", log)
     path = self.logfilepath
     events = cei_events.events_from_file(path,
                                          sourcefilter="SRC",
                                          namefilter="NM")
     assert len(events) == 2
Пример #15
0
    def test_extra_hierarchy(self):
        # note the conflicting "hello3" key in higher level:
        innerdict = {"hello3": "hello4"}
        adict = {"hello1": "hello2", "hello5": innerdict, "hello3": "hello6"}

        cei_events.event("unittest", "TRIAL1", log, extra=adict)
        events = cei_events.events_from_file(self.logfilepath)
        assert len(events) == 1
        assert events[0].extra["hello1"] == "hello2"
        assert events[0].extra["hello3"] == "hello6"

        innerdict = events[0].extra["hello5"]
        assert isinstance(innerdict, dict)
        assert innerdict["hello3"] == "hello4"
Пример #16
0
 def test_unique_keys(self):
     cei_events.event("unittest", "NAME", log)
     cei_events.event("unittest", "NAME", log)
     cei_events.event("unittest", "NAME", log)
     cei_events.event("unittest", "NAME", log)
     cei_events.event("unittest", "NAME", log)
     cei_events.event("unittest", "NAME", log)
     cei_events.event("unittest", "NAME", log)
     events = cei_events.events_from_file(self.logfilepath)
     assert len(events) == 7
     uniqs = {}
     for ev in events:
         uniqs[ev.timestamp] = None
     assert len(uniqs) == 7
Пример #17
0
 def test_extra(self):
     adict = {"hello1":"hello2"}
     cei_events.event("unittest", "TRIAL1", log, extra=adict)
     events = cei_events.events_from_file(self.logfilepath)
     assert len(events) == 1
     assert events[0].extra["hello1"] == "hello2"
Пример #18
0
 def test_extra_integer_values(self):
     adict = {"hello1": 34}
     cei_events.event("unittest", "TRIAL1", self.log, extra=adict)
     events = cei_events.events_from_file(self.logfilepath)
     assert len(events) == 1
     assert events[0].extra["hello1"] == 34
Пример #19
0
 def test_extra_integer_values(self):
     adict = {"hello1": 34}
     cei_events.event("unittest", "TRIAL1", log, extra=adict)
     events = cei_events.events_from_file(self.logfilepath)
     assert len(events) == 1
     assert events[0].extra["hello1"] == 34