Skip to content

Commit

Permalink
Close joke2k#912. Skip tests on 32bit systems (joke2k#922)
Browse files Browse the repository at this point in the history
  • Loading branch information
fcurella authored Mar 11, 2019
1 parent 5f3bc39 commit 26260b9
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 14 deletions.
16 changes: 16 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.git/

build
dist
*.egg-info
*.egg/
*.pyc
*.swp

.tox
.coverage
html/*
__pycache__

# Compiled Documentation
docs/_build
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ branches:

matrix:
include:
- python: 3.7
env: TOXENV=flake8
- python: 3.7
env: TOXENV=checkmanifest
- python: 2.7
env: TOXENV=py27
- python: 3.4
Expand All @@ -23,9 +27,8 @@ matrix:
- python: pypy3.5-6.0
env: TOXENV=pypy3
- python: 3.7
env: TOXENV=flake8
- python: 3.7
env: TOXENV=checkmanifest
os: linux
env: TOXENV=32bit

install:
- pip install tox
Expand Down
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ recursive-include tests *.json
recursive-include tests *.py

global-exclude *.py[cod] __pycache__ *.so
exclude Makefile tox.ini .coveragerc .bumpversion.cfg
exclude Makefile tox.ini .coveragerc .bumpversion.cfg .dockerignore
exclude ISSUE_TEMPLATE.md PULL_REQUEST_TEMPLATE.md
exclude appveyor.yml readthedocs.yml
exclude build32bit.sh
prune docs
prune .circleci

10 changes: 10 additions & 0 deletions build32bit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

docker run -v ${PWD}:/code -e INSTALL_REQUIREMENTS=${INSTALL_REQUIREMENTS} i386/ubuntu bash -c "
apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq python3 locales python3-pip debianutils \
&& pip3 install tox coveralls \
&& locale-gen en_US.UTF-8 \
&& cd /code \
&& coverage run --source=faker setup.py test \
&& coverage report"
18 changes: 12 additions & 6 deletions faker/providers/date_time/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Software Development :: Testing',
'Topic :: Utilities',
'License :: OSI Approved :: MIT License'
'License :: OSI Approved :: MIT License',
],
keywords='faker fixtures data test mock generator',
author='joke2k',
Expand Down Expand Up @@ -80,5 +80,5 @@
':python_version=="2.7"': [
'ipaddress',
],
}
},
)
8 changes: 8 additions & 0 deletions tests/providers/test_date_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import time
import unittest
import random
import sys

import six

Expand All @@ -18,6 +19,10 @@
import pytest


def is64bit():
return sys.maxsize > 2**32


class UTC(tzinfo):
"""
UTC implementation taken from Python's docs.
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 6 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist=py{27,34,35,36,37,py,py3},flake8,checkmanifest
envlist=py{27,34,35,36,37,py,py3},32bit,flake8,checkmanifest
skip_missing_interpreters = true

[testenv]
Expand All @@ -24,6 +24,10 @@ deps =
commands =
check-manifest

[testenv:32bit]
basepython = python
commands = ./build32bit.sh

[flake8]
max-line-length = 120
exclude = faker/lib,faker/bin
exclude = faker/lib,faker/bin,.eggs,docs

0 comments on commit 26260b9

Please sign in to comment.