Skip to content

Commit

Permalink
Bring field2int under test.
Browse files Browse the repository at this point in the history
modified:   src/ZPublisher/Converters.py
modified:   src/ZPublisher/tests/test_Converters.py
  • Loading branch information
jugmac00 committed Apr 16, 2019
1 parent 4916ee9 commit 4280815
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ZPublisher/Converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def field2int(v):
return int(v)
except ValueError:
raise ValueError(
"An integer was expected in the value %r" % escape(v, True)
"An integer was expected in the value %r" % escape(
v, quote=True
)
)
raise ValueError('Empty entry when <strong>integer</strong> expected')

Expand Down
22 changes: 22 additions & 0 deletions src/ZPublisher/tests/test_Converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ def test_field2boolean_with_emtpy_list(self):
expected = False
self.assertEqual(field2boolean(to_convert), expected)

def test_field2int_with_list_of_numbers(self):
from ZPublisher.Converters import field2int
to_convert = ["1", "2", "3"]
expected = [1, 2, 3]
self.assertEqual(field2int(to_convert), expected)

def test_field2int_with_regular_number(self):
from ZPublisher.Converters import field2int
to_convert = "1"
expected = 1
self.assertEqual(field2int(to_convert), expected)

def test_field2int_with_illegal_value(self):
from ZPublisher.Converters import field2int
to_convert = "<"
self.assertRaises(ValueError, field2int, to_convert)

def test_field2int_with_empty_value(self):
from ZPublisher.Converters import field2int
to_convert = ""
self.assertRaises(ValueError, field2int, to_convert)

def test_field2string_with_string(self):
from ZPublisher.Converters import field2string
to_convert = 'to_convert'
Expand Down

0 comments on commit 4280815

Please sign in to comment.