Skip to content

Commit

Permalink
🔉Add logging to ListBasedSourceDataProvider (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
hf-kklein authored Feb 23, 2023
1 parent 11833b6 commit c1b1a92
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/bomf/provider/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion unittests/test_source_data_provider.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from pathlib import Path
from typing import List

Expand Down Expand Up @@ -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

0 comments on commit c1b1a92

Please sign in to comment.