1 | import pytest |
||
2 | import os, sys |
||
3 | import logging |
||
4 | from asyncio import coroutine |
||
5 | |||
6 | import smtplib |
||
7 | from mock import Mock |
||
8 | from mock import patch, call |
||
9 | from mock import MagicMock |
||
10 | from mock import PropertyMock |
||
11 | |||
12 | sys.modules['bleak'] = MagicMock() |
||
13 | from bricknil.process import Process |
||
14 | from bricknil.sensor import TrainMotor |
||
15 | |||
16 | class AsyncMock(MagicMock): |
||
17 | async def __call__(self, *args, **kwargs): |
||
18 | return super(AsyncMock, self).__call__(*args, **kwargs) |
||
19 | |||
20 | |||
21 | class Testbricknil: |
||
22 | |||
23 | def setup(self): |
||
24 | self.p = Process('test') |
||
25 | |||
26 | def test_name(self): |
||
27 | assert self.p.name == 'test' |
||
28 | |||
29 | def test_increment(self): |
||
30 | for i in range(10): |
||
31 | p2 = Process('test2') |
||
32 | assert self.p.id == p2.id-(i+1) |
||
33 | assert p2.__str__() == 'test2.11' |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
34 | assert p2.__repr__() == 'Process("test2")' |
||
35 | |||
36 | def test_messages(self): |
||
37 | self.p.message('hello') |
||
38 | self.p.message_info('hello') |
||
39 | self.p.message_debug('hello') |
||
40 | self.p.message_error('hello') |
||
41 | |||
42 | @pytest.mark.curio |
||
43 | #@patch('test_bricknil.TrainMotor.set_output', new_callable=AsyncMock) |
||
44 | async def test_motor(self): |
||
45 | m = TrainMotor('motor') |
||
46 | m.set_output = Mock(side_effect=coroutine(lambda x,y :'the awaitable should return this')) |
||
47 | await m.set_speed(10) |
||
48 | assert m.set_output.call_args == call(0, 10) |
||
49 | |||
50 |