|
1 |
| -import py_validate.backend.shortcuts as shortcuts |
| 1 | +from py_validate.backend.shortcuts import NegateShortcut |
2 | 2 | from py_validate.tests import assert_raises
|
3 | 3 |
|
| 4 | +import py_validate.backend.shortcuts as shortcuts |
4 | 5 | import pytest
|
5 | 6 |
|
6 | 7 |
|
@@ -109,3 +110,37 @@ def test_invalid_odd_not_int(self, invalid):
|
109 | 110 | def test_invalid_even_not_even(self, invalid):
|
110 | 111 | msg = "Expected an odd integer"
|
111 | 112 | assert_raises(ValueError, msg, shortcuts.check_odd, invalid)
|
| 113 | + |
| 114 | + |
| 115 | +class TestCheckNegateShortcut(object): |
| 116 | + |
| 117 | + @pytest.mark.parametrize("invalid", [ |
| 118 | + "foo", "bar", "baz" |
| 119 | + ]) |
| 120 | + def test_invalid_shortcut_negate(self, invalid): |
| 121 | + msg = "Unknown shortcut" |
| 122 | + assert_raises(ValueError, msg, NegateShortcut, invalid) |
| 123 | + |
| 124 | + @pytest.mark.parametrize("valid,value", [ |
| 125 | + ("number", "foo"), |
| 126 | + ("integer", 1.0), |
| 127 | + ("even", 3), |
| 128 | + ("odd", 2) |
| 129 | + ]) |
| 130 | + def test_valid_negate(self, valid, value): |
| 131 | + |
| 132 | + # No Exception should be raised. |
| 133 | + negate_check = NegateShortcut(valid) |
| 134 | + negate_check(value) |
| 135 | + |
| 136 | + @pytest.mark.parametrize("valid,value", [ |
| 137 | + ("number", 1.5), |
| 138 | + ("integer", 1), |
| 139 | + ("even", 2), |
| 140 | + ("odd", 3) |
| 141 | + ]) |
| 142 | + def test_invalid_negate(self, valid, value): |
| 143 | + msg = "passed when it shouldn't have" |
| 144 | + negate_check = NegateShortcut(valid) |
| 145 | + |
| 146 | + assert_raises(shortcuts.NegateFailure, msg, negate_check, value) |
0 commit comments