Esempio n. 1
0
 def test_event_write(self):
     logger.debug("something")
     cyvents.event("unittest", "TRIAL1", logger)
     logger.debug("something-else")
     events = cyvents.events_from_file(self.logfilepath)
     assert len(events) == 1
     assert events[0].source == "unittest"
     assert events[0].name == "TRIAL1"
Esempio n. 2
0
 def test_event_nameandsourcefilter(self):
     cyvents.event("SRC1", "NX1", logger)
     logger.debug("something not an event")
     cyvents.event("SRX2", "NM2", logger)
     cyvents.event("SRC3", "XX3", logger)
     cyvents.event("SRX4", "XX4", logger)
     cyvents.event("SRC5", "NM5", logger)
     logger.debug("something not an event")
     cyvents.event("SRC6", "NM6", logger)
     path = self.logfilepath
     events = cyvents.events_from_file(path, sourcefilter="SRC", namefilter="NM")
     assert len(events) == 2
Esempio n. 3
0
 def test_event_sourcefilter2(self):
     cyvents.event("SRC1", "NM1", logger)
     logger.debug("something not an event")
     cyvents.event("SRX2", "NM2", logger)
     cyvents.event("SRC3", "NM3", logger)
     logger.debug("something not an event")
     cyvents.event("SRX4", "NM4", logger)
     cyvents.event("SRC5", "NM5", logger)
     cyvents.event("SRC6", "NM6", logger)
     path = self.logfilepath
     events = cyvents.events_from_file(path, sourcefilter="SRC")
     assert len(events) == 4
Esempio n. 4
0
 def test_event_namefilter2(self):
     cyvents.event("unittest", "NM1", logger)
     logger.debug("something not an event")
     cyvents.event("unittest", "XX2", logger)
     cyvents.event("unittest", "NM3", logger)
     logger.debug("something not an event")
     cyvents.event("unittest", "XX4", logger)
     cyvents.event("unittest", "NM5", logger)
     cyvents.event("unittest", "XX6", logger)
     path = self.logfilepath
     events = cyvents.events_from_file(path, namefilter="NM")
     assert len(events) == 3
Esempio n. 5
0
 def test_manual_event_write(self):
     cruft = "some cruft %s" % cyvents.event_logtxt("unittest", "TRIAL1")
     logger.warning(cruft)
     events = cyvents.events_from_file(self.logfilepath)
     assert len(events) == 1
     
     cyvents.event("unittest", "TRIAL2", logger)
     events = cyvents.events_from_file(self.logfilepath)
     assert len(events) == 2
     
     cruft = "cruft2 %s" % cyvents.event_logtxt("unittest", "TRIAL3")
     logger.warning(cruft)
     
     events = cyvents.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
Esempio n. 6
0
 def test_timestamp(self):
     utc_now = datetime.datetime.utcnow()
     cyvents.event("unittest", "TRIAL1", logger)
     events = cyvents.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
Esempio n. 7
0
 def test_extra_hierarchy(self):
     # note the conflicting "hello3" key in higher level:
     innerdict = {"hello3":"hello4"}
     adict = {"hello1":"hello2", "hello5":innerdict, "hello3":"hello6"}
     
     cyvents.event("unittest", "TRIAL1", logger, extra=adict)
     events = cyvents.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"
Esempio n. 8
0
 def test_unique_keys(self):
     cyvents.event("unittest", "NAME", logger)
     cyvents.event("unittest", "NAME", logger)
     cyvents.event("unittest", "NAME", logger)
     cyvents.event("unittest", "NAME", logger)
     cyvents.event("unittest", "NAME", logger)
     cyvents.event("unittest", "NAME", logger)
     cyvents.event("unittest", "NAME", logger)
     events = cyvents.events_from_file(self.logfilepath)
     assert len(events) == 7
     uniqs = {}
     for ev in events:
         uniqs[ev.timestamp] = None
     assert len(uniqs) == 7
Esempio n. 9
0
 def _all_events_in_dir(self, logdir):
     self.c.log.debug("Getting events from '%s'" % logdir)
     events = []
     for fullpath in self.dirwalk(logdir):
         events.extend(cyvents.events_from_file(fullpath))
     return events
Esempio n. 10
0
 def test_extra_integer_values(self):
     adict = {"hello1":34}
     cyvents.event("unittest", "TRIAL1", logger, extra=adict)
     events = cyvents.events_from_file(self.logfilepath)
     assert len(events) == 1
     assert events[0].extra["hello1"] == 34