Skip to content

Commit

Permalink
🐛 fix the conversion issue for long type on python 2. fix #67
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw committed Mar 19, 2019
1 parent 29a7ffc commit 4034787
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pyexcel_io/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def boolean_value(value):

if PY2:
ODS_WRITE_FORMAT_COVERSION[unicode] = "string" # noqa: F821
ODS_WRITE_FORMAT_COVERSION[long] = "throw_exception" # noqa: F821
ODS_WRITE_FORMAT_COVERSION[long] = "long" # noqa: F821


VALUE_CONVERTERS = {
Expand All @@ -198,7 +198,7 @@ def throw_exception(value):


def ods_float_value(value):
if int(value) > int(constants.MAX_INTEGER):
if value > constants.MAX_INTEGER:
raise exceptions.IntegerAccuracyLossError("%s is too big" % value)
return value

Expand Down Expand Up @@ -234,7 +234,7 @@ def ods_timedelta_value(cell):
"boolean": ods_bool_value,
"timedelta": ods_timedelta_value,
"float": ods_float_value,
"throw_exception": throw_exception
"long": ods_float_value
}


Expand Down
18 changes: 18 additions & 0 deletions tests/test_service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from nose.tools import eq_, raises
from pyexcel_io.service import date_value, time_value
from pyexcel_io.service import detect_int_value
Expand All @@ -9,6 +10,8 @@
from pyexcel_io.exceptions import IntegerAccuracyLossError
from nose import SkipTest

PY2 = sys.version[0] == 2


def test_date_util_parse():
value = "2015-08-17T19:20:00"
Expand Down Expand Up @@ -110,6 +113,21 @@ def test_big_int_value():
ods_float_value(1000000000000000)


def test_max_value_on_python_2():
if PY2:
ods_float_value(long(999999999999999))
else:
raise SkipTest("No long in python 3")


@raises(IntegerAccuracyLossError)
def test_really_long_value_on_python2():
if PY2:
ods_float_value(long(999999999999999+1))
else:
raise SkipTest("No long in python 3")


@raises(IntegerAccuracyLossError)
def test_throw_exception():
throw_exception(1000000000000000)

0 comments on commit 4034787

Please sign in to comment.