Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve tests #31

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion modules/display/mip_sharp_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def init_buffer(self):
self.img_buff_rgb8 = np.zeros(
(self.config.G_HEIGHT, self.buff_width), dtype="uint8"
)
self.pre_img = np.full((self.config.G_HEIGHT, self.buff_width), 255, dtype="uint8")
self.pre_img = np.full(
(self.config.G_HEIGHT, self.buff_width), 255, dtype="uint8"
)
self.img_buff_rgb8[:, 0] = UPDATE_MODE
# address is set in reversed bits
self.img_buff_rgb8[:, 1] = [
Expand Down
4 changes: 1 addition & 3 deletions modules/helper/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,7 @@ async def send_livetrack_data_internal(self, quick_send=False):

# close connection
if self.config.G_THINGSBOARD_API["AUTO_UPLOAD_VIA_BT"]:
bt_pan_status = await self.config.bluetooth_tethering(
disconnect=True
)
bt_pan_status = await self.config.bluetooth_tethering(disconnect=True)
self.bt_cmd_lock = False
network_status = self.config.detect_network()
# print("[BT] {} disconnect, network status:{}".format(timestamp_str, network_status))
Expand Down
2 changes: 1 addition & 1 deletion modules/helper/ble_gatt_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def send_message(self, value):

def atob(self, matchobj):
r = base64.b64decode(matchobj.group(1)).decode()
return f"\"{r}\""
return f'"{r}"'

# receive from central
@characteristic(rx_characteristic_uuid, CharFlags.WRITE).setter
Expand Down
1 change: 0 additions & 1 deletion modules/sensor/sensor_ant.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,3 @@ def set_light_mode(self, mode, auto=False):
self.device[
self.config.G_ANT["ID_TYPE"]["LGT"]
].send_light_setting_light_off_flash_low(auto)

Empty file added tests/__init__.py
Empty file.
35 changes: 26 additions & 9 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,36 @@ class LocalConfig:
G_LOG_DIR = "/tmp" # nosec
G_UNIT_ID_HEX = 0x12345678

G_LOG_START_DATE = None

class TestLogger(unittest.TestCase):
def test_logger_fit_cython(self):
logger = LoggerFit(LocalConfig)

class TestLoggerCsv(unittest.TestCase):
def test_write_log(self):
config = LocalConfig()
logger = LoggerCsv(config)
result = logger.write_log()
self.assertTrue(result)
self.assertEqual(config.G_LOG_START_DATE, "20230928223913")


class TestLoggerFit(unittest.TestCase):
def test_write_logs(self):
config = LocalConfig()
logger = LoggerFit(config)
result = logger.write_log_cython()
self.assertTrue(result)
self.assertEqual(config.G_LOG_START_DATE, "20230928223913")

filename = f"{config.G_LOG_DIR}/{config.G_LOG_START_DATE}.fit"

with open(filename, "rb") as f:
cython_data = f.read()

def test_logger_fit_python(self):
logger = LoggerFit(LocalConfig)
result = logger.write_log_python()
self.assertTrue(result)
self.assertEqual(config.G_LOG_START_DATE, "20230928223913")

def test_logger_fit_csv(self):
logger = LoggerCsv(LocalConfig)
result = logger.write_log()
self.assertTrue(result)
with open(filename, "rb") as f:
python_data = f.read()

self.assertEqual(cython_data, python_data)