-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_loader.py
87 lines (73 loc) · 2.35 KB
/
test_loader.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import pytest
from smlib import fsmBase, loader, fsmLogger, fsmFileLogger, fsmIOs, mappedIOs
@pytest.fixture
def l(scope='module'):
return loader()
def test_setVerbosity(l):
#default value 2=info
assert l._verbosity == 2
assert l._logger._level == 2
# test setting verbosity via number
l.setVerbosity(-1)
assert l._logger._level == 0
assert l._verbosity == 0
l.setVerbosity(0)
assert l._verbosity == 0
assert l._logger._level == 0
l.setVerbosity(1)
assert l._verbosity == 1
assert l._logger._level == 1
l.setVerbosity(2)
assert l._verbosity == 2
assert l._logger._level == 2
l.setVerbosity(3)
assert l._verbosity == 3
assert l._logger._level == 3
l.setVerbosity(4)
assert l._verbosity == 3
assert l._logger._level == 3
# test setting verbosity via string
l.setVerbosity("error")
assert l._verbosity == 0
assert l._logger._level == 0
l.setVerbosity("warning")
assert l._verbosity == 1
assert l._logger._level == 1
l.setVerbosity("info")
assert l._verbosity == 2
assert l._logger._level == 2
l.setVerbosity("debug")
assert l._verbosity == 3
assert l._logger._level == 3
with pytest.raises(KeyError):
l.setVerbosity("otherstring")
def test_logToFile(l):
#default value
assert isinstance(l._logger, fsmLogger)
l.logToFile("dir", "prefix")
assert isinstance(l._logger, fsmFileLogger)
assert l._logger.dir == "dir"
assert l._logger.prefix == "prefix"
assert l._logger._level == l._verbosity
def test_setIoMap(l):
#default
assert isinstance(l._ioManager, fsmIOs)
l.setIoMap("../examples/config/iomap.txt")
assert isinstance(l._ioManager, mappedIOs)
def test_load(l):
#default
assert len(l._fsmsList) == 0
class fsm_fake(fsmBase):
def __init__(self, name, num, **kwargs):
self.timerManager = kwargs.get("tmgr", None)
self.ioManager = kwargs.get("ios", None)
self.logger = kwargs.get("logger", None)
self.args = num
l.load(fsm_fake, "testname", 5)
assert len(l._fsmsList) == 1
loaded = l._fsmsList[0]
assert isinstance(loaded, fsm_fake)
assert loaded.timerManager == l._timerManager
assert loaded.ioManager == l._ioManager
assert loaded.logger == l._logger
assert loaded.args == 5