-
Notifications
You must be signed in to change notification settings - Fork 269
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
Update unit tests to pass in different timezones #323
base: master
Are you sure you want to change the base?
Conversation
That _Utc class was totalled not needed. It is much simpler now. I understand that this doesn't interact well with #89, but I'm looking for a smaller issue to chew on for my first contribution. :) Tested in the following timezones:
|
utc_time = local_time - datetime.timedelta(seconds=time.timezone) | ||
expected_timestamp = time.mktime(utc_time.timetuple()) | ||
utc_time = datetime.datetime(2012, 1, 14) | ||
expected_timestamp = calendar.timegm(utc_time.timetuple()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a sorta clunky way to get a timestamp for UTC, how about this:
utc_time = datetime.datetime(2012, 1, 14, tzinfo=datetime.timezone.utc)
expected_timestamp = utc_time.timestamp()
datetime_from_time = datetime.datetime.fromtimestamp(time.time()) | ||
timezone_adjusted_datetime = datetime_from_time + datetime.timedelta(seconds=time.timezone) | ||
assert timezone_adjusted_datetime == expected_datetime | ||
datetime_from_time = datetime.datetime.utcfromtimestamp(time.time()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced that this is the right thing to do, but I also don't think the assertion this replaces makes much sense.
It seems to be asserting that datetime.datetime.now()
should not be equal to datetime.fromtimestamp(time.time())
if the test is run in a locale with an offset, which is not the same behavior as what datetime.datetime
does. Fixing this assumption in the tests (and code?) is how this should be fixed, I think.
I think it would probably be a good idea to add a CI job that runs the tests in some non-UTC locale (or possibly in a few locales). Presumably it's OK to just use whatever the latest Python is and run the test suite in a |
Fixes #322