MCPcopy Create free account
hub / github.com/Delgan/loguru / test_cast_function

Function test_cast_function

tests/test_parse.py:120–131  ·  view source on GitHub ↗
(tmp_path)

Source from the content-addressed store, hash-verified

118
119
120def test_cast_function(tmp_path):
121 file = tmp_path / "test.log"
122 file.write_text("[123] [1.1] [2017-03-29 11:11:11]\n")
123 regex = r"\[(?P<num>.*)\] \[(?P<val>.*)\] \[(?P<date>.*)\]"
124
125 def caster(groups):
126 groups["num"] = int(groups["num"])
127 groups["val"] = float(groups["val"])
128 groups["date"] = datetime.strptime(groups["date"], "%Y-%m-%d %H:%M:%S")
129
130 result = next(logger.parse(file, regex, cast=caster))
131 assert result == dict(num=123, val=1.1, date=datetime(2017, 3, 29, 11, 11, 11))
132
133
134def test_cast_with_irrelevant_arg(tmp_path):

Callers

nothing calls this directly

Calls 2

datetimeClass · 0.90
parseMethod · 0.80

Tested by

no test coverage detected