Skip to content
This repository has been archived by the owner on Oct 3, 2019. It is now read-only.

Commit

Permalink
Add exception for bad type conversion
Browse files Browse the repository at this point in the history
Fixes #8
  • Loading branch information
jacebrowning committed Sep 12, 2014
1 parent 1cab907 commit 589faa1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions yorm/standard.py
Expand Up @@ -47,6 +47,8 @@ def to_value(data):
return text.split(',')
else:
return text.split()
elif data is not None:
return [data]
else:
return []

Expand Down
11 changes: 11 additions & 0 deletions yorm/test/test_standard.py
Expand Up @@ -51,6 +51,7 @@ class TestList:
("a,b,c", ["a", "b", "c"]),
("abc", ["abc"]),
("a\nb\nc", ["a", "b", "c"]),
(4.2, [4.2]),
]

value_data = [
Expand Down Expand Up @@ -119,6 +120,11 @@ def test_to_value(self, data, value):
"""Verify input data is converted to values."""
assert standard.Integer.to_value(data) == value

def test_to_value_error(self):
"""Verify an exception is raised for unconvertible values."""
with pytest.raises(ValueError):
standard.Integer.to_value("abc")

@pytest.mark.parametrize("value,data", value_data)
def test_to_data(self, value, data):
"""Verify values are converted to output data."""
Expand Down Expand Up @@ -147,6 +153,11 @@ def test_to_value(self, data, value):
"""Verify input data is converted to values."""
assert standard.Float.to_value(data) == value

def test_to_value_error(self):
"""Verify an exception is raised for unconvertible values."""
with pytest.raises(ValueError):
standard.Integer.to_value("abc")

@pytest.mark.parametrize("value,data", value_data)
def test_to_data(self, value, data):
"""Verify values are converted to output data."""
Expand Down

0 comments on commit 589faa1

Please sign in to comment.