| Conditions | 1 |
| Total Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | import json |
||
| 9 | def test_json_formatter(self): |
||
| 10 | name = 'name' |
||
| 11 | line = 42 |
||
| 12 | module = 'some_module' |
||
| 13 | func = 'some_function' |
||
| 14 | msg = {'content': 'sample log'} |
||
| 15 | |||
| 16 | log_record = LogRecord( |
||
| 17 | name, INFO, module, line, msg, None, None, func=func |
||
| 18 | ) |
||
| 19 | formatter = JSONFormatter() |
||
| 20 | |||
| 21 | log_result = formatter.format(log_record) |
||
| 22 | result = json.loads(log_result) |
||
| 23 | |||
| 24 | # check some of the fields to ensure json formatted correctly |
||
| 25 | self.assertEqual(name, result['name']) |
||
| 26 | self.assertEqual(line, result['lineNumber']) |
||
| 27 | self.assertEqual(func, result['functionName']) |
||
| 28 | self.assertEqual(module, result['module']) |
||
| 29 | self.assertEqual('INFO', result['level']) |
||
| 30 | self.assertEqual(msg, result['message']) |
||
| 31 |
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.