-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathtest.py
51 lines (36 loc) · 1.56 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import sys
import types
import unittest
if sys.version_info >= (3, 4):
from importlib.machinery import SourceFileLoader
loader = SourceFileLoader('rollbar-agent', './rollbar-agent')
rollbar_agent = types.ModuleType(loader.name)
loader.exec_module(rollbar_agent)
else:
import imp
rollbar_agent = imp.load_source('rollbar-agent', './rollbar-agent')
class FakeScanner:
def __init__(self, config):
self.config = config
class TestDefaultMessageStartParserUsage(unittest.TestCase):
app = {'name': 'pyramid',
'config': {
'log_format.default': 'pyramid',
'log_format.patterns': 'celery*.log celery_process',
'min_log_level': 'INFO'
}
}
def test_process_log_debug_with_format_name(self):
# check if self.default_parser uses valid format name provided in the config
config = {'_formats': {'pyramid': {'name': 'pyramid'}}}
scanner = FakeScanner(config)
new_processor = rollbar_agent.LogFileProcessor(scanner, self.app)
self.assertEqual('pyramid', new_processor.default_parser['name'])
def test_process_log_debug_without_format_name(self):
# check if self.default_parser can access _default_message_start_parser if format name not provided in config
config = {'_formats': {}}
scanner = FakeScanner(config)
new_processor = rollbar_agent.LogFileProcessor(scanner, self.app)
self.assertEqual('default parser', new_processor.default_parser['name'])
if __name__ == '__main__':
unittest.main()