def __init__(self, log_file: Union[str, Path]): self.log_file = Path(log_file) self.log_file.parent.mkdir(parents=True, exist_ok=True) self.write_log_line( indexes.index_to_str(indexes.Index.HEADER), {'init': self.__class__.__name__} )
def test_index_to_str(): assert indexes.index_to_str(100) == "int100" assert indexes.index_to_str(0) == "int0" date = datetime.fromtimestamp(1607727600.0, tz=timezone.utc) assert indexes.index_to_str(date) == "ts1607727600.0" assert indexes.index_to_str(indexes.Index.HEADER) == "HEADER" for malformed_index in [1.0, True, "invalid", object()]: with pytest.raises(TypeError): indexes.index_to_str(malformed_index)
def log_results(self, dictionary: Optional[Dict] = None, **kwargs): index_str = indexes.index_to_str(indexes.Index.END) params = unite_kwargs(dictionary, **kwargs) self.write_log_line(index_str, params)
def log_event(self, index: Union[int, datetime], dictionary: Optional[Dict] = None, **kwargs): index_str = indexes.index_to_str(index) params = unite_kwargs(dictionary, **kwargs) self.write_log_line(index_str, params)