Open RTnhN opened 1 day ago
Maybe it would be good to extend the tests to include logs with the formats that you support out of the box instead of just plain iso format?
It seems that maybe each instance of strptime_format could just be replaced by the string equivalency of it. For example, strptime_format = "%Y-%m-%d %H:%M:%S,%f"
would be for the comma ms format that I use. The following code will take the string and convert it into a function that will do the actual conversion:
I tested this with my logs, and it worked.
Yeah, I was just looking at that myself. :) It turns out that the fromisoformat
method is tolerant of variations, but only as of Python 3.11. https://docs.python.org/3/library/datetime.html#datetime.datetime.fromisoformat
I need to finish some day job stuff this afternoon/evening, so it will need to wait a day or two. (Test submissions are always welcome PRs, btw.)
Ah, okay. I am on python 3.10 right now. My raspberry pis run python 3.11, and it works as expected there. It would be really nice to have reverse compatibility though.
Great! If I have some time, I will make some more test submissions.
Have you thought about implementing some CI/CD to build and test? For example, you can have it test the build on multiple versions of python: https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-python
It looks like since you use tox for testing, you could just do this: https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-python#running-tests-with-tox
I do this for some other open source projects of mine (pyparsing, and maybe littletable), this one just hasn't reached critical mass yet.
Yes, logmerger is supposed to be compatible back to Python 3.9, so I have tox
configured to test those versions - if only there were some tests for those other formats...
Unit tests could be written without having to have lots of files just by directly testing the TimestampedLineTransformer.make_transformer_from_sample_line
function to get a transformer, and then using that transformer to get an expected datetime.
- if only there were some tests for those other formats...
:) I'll try to get a PR ready for other formats this weekend.
Please follow the pattern of other tests using pytest and pytest.mark.parametrize. And staying at the unit level will make the test more self-contained (won't require lots of extra supporting files).
I envision a unit test that takes a string of any of the supported formats and the expected resulting datetime value, calls TimetstampedLineTransformer.make_transformer_from_sample_line to get a transformer, and then passes the test string to it to get a computed datetime instance, which should match the given expected datetime.
Once we get past this step, the remainder of logmerger will work with the resulting datetimes, so that code is isolated from any particular timestamp format.
You might even give ChatGPT a try at generating such a test - I've found its not too terrible at writing test code.
With the following logs, I ran into a parser issue:
I think that the
datetime.fromisoformat
does not support comma for the millisecond section. For example:but
I think it might need to have a custom written datetime. Actually, it seems that every one of your formatters uses the same
datetime.fromisoformat
function for thestrptime_format
?Here are the two log sections that I was trying to use:
test.log
test2.log