Skip to content

Commit

Permalink
fix casting of ints
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Saunders committed Aug 16, 2016
1 parent 7a5323d commit fb9a0c8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion kim/pipelines/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ def is_valid_integer(session):
"""

try:
return int(session.data)
session.data = int(session.data)
except TypeError:
raise session.field.invalid(error_type='type_error')
except ValueError:
raise session.field.invalid(error_type='type_error')
return session.data


@pipe()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PyTest(TestCommand):

def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = ['-x', '-s']
self.test_args = ['-s']
self.test_suite = True

def run_tests(self):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_pipelines/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def test_integer_input():
field.marshal(mapper_session)
assert output == {'name': 2}

output = {}
mapper_session = get_mapper_session(
data={'name': '2', 'email': 'mike@mike.com'}, output=output)
field.marshal(mapper_session)
assert output == {'name': 2}


def test_integer_field_invalid_type():

Expand Down Expand Up @@ -122,6 +128,10 @@ def test_min_max():
field.marshal(mapper_session)
assert output == {'age': 25}

mapper_session = get_mapper_session(data={'age': '25'}, output=output)
field.marshal(mapper_session)
assert output == {'age': 25}


def test_is_valid_decimal_pipe():
"""test piping data through is_valid_decimal.
Expand Down

0 comments on commit fb9a0c8

Please sign in to comment.