🐛 fix bugs during integration tests

This commit is contained in:
chfw 2018-11-26 07:19:51 +00:00
parent a62527e7de
commit e37ed9f6e4
2 changed files with 16 additions and 10 deletions

View File

@ -99,16 +99,10 @@ def detect_int_value(cell_text, pep_0515_off=True):
def float_value(value):
"""convert a value to float"""
if value > constants.MAX_INTEGER:
raise exceptions.IntegerAccuracyLossError("%s is too big" % value)
ret = float(value)
return ret
def throw_exception(value):
raise exceptions.IntegerAccuracyLossError("%s is too big" % value)
def date_value(value):
"""convert to data value accroding ods specification"""
ret = "invalid"
@ -176,6 +170,7 @@ ODS_FORMAT_CONVERSION = {
ODS_WRITE_FORMAT_COVERSION = {
float: "float",
int: "float",
str: "string",
datetime.date: "date",
datetime.time: "time",
@ -184,8 +179,8 @@ ODS_WRITE_FORMAT_COVERSION = {
}
if PY2:
ODS_WRITE_FORMAT_COVERSION[unicode] = "string"
ODS_WRITE_FORMAT_COVERSION[long] = "throw_exception"
ODS_WRITE_FORMAT_COVERSION[unicode] = "string" # noqa: F821
ODS_WRITE_FORMAT_COVERSION[long] = "throw_exception" # noqa: F821
VALUE_CONVERTERS = {
@ -198,6 +193,16 @@ VALUE_CONVERTERS = {
}
def throw_exception(value):
raise exceptions.IntegerAccuracyLossError("%s is too big" % value)
def ods_float_value(value):
if value > constants.MAX_INTEGER:
raise exceptions.IntegerAccuracyLossError("%s is too big" % value)
return value
def ods_date_value(value):
return value.strftime("%Y-%m-%d")
@ -228,6 +233,7 @@ ODS_VALUE_CONVERTERS = {
"time": ods_time_value,
"boolean": ods_bool_value,
"timedelta": ods_timedelta_value,
"float": ods_float_value,
"throw_exception": throw_exception
}

View File

@ -3,7 +3,7 @@ from pyexcel_io.service import date_value, time_value
from pyexcel_io.service import detect_int_value
from pyexcel_io.service import detect_float_value
from pyexcel_io.service import ODS_WRITE_FORMAT_COVERSION
from pyexcel_io.service import float_value
from pyexcel_io.service import ods_float_value
from pyexcel_io.service import throw_exception
from pyexcel_io._compact import PY2
from pyexcel_io.exceptions import IntegerAccuracyLossError
@ -107,7 +107,7 @@ def test_ods_write_format_conversion():
@raises(IntegerAccuracyLossError)
def test_big_int_value():
float_value(1000000000000000)
ods_float_value(1000000000000000)
@raises(IntegerAccuracyLossError)