-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmock_ifs_test.py
executable file
·56 lines (49 loc) · 1.62 KB
/
mock_ifs_test.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright 2020-2021 by Murray Altheim. All rights reserved. This file is part
# of the Robot Operating System project, released under the MIT License. Please
# see the LICENSE file included as part of this package.
#
# author: Murray Altheim
# created: 2020-05-19
# modified: 2020-11-06
#
# dd mock IFS that responds to key presses
#
import sys, time, traceback
from colorama import init, Fore, Style
init()
try:
import pytest
except ImportError:
sys.exit(Fore.RED + "This script requires the pytest module.\nInstall with: pip3 install --user pytest" + Style.RESET_ALL)
from mock.message_bus import MockMessageBus
from mock.ifs import MockIntegratedFrontSensor
from lib.logger import Logger, Level
# ..............................................................................
@pytest.mark.unit
def test_mock_ifs():
_log = Logger('mock-ifs-test', Level.INFO)
time.sleep(1.0)
_message_bus = MockMessageBus(Level.INFO)
_ifs = MockIntegratedFrontSensor(_message_bus, Level.INFO)
_message_bus.set_ifs(_ifs)
_ifs.enable()
while _ifs.enabled:
time.sleep(1.0)
_ifs.close()
_log.info('test complete.')
# ..............................................................................
def main():
try:
test_mock_ifs()
except KeyboardInterrupt:
print(Fore.RED + 'Ctrl-C caught; exiting...' + Style.RESET_ALL)
except Exception as e:
print(Fore.RED + Style.BRIGHT + 'error starting ifs: {}\n{}'.format(e, traceback.format_exc()) + Style.RESET_ALL)
finally:
pass
if __name__== "__main__":
main()
#EOF