-
Notifications
You must be signed in to change notification settings - Fork 1
/
threaded_mock.py
56 lines (48 loc) · 1.57 KB
/
threaded_mock.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
import threading
import os
import time
import logging
from mock.mockservice import MockService
from lib.animator import RepeatMode
from lib.dsl import (
create_animation_action,
create_behavior,
mock_datapoint,
_mocked_datapoints,
)
from lib.trigger import ClockTrigger
# Configure the root logger
root_log = logging.getLogger()
root_log.setLevel(logging.DEBUG)
# Configure a console handler to display log messages on the command line
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.DEBUG)
# Create a formatter with your desired log message format
formatter = logging.Formatter('%(asctime)s [%(threadName)s] [%(name)s] [%(levelname)s] %(message)s')
console_handler.setFormatter(formatter)
# Add the console handler to the root logger
root_log.addHandler(console_handler)
# Rest of your code
MOCK_ADDRESS = os.getenv("MOCK_ADDR", "0.0.0.0:50053")
if __name__ == "__main__":
mock = MockService(MOCK_ADDRESS)
# Set the logger for the mock instance to the root logger
mock.log = root_log
threading.Thread(target=mock.main_loop).start()
print(_mocked_datapoints)
time.sleep(10)
mock_datapoint(
path="Vehicle.Width",
initial_value=0.0,
behaviors=[
create_behavior(
trigger=ClockTrigger(0),
action=create_animation_action(
duration=10.0,
repeat_mode=RepeatMode.REPEAT,
values=[0, 30.0, 50.0, 70.0, 100.0, 70.0, 50.0, 30.0, 0.0],
),
)
],
)
print(_mocked_datapoints)