ListLogPrinterTest.test_logging()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
1
import unittest
2
from datetime import datetime
3
4
from coalib.output.printers.ListLogPrinter import ListLogPrinter
5
from coalib.output.printers.LOG_LEVEL import LOG_LEVEL
6
from coalib.processes.communication.LogMessage import LogMessage
7
8
9
class ListLogPrinterTest(unittest.TestCase):
10
11
    def test_logging(self):
12
        uut = ListLogPrinter()
13
        ts = datetime.today()
14
        ts_str = ts.strftime("%X")
15
16
        uut.log_level = LOG_LEVEL.INFO
17
        uut.warn("Test value", timestamp=ts)
18
        uut.print("Test 2", timestamp=ts)  # Should go to INFO
19
        uut.debug("Test 2", timestamp=ts)  # Should not be logged
20
21
        self.assertEqual(uut.logs,
22
                         [LogMessage(LOG_LEVEL.WARNING,
23
                                     "Test value",
24
                                     timestamp=ts),
25
                          LogMessage(LOG_LEVEL.INFO,
26
                                     "Test 2",
27
                                     timestamp=ts)])
28
29
        self.assertRaises(TypeError, uut.log_message, "message")
30