-
Notifications
You must be signed in to change notification settings - Fork 42
/
08_02_first_test.py
45 lines (38 loc) · 1.36 KB
/
08_02_first_test.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import decimal
import unittest
class Column:
def __init__(self, name, kind, description=""):
self._name = name
self._kind = kind
self._description = description
@staticmethod
def validate(kind, data):
if kind == 'bigint':
if isinstance(data, int):
return True
return False
elif kind == 'varchar':
if isinstance(data, str):
return True
return False
elif kind == 'numeric':
try:
val = decimal.Decimal(data)
except:
return False
return True
class ColumnTest(unittest.TestCase):
def test_validate_bigint(self):
self.assertTrue(Column.validate('bigint', 100))
self.assertTrue(not Column.validate('bigint', 10.1))
self.assertTrue(not Column.validate('bigint', 'Texto'))
def test_validate_numeric(self):
self.assertTrue(Column.validate('numeric', 10.1))
self.assertTrue(Column.validate('numeric', 100))
self.assertTrue(not Column.validate('numeric', 'Texto'))
def test_validate_varchar(self):
self.assertTrue(Column.validate('varchar', 'Texto'))
self.assertTrue(not Column.validate('varchar', 100))
self.assertTrue(not Column.validate('varchar', 10.1))
if __name__ == "__main__":
unittest.main()