Skip to content
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

Unit tests fail when run in Adelaide, Australia #322

Open
dcrowe opened this issue Dec 17, 2019 · 3 comments · May be fixed by #323
Open

Unit tests fail when run in Adelaide, Australia #322

dcrowe opened this issue Dec 17, 2019 · 3 comments · May be fixed by #323

Comments

@dcrowe
Copy link

dcrowe commented Dec 17, 2019

Hi, I've been having a play with your nice library but I've discovered that lots of unit tests fail when my machine is in my local timezone "Australian Central Daylight Time". The unit tests pass if I change to a northern hemisphere timezone like Central Standard Time.

I've inspected one of the tests and it appears to assume that it is not DST during 2012-01-14 which is true for the North America, but not Australia.

I'm happy to have a go at fixing this, and I have a fix that I think works, but would like your feedback on if it is the correct way to go.

@dcrowe
Copy link
Author

dcrowe commented Dec 17, 2019

My proposed fix for test_import_time is:

+LOCAL_TIMEZONE = datetime.datetime.now(datetime.timezone.utc).astimezone().tzinfo

 @freeze_time("2012-01-14")
 def test_import_time():
     local_time = datetime.datetime(2012, 1, 14)
-    utc_time = local_time - datetime.timedelta(seconds=time.timezone)
+    utc_time = local_time + LOCAL_TIMEZONE.utcoffset(local_time)
     expected_timestamp = time.mktime(utc_time.timetuple())
     assert fake_time_function() == expected_timestamp

@boxed
Copy link
Contributor

boxed commented Dec 17, 2019

I believe the tests are wrong by not working in UTC and #89 not being fixed.

This issue and #89 seems to me to be the same thing. I just haven't had the time/motivation to tackle this. I would love it if someone made an attempt!

@dcrowe
Copy link
Author

dcrowe commented Dec 17, 2019

How about a change more along these lines?

 @freeze_time("2012-01-14")
 def test_import_time():
-    local_time = datetime.datetime(2012, 1, 14)
-    utc_time = local_time - datetime.timedelta(seconds=time.timezone)
-    expected_timestamp = time.mktime(utc_time.timetuple())
+    expected_time = datetime.datetime(2012, 1, 14, tzinfo=datetime.timezone.utc)
+    expected_timestamp = calendar.timegm(expected_time.timetuple())
     assert fake_time_function() == expected_timestamp

@dcrowe dcrowe linked a pull request Dec 17, 2019 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants