forked from pool/python-Faker
5717d27503
* faker-32bit.patch OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-Faker?expand=0&rev=19
103 lines
3.7 KiB
Diff
103 lines
3.7 KiB
Diff
From 26260b97bee18e2b1ace7cd0f450215f35fd667e Mon Sep 17 00:00:00 2001
|
|
From: Flavio Curella <89607+fcurella@users.noreply.github.com>
|
|
Date: Mon, 11 Mar 2019 13:38:18 -0500
|
|
Subject: [PATCH] Close #912. Skip tests on 32bit systems (#922)
|
|
|
|
---
|
|
.dockerignore | 16 ++++++++++++++++
|
|
.travis.yml | 9 ++++++---
|
|
MANIFEST.in | 3 ++-
|
|
build32bit.sh | 10 ++++++++++
|
|
faker/providers/date_time/__init__.py | 18 ++++++++++++------
|
|
setup.py | 4 ++--
|
|
tests/providers/test_date_time.py | 8 ++++++++
|
|
tox.ini | 8 ++++++--
|
|
8 files changed, 62 insertions(+), 14 deletions(-)
|
|
create mode 100644 .dockerignore
|
|
create mode 100755 build32bit.sh
|
|
|
|
diff --git a/faker/providers/date_time/__init__.py b/faker/providers/date_time/__init__.py
|
|
index ed27c9f4..7158307a 100644
|
|
--- a/faker/providers/date_time/__init__.py
|
|
+++ b/faker/providers/date_time/__init__.py
|
|
@@ -11,8 +11,8 @@
|
|
from dateutil import relativedelta
|
|
from dateutil.tz import tzlocal, tzutc
|
|
|
|
-from faker.utils.datetime_safe import date, datetime, real_date, real_datetime
|
|
from faker.utils import is_string
|
|
+from faker.utils.datetime_safe import date, datetime, real_date, real_datetime
|
|
|
|
from .. import BaseProvider
|
|
|
|
@@ -1664,11 +1664,17 @@ def date_time_between_dates(
|
|
datetime_to_timestamp(datetime_start),
|
|
datetime_to_timestamp(datetime_end),
|
|
)
|
|
- if tzinfo is None:
|
|
- pick = datetime.fromtimestamp(timestamp, tzlocal())
|
|
- pick = pick.astimezone(tzutc()).replace(tzinfo=None)
|
|
- else:
|
|
- pick = datetime.fromtimestamp(timestamp, tzinfo)
|
|
+ try:
|
|
+ if tzinfo is None:
|
|
+ pick = datetime.fromtimestamp(timestamp, tzlocal())
|
|
+ pick = pick.astimezone(tzutc()).replace(tzinfo=None)
|
|
+ else:
|
|
+ pick = datetime.fromtimestamp(timestamp, tzinfo)
|
|
+ except OverflowError:
|
|
+ raise OverflowError(
|
|
+ "You specified an end date with a timestamp bigger than the maximum allowed on this"
|
|
+ " system. Please specify an earlier date.",
|
|
+ )
|
|
return pick
|
|
|
|
def date_between_dates(self, date_start=None, date_end=None):
|
|
diff --git a/tests/providers/test_date_time.py b/tests/providers/test_date_time.py
|
|
index 6f80ed54..67c974cb 100644
|
|
--- a/tests/providers/test_date_time.py
|
|
+++ b/tests/providers/test_date_time.py
|
|
@@ -6,6 +6,7 @@
|
|
import time
|
|
import unittest
|
|
import random
|
|
+import sys
|
|
|
|
import six
|
|
|
|
@@ -18,6 +19,10 @@
|
|
import pytest
|
|
|
|
|
|
+def is64bit():
|
|
+ return sys.maxsize > 2**32
|
|
+
|
|
+
|
|
class UTC(tzinfo):
|
|
"""
|
|
UTC implementation taken from Python's docs.
|
|
@@ -225,6 +230,7 @@ def test_date_between_dates(self):
|
|
def _datetime_to_time(self, value):
|
|
return int(time.mktime(value.timetuple()))
|
|
|
|
+ @unittest.skipUnless(is64bit(), "requires 64bit")
|
|
def test_date_time_this_period(self):
|
|
# test century
|
|
this_century_start = self._datetime_to_time(
|
|
@@ -292,6 +298,7 @@ def test_date_time_this_period(self):
|
|
self._datetime_to_time(datetime.now())
|
|
)
|
|
|
|
+ @unittest.skipUnless(is64bit(), "requires 64bit")
|
|
def test_date_time_this_period_with_tzinfo(self):
|
|
# ensure all methods provide timezone aware datetimes
|
|
with pytest.raises(TypeError):
|
|
@@ -329,6 +336,7 @@ def test_date_time_this_period_with_tzinfo(self):
|
|
replace(second=0, microsecond=0) == datetime.now(utc).replace(second=0, microsecond=0)
|
|
)
|
|
|
|
+ @unittest.skipUnless(is64bit(), "requires 64bit")
|
|
def test_date_this_period(self):
|
|
# test century
|
|
assert self.factory.date_this_century(after_today=False) <= date.today()
|