FreeDATA/tnc/selftest.py

75 lines
1.9 KiB
Python
Raw Normal View History

2022-11-05 21:27:33 +00:00
"""
simple TNC self tests
"""
# -*- coding: utf-8 -*-
# pylint: disable=invalid-name, line-too-long, c-extension-no-member
# pylint: disable=import-outside-toplevel, attribute-defined-outside-init
import sys
import structlog
2023-04-26 16:23:49 +00:00
2022-11-05 21:27:33 +00:00
log = structlog.get_logger("selftest")
class TEST():
def __init__(self):
log.info("[selftest] running self tests...")
if self.run_tests():
log.info("[selftest] passed -> starting TNC")
else:
log.error("[selftest] failed -> closing TNC")
sys.exit(0)
def run_tests(self):
return bool(
self.check_imports()
and self.check_sounddevice()
and self.check_helpers()
)
def check_imports(self):
try:
import argparse
import atexit
import multiprocessing
import os
import signal
import socketserver
import sys
import threading
import time
import structlog
import crcengine
import ctypes
import glob
import enum
import numpy
import sounddevice
return True
except Exception as e:
log.info("[selftest] [check_imports] [failed]", e=e)
return False
def check_sounddevice(self):
try:
import audio
audio.get_audio_devices()
return True
except Exception as e:
log.info("[selftest] [check_sounddevice] [failed]", e=e)
return False
def check_helpers(self):
try:
import helpers
valid_crc24 = "f86ed0"
if helpers.get_crc_24(b"test").hex() == valid_crc24:
return True
else:
raise Exception
except Exception as e:
log.info("[selftest] [check_helpers] [failed]", e=e)
return False