-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.py
More file actions
27 lines (21 loc) · 810 Bytes
/
test.py
File metadata and controls
27 lines (21 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import unittest
from main import assert_type, assert_maxlen, coerce_value
class TestValidators(unittest.TestCase):
def test_assert_type(self):
assert_type(1, int)
assert_type(1, (int, str, float))
assert_type("wow", str)
assert_type(1.23, float)
with self.assertRaises(TypeError):
assert_type("fail", int)
assert_type(123, str)
def test_assert_maxlen(self):
assert_maxlen("123456789", 10)
with self.assertRaises(ValueError):
assert_maxlen("123456789", 8)
def test_coerce_value(self):
self.assertIsInstance(coerce_value(0), float)
self.assertIsInstance(coerce_value(0.12), float)
self.assertIsInstance(coerce_value("hello"), str)
if __name__ == "__main__":
unittest.main()