-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
generalize and test replay, fix comments
- Loading branch information
Showing
6 changed files
with
121 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.pyc | ||
*.pyo | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
|
||
from ooi.logging import config | ||
import logging | ||
import unittest | ||
from unittest.case import TestCase | ||
import os.path | ||
import os | ||
import ooi.exception | ||
import ooi.logging.replay | ||
|
||
RAW_LOGFILE='/tmp/unittest-raw.log' | ||
REPLAY_LOGFILE='/tmp/unittest-replay.log' | ||
CONFIGFILE='logging.yml' | ||
|
||
class TestRawLogger(TestCase): | ||
def setUp(self): | ||
# clear file | ||
try: os.remove(RAW_LOGFILE) | ||
except: pass | ||
try: os.remove(REPLAY_LOGFILE) | ||
except: pass | ||
# configure logging system | ||
path = os.path.dirname(__file__) + '/' + CONFIGFILE | ||
config.replace_configuration(path) | ||
self.log = logging.getLogger('raw') | ||
|
||
replay_log = logging.getLogger('replay') | ||
handler = replay_log.handlers[0] | ||
self.replay = ooi.logging.replay.Replayer(handler) | ||
|
||
def tearDown(self): | ||
try: os.remove(RAW_LOGFILE) | ||
except: pass | ||
try: os.remove(REPLAY_LOGFILE) | ||
except: pass | ||
|
||
def read_file(self): | ||
with open(REPLAY_LOGFILE, 'r') as f: | ||
contents = f.readlines() | ||
self.count = len(contents) | ||
|
||
def test_simple_message(self): | ||
""" make sure message makes file grow """ | ||
self.assertEquals(0, os.path.getsize(RAW_LOGFILE)) | ||
self.log.info("short message") | ||
self.replay.relay(RAW_LOGFILE) | ||
self.assertTrue(os.path.getsize(REPLAY_LOGFILE)>0) | ||
self.read_file() | ||
self.assertEquals(1, self.count) | ||
|
||
def test_multiple_messages(self): | ||
""" multiple log statements can be read back as multiple dictionaries """ | ||
self.assertEquals(0, os.path.getsize(RAW_LOGFILE)) | ||
self.log.info("short message") | ||
self.log.info("another short message") | ||
self.log.info("a third short message") | ||
self.replay.relay(RAW_LOGFILE) | ||
self.assertTrue(os.path.getsize(REPLAY_LOGFILE)>0) | ||
self.read_file() | ||
self.assertEquals(3, self.count) | ||
|
||
def test_multi_line_messages(self): | ||
""" newline won't break parsing back to dict """ | ||
self.assertEquals(0, os.path.getsize(RAW_LOGFILE)) | ||
self.log.info("short message") | ||
self.log.info("this message\nspans multiple\nlines of text") | ||
self.replay.relay(RAW_LOGFILE) | ||
self.assertTrue(os.path.getsize(REPLAY_LOGFILE)>0) | ||
self.read_file() | ||
self.assertTrue(self.count>2) | ||
|
||
def test_messages_with_stack(self): | ||
""" record can contain stack trace """ | ||
self.assertEquals(0, os.path.getsize(RAW_LOGFILE)) | ||
try: | ||
awjrht() | ||
except: | ||
self.log.info("message and stack", exc_info=True) | ||
self.replay.relay(RAW_LOGFILE) | ||
self.assertTrue(os.path.getsize(REPLAY_LOGFILE)>0) | ||
self.read_file() | ||
self.assertTrue(self.count>1) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters