Skip to content

Commit 32d165a

Browse files
committed
Adding log tests
1 parent 7274070 commit 32d165a

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

tests/test_formats.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ def __init__(self, color):
3939

4040
self.assertEqual(json.loads(result), {'children': [{'color': 'red'}, {'color': 'green'}]})
4141

42+
def test_nonempty_attributes(self):
43+
'''Only nonempty attributes are serialized'''
44+
class MyTest(JSONObject):
45+
def __init__(self):
46+
self.a = '1'
47+
self.b = False
48+
self.c = None
49+
self.d = []
50+
result = MyTest().toJSON()
51+
52+
self.assertEqual(json.loads(result), {'a': '1', 'b': False, 'd': []})
53+
4254

4355
if __name__=='__main__':
4456
unittest.main()

tests/test_log.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python
2+
"""
3+
Test the stackify.log module
4+
"""
5+
6+
import unittest
7+
from mock import patch, Mock
8+
import json
9+
10+
import stackify.log
11+
12+
from stackify.log import LogMsg
13+
import logging
14+
import json
15+
import time
16+
#logging.LogRecord('name','level','pathname','lineno','msg','args','exc_info','func')
17+
18+
19+
class TestLogPopulate(unittest.TestCase):
20+
'''
21+
Test populating log objects with data
22+
'''
23+
24+
def test_record_to_error(self):
25+
'''LogMsgs can load logger records'''
26+
record = logging.LogRecord('name',logging.WARNING,'pathname',32,
27+
'message',(),(),'func')
28+
record.my_extra = [1,2,3]
29+
msg = LogMsg()
30+
msg.from_record(record)
31+
32+
curr_ms = time.time() * 1000
33+
34+
self.assertEqual(msg.SrcMethod, 'func')
35+
self.assertEqual(msg.SrcLine, 32)
36+
self.assertEqual(msg.Th, 'MainThread')
37+
self.assertEqual(msg.Msg, 'message')
38+
self.assertTrue(msg.EpochMs <= curr_ms)
39+
self.assertEqual(json.loads(msg.data), {'my_extra':[1,2,3]})
40+
41+
42+
if __name__=='__main__':
43+
unittest.main()
44+

0 commit comments

Comments
 (0)