def test_if_value_is_returned(self, python_logger): logger = ULog(logger=python_logger) @logger.log_args(msg=ERROR_MSG, arguments=('p1', )) def f(p1, kw1=''): return RETURN_VALUE return_value = f('v1') assert return_value == RETURN_VALUE
def test_if_value_is_returned(self, python_logger): logger = ULog(logger=python_logger) @logger.log_return(msg=ERROR_MSG) def f(): return RETURN_VALUE return_value = f() assert return_value == RETURN_VALUE
def test_if_selected_paramet_is_logged(self, python_logger): logger = ULog(logger=python_logger) @logger.log_args(msg=ERROR_MSG, arguments=('p1', )) def f(p1, kw1=''): pass f('v1') python_logger.log.assert_called_with(10, 'msg\np1: v1', exc_info=False)
def test_if_the_same_log_level_is_loged(self, python_logger): logger = ULog(logger=python_logger) @logger.log_return(msg=ERROR_MSG, level=LogLevel.Debug) def f(): return RETURN_VALUE f() assert python_logger.log.call_count == 1
def test_if_the_same_log_level_is_loged(self, python_logger): logger = ULog(logger=python_logger) @logger.log_args(msg=ERROR_MSG, arguments=('p1', ), level=LogLevel.Debug) def f(p1, kw1=''): return RETURN_VALUE f('v1') assert python_logger.log.call_count == 1
def test_if_return_value_is_returned_when_there_is_no_exception( self, python_logger): logger = ULog(logger=python_logger) @logger.log_exception(ERROR_MSG, level=LogLevel.Debug) def myfunc(): return RETURN_VALUE return_value = myfunc() assert python_logger.log.call_count == 0 assert return_value == RETURN_VALUE
def test_if_the_same_log_level_is_loged(self, python_logger): logger = ULog(logger=python_logger) exception = FakeException() @logger.log_exception(ERROR_MSG, level=LogLevel.Debug) def myfunc(): raise exception with pytest.raises(FakeException): myfunc() assert python_logger.log.call_count == 1
def test_if_logger_is_called_for_loggin_exception(self, python_logger): logger = ULog(logger=python_logger) exception = FakeException() @logger.log_exception(msg=ERROR_MSG) def myfunc(): raise exception with pytest.raises(FakeException): myfunc() python_logger.log.assert_called_once_with(40, ERROR_MSG, True)
def test_if_all_passed_params_are_logged(self, python_logger): logger = ULog(logger=python_logger) @logger.log_args(msg=ERROR_MSG) def f(p1, kw1=''): pass f('v1', 'v2') python_logger.log.assert_called_with(LogLevel.Debug, 'msg\np1: v1\nkw1: v2', exc_info=False) assert python_logger.log.call_count == 1
def test_if_kwargs_are_logged(self, python_logger): logger = ULog(logger=python_logger) @logger.log_args(msg=ERROR_MSG) def f(p1, p2=''): pass f(p1='v1', p2='v2') call = python_logger.log.call_args[0] logged_message = call[1] assert '\np1: v1' in logged_message assert '\np2: v2' in logged_message assert python_logger.log.call_count == 1
def test_if_log_is_returned(self, python_logger): logger = ULog(logger=python_logger) @logger.log_return() def f(): return RETURN_VALUE f() assert python_logger.log.call_count == 1 call = python_logger.log.call_args[0] logged_message = call[1] assert RETURN_VALUE in logged_message assert LogLevel.Debug == call[0]
import logging from ulog import ULog logging.basicConfig(level=logging.DEBUG) ulog = ULog() class MyException(Exception): def __init__(self, context): self._context = context def __str__(self): return 'My exception with context: %s' % self._context class TestClass(object): @ulog.log_return('Return from function {callable_name}: {return_value}') @ulog.log_exception(msg='OMG!', traceback=True) @ulog.log_args() def divide_func(self, x, y): return x / y tc = TestClass() try: tc.divide_func(0, 0) except: pass
from .sd import setup_sd import uos import network import gc import json from ulog import ULog import machine # RESOURCE_DIR = "app/resources" IMG_PATH_TEMPLATE = "app/resources/{}__{}__{}.jpg" V1_BASE_PATH = "/api/v1" IMG_API_PATH = "{}/{}".format(V1_BASE_PATH, "retrieve") RESET_API_PATH = "{}/{}".format(V1_BASE_PATH, "reset") IMG_API_CAPTURE_PATH = "{}/{}".format(V1_BASE_PATH, "obtain") logger = ULog("main.py") run_logger = ULog("runtime") LED_PIN = 15 LED = machine.Pin(LED_PIN, machine.Pin.OUT) time.sleep_ms(300) logger.info("led set to pin {}".format(LED_PIN)) LED.off() logger.info("led.off") # TODO: check if connected CAM = None if not CAM: CAM = setup_cam(logger) logger.info("camera setup")
import machine from ulog import ULog from updater.ota_updater import OTAUpdater install_logger = ULog("install") def maybe_download_and_install_update(): install_logger.info("Checking for Updates...") ota_updater = OTAUpdater( "https://github.com/JackBurdick/argus", github_src_dir="src", main_dir="app", secrets_file="secrets.py", ) install_logger.info("ota_updater created") new_update_installed = ota_updater.install_update_if_available() install_logger.info("no new update installed") if new_update_installed: install_logger.info("installed update") install_logger.info("restarting machine") machine.reset() del ota_updater def boot(): maybe_download_and_install_update()