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

Tests: OverflowError on i686 and mips64el #408

Closed
htgoebel opened this issue Oct 19, 2016 · 7 comments
Closed

Tests: OverflowError on i686 and mips64el #408

htgoebel opened this issue Oct 19, 2016 · 7 comments

Comments

@htgoebel
Copy link

test_date_time_this_period and test_date_time_this_period_with_tzinfo fail on i686 and mips64el. For details please see

ERROR: test_date_time_this_period (faker.tests.FactoryTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/guix-build-python-fake-factory-0.7.2.drv-0/fake-factory-0.7.2/faker/tests/__init__.py", line 376, in test_date_time_this_period
    self.assertTrue(self._datetime_to_time(provider.date_time_this_century(before_now=False, after_now=True)) >= self._datetime_to_time(datetime.datetime.now()))
  File "/tmp/guix-build-python-fake-factory-0.7.2.drv-0/fake-factory-0.7.2/faker/providers/date_time/__init__.py", line 387, in date_time_this_century
    return cls.date_time_between_dates(now, next_century_start, tzinfo)
  File "/tmp/guix-build-python-fake-factory-0.7.2.drv-0/fake-factory-0.7.2/faker/providers/date_time/__init__.py", line 365, in date_time_between_dates
    datetime_to_timestamp(datetime_end),
  File "/tmp/guix-build-python-fake-factory-0.7.2.drv-0/fake-factory-0.7.2/faker/providers/date_time/__init__.py", line 22, in datetime_to_timestamp
    return mktime(dt.timetuple())
OverflowError: mktime argument out of range

======================================================================
ERROR: test_date_time_this_period_with_tzinfo (faker.tests.FactoryTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/guix-build-python-fake-factory-0.7.2.drv-0/fake-factory-0.7.2/faker/tests/__init__.py", line 405, in test_date_time_this_period_with_tzinfo
    provider.date_time_this_century(before_now=False, after_now=True, tzinfo=utc) >= datetime.datetime.now()
  File "/tmp/guix-build-python-fake-factory-0.7.2.drv-0/fake-factory-0.7.2/faker/providers/date_time/__init__.py", line 387, in date_time_this_century
    return cls.date_time_between_dates(now, next_century_start, tzinfo)
  File "/tmp/guix-build-python-fake-factory-0.7.2.drv-0/fake-factory-0.7.2/faker/providers/date_time/__init__.py", line 365, in date_time_between_dates
    datetime_to_timestamp(datetime_end),
  File "/tmp/guix-build-python-fake-factory-0.7.2.drv-0/fake-factory-0.7.2/faker/providers/date_time/__init__.py", line 21, in datetime_to_timestamp
    dt = dt.astimezone(tzlocal())
  File "/gnu/store/3wppcdw10k68aiw2x1r0x2m9zd10lg63-python-dateutil-2.5.2/lib/python3.4/site-packages/python_dateutil-2.5.2-py3.4.egg/dateutil/tz/tz.py", line 99, in utcoffset
    if self._isdst(dt):
  File "/gnu/store/3wppcdw10k68aiw2x1r0x2m9zd10lg63-python-dateutil-2.5.2/lib/python3.4/site-packages/python_dateutil-2.5.2-py3.4.egg/dateutil/tz/tz.py", line 143, in _isdst
    return time.localtime(timestamp+time.timezone).tm_isdst
OverflowError: timestamp out of range for platform time_t
@NathanWailes
Copy link

NathanWailes commented Nov 18, 2016

See:
http://stackoverflow.com/questions/2518706/python-mktime-overflow-error
https://docs.python.org/2/library/time.html#time.mktime
"The earliest date for which it can generate a time is platform-dependent."

@deep-42-thought
Copy link

So can you please disable the respective tests on i686?

@htgoebel
Copy link
Author

htgoebel commented Sep 1, 2017

Disabling tests is a bad idea since it covers problems.

The bug is caused by this line creating a value which not accepted at these platforms:

next_century_start = datetime(this_century_start.year + 100, 1, 1, tzinfo=tzinfo)

The same problem theoretically exists in date_time_this_decade() with next_decade() for the case the tests are run near the end of the supported year-range.

The solution is to use

next_century_start = datetime(min(this_century_start.year + 100, datetime.date.max.year),
                              1, 1, tzinfo=tzinfo)

Same for date_time_this_decade().

Maybe you also want to issue a warning if this case occurs.

@htgoebel
Copy link
Author

htgoebel commented Sep 1, 2017

datetime.MAXYEAR is the same as datetime.date.max.year. You may prefer this

@htgoebel
Copy link
Author

htgoebel commented Sep 1, 2017

Oh, well, this might analysis might be wrong: MAXYEAR is defined to be 9999.

@fcurella
Copy link
Collaborator

fcurella commented Sep 1, 2017

I can switch behavior for 32bit system to something like solution suggested by @htgoebel. What should the max year be on 32bit systems?

@htgoebel
Copy link
Author

htgoebel commented Sep 1, 2017

Depending this on 32-bit is dangerous and wrong: mips64el is 64-bit.

I'm afraid you need to have a deeper look into your code to find out where you query the boundary.

fcurella added a commit that referenced this issue Jun 21, 2018
TODO: remove this as we get closer to 9999
fcurella added a commit that referenced this issue Jun 21, 2018
TODO: remove this as we get closer to 9999
fcurella added a commit that referenced this issue Jun 21, 2018
TODO: remove this as we get closer to 9999
fcurella added a commit that referenced this issue Jun 21, 2018
Close #408. Cap years to 9999 to support 32-bit platforms
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

No branches or pull requests

4 participants