-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest__get_param.py
More file actions
113 lines (74 loc) · 2.24 KB
/
Copy pathtest__get_param.py
File metadata and controls
113 lines (74 loc) · 2.24 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from pytest import raises, warns
from TMCL import Reply
from TMCL.tmcl_commands import Command
from TMCL.module import Module
class SuccessException (BaseException): pass
class Bus (object):
def send (self, address, cmd, type=0, motbank=0, value=0):
return Reply()
class Test__Module__get_param (object):
def test__if_param_is_int_then_bank_must_be_set (self):
module = Module(Bus())
## Should pass
module.get_param(123, bank=1)
module.get_param(123,2)
## Should raise
with raises(AssertionError):
module.get_param(123)
def test__if_param_is_tuple_it_must_be_valid (self):
module = Module(Bus())
## Should pass
module.get_param((1,2))
module.get_param((0,22))
## Should raise
with raises(AssertionError):
module.get_param( (1,2,3) )
with raises(AssertionError):
module.get_param( (1, 'not an int') )
with raises(AssertionError):
module.get_param( () )
def test__if_param_is_tuple_setting_bank_will_warn (self):
module = Module(Bus())
## Should pass
with warns(None) as warnings:
module.get_param( (0, 123) )
module.get_param( 123, 0 )
assert len(warnings) == 0
with warns(UserWarning) as warnings:
module.get_param( (0, 123), 123)
module.get_param( (0, 123), bank=1)
assert len(warnings) == 2
def test__bank_arg_must_be_0_1_2 (self):
module = Module(Bus())
with raises(AssertionError):
module.get_param(123, 10)
with raises(AssertionError):
module.get_param(123, 'not an integer')
def test__sends_correct_instruction_to_bus (self):
ADDRESS = 4
CMD = Command.GGP
PARAM = 22
BANK = 2
VALUE = 0
class Bus:
def send (self, address, instruction):
assert address == ADDRESS
assert instruction.cmd == CMD
assert instruction.type == PARAM
assert instruction.motbank == BANK
assert instruction.value == 0
raise SuccessException()
module = Module(Bus(), address=ADDRESS)
with raises(SuccessException):
module.get_param((BANK, PARAM))
with raises(SuccessException):
module.get_param( PARAM, BANK )
def test__returns_reply_value (self):
VALUE = 142
class Bus:
def send (self, address, instruction):
reply = Reply()
reply.value = VALUE
return reply
module = Module(Bus())
assert module.get_param(123,0) == VALUE