Skip to content

Instantly share code, notes, and snippets.

@benhowes
Created August 2, 2018 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benhowes/a589e0b3b0a30a3e047a4b125d5a48cc to your computer and use it in GitHub Desktop.
Save benhowes/a589e0b3b0a30a3e047a4b125d5a48cc to your computer and use it in GitHub Desktop.
# Unittest style, written for easy port
def test_boolean_validator(self):
variations = (
('False', 'err'),
('True', 'err'),
(0, 'err'),
(1, 'err'),
(True, True),
(False, False),
({}, 'err'),
((,), 'err')
)
for (claim_value, expected) in variations:
if expected == "err":
with self.expectRaises(TypeError):
boolean_parser(claim_value)
else:
self.assertEqual(boolean_parser(claim_value), expected)
# Pytest style
@pytest.mark.parameterize(('claim_value,expected'), (
('False', 'err'),
('True', 'err'),
(0, 'err'),
(1, 'err'),
(True, True),
(False, False),
({}, 'err'),
((,), 'err')
))
def test_boolean_validator(claim_value, expected):
if expected == "err":
with pytest.raises(TypeError):
boolean_parser(claim_value)
else:
assert boolean_parser(claim_value) == expected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment