powerctl/test.py
2025-01-27 14:15:03 +01:00

30 lines
615 B
Python

import random
import time
from unittest.mock import patch
import paho.mqtt.client as mqtt
import power_mqtt1
class SMBus:
def __init__(self, _bus):
pass
def read_byte(self, _i2c_addr):
time.sleep(5)
return random.randbytes(1)[0]
def write_byte(self, i2c_addr, data):
pass
class MqttClient(mqtt.Client):
def connect(self, host, *args, **kwargs):
return super().connect("127.0.0.1", *args, **kwargs)
with patch('smbus.SMBus', new=SMBus) as SMBus_mock, \
patch("paho.mqtt.client.Client", new=MqttClient) as connect_mock:
power_mqtt1.main()