| 118 | |
| 119 | |
| 120 | def 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 | |
| 134 | def test_cast_with_irrelevant_arg(tmp_path): |