From c1b1a920002850f20eefbc0101546414aba73d9d Mon Sep 17 00:00:00 2001 From: konstantin Date: Thu, 23 Feb 2023 11:43:02 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=89Add=20logging=20to=20`ListBasedSour?= =?UTF-8?q?ceDataProvider`=20(#31)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bomf/provider/__init__.py | 4 ++++ unittests/test_source_data_provider.py | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/bomf/provider/__init__.py b/src/bomf/provider/__init__.py index 54a0f4f..529b13c 100644 --- a/src/bomf/provider/__init__.py +++ b/src/bomf/provider/__init__.py @@ -2,6 +2,7 @@ providers provide data """ import json +import logging from abc import ABC, abstractmethod from pathlib import Path from typing import Callable, Generic, List, Mapping, Optional, Protocol, TypeVar, Union @@ -50,6 +51,9 @@ def __init__(self, source_data_models: List[SourceDataModel], key_selector: Call """ self._models: List[SourceDataModel] = source_data_models self._models_dict: Mapping[KeyTyp, SourceDataModel] = {key_selector(m): m for m in source_data_models} + logging.getLogger(self.__module__).info( + "Read %i records from %s", len(self._models_dict), str(source_data_models) + ) self.key_selector = key_selector def get_entry(self, key: KeyTyp) -> SourceDataModel: diff --git a/unittests/test_source_data_provider.py b/unittests/test_source_data_provider.py index 0cfbd8c..e0da265 100644 --- a/unittests/test_source_data_provider.py +++ b/unittests/test_source_data_provider.py @@ -1,3 +1,4 @@ +import logging from pathlib import Path from typing import List @@ -42,7 +43,9 @@ def test_json_file_provider(self, datafiles): class TestListBasedSourceDataProvider: - def test_list_based_provider(self): + def test_list_based_provider(self, caplog): + caplog.set_level(logging.DEBUG, logger=ListBasedSourceDataProvider.__module__) my_provider = ListBasedSourceDataProvider(["foo", "bar", "baz"], key_selector=lambda x: x) assert len(my_provider.get_data()) == 3 assert my_provider.get_entry("bar") == "bar" + assert "Read 3 records from ['foo', 'bar', 'baz']" in caplog.messages