-
Notifications
You must be signed in to change notification settings - Fork 17
Check Functions do not display datetime comparisons helpfully #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Had a go at replicating this issue but without any luck. Ended up writing some tests for chk_smaller. |
@pazzarpj, have you got a script that shows the error? or can you write a failing test? |
from datetime import datetime, timedelta
from fixate.core.checks import CheckClass, _in_range
from fixate.ui_cmdline.cmd_line import _print_comparisons
chk1 = CheckClass(_min=2, _max=3, test_val=2.5, target=_in_range)
date_thing = datetime(2019, 1, 1, 0, 0)
chk2 = CheckClass(_min=date_thing - timedelta(seconds=2), _max=datetime.now() + timedelta(seconds=2), test_val=date_thing, target=_in_range)
_print_comparisons(True, chk1, 1, None)
_print_comparisons(True, chk2, 2, None) Expected output Check 1: PASS when comparing 2.5 in range 2 - 3 :
Check 2: PASS when comparing 2019-01-01 00:00:00 in range 2018-12-31 23:59:58 - 2019-01-01 00:00:02 : Actual Check 1: PASS when comparing 2.5 in range 2 - 3 :
Check 2: PASS when comparing .3g in range .3g - .3g : |
There seems to be an issue with timestruct objects as well in that script. They're displayed with their data but always pass:
However the issue doesn't seem to occur when using chk_in_range for either timestruct or datetime objects as the following tests pass:
|
The script I provided was to demonstrate the display issue, the CheckClass doesn't actually run the check. _print_comparisons first parameter determines if it displays as pass/fail. The issue is that the _print_comparisons function assumes a number with the {:.3g} string formatter. |
Riiight, i finally get it now. I'll stop barking up the wrong tree. Will look into it when i get a chance. Thanks for slow walking me there. |
Issue found in ui_cmdline\cmd_line.py line 304:
format with decimal places does not produce the desired output but does not raise an error when datetime object is used. Adding an assert math.isclose within the try: rejects the change of format, allowing the original formatting (standard datetime object output) to be shown:
Will run a few more tests and upload the code. |
Comparing datetime functions in a chk_* will show .3g instead of the repr for the datetime object. This could overflow into other object time comparisons that are not float or integer based.
The text was updated successfully, but these errors were encountered: