forked from piccolo-orm/piccolo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_numeric.py
More file actions
30 lines (20 loc) · 809 Bytes
/
test_numeric.py
File metadata and controls
30 lines (20 loc) · 809 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
28
29
30
from decimal import Decimal
from unittest import TestCase
from piccolo.table import Table
from piccolo.columns.column_types import Numeric
class MyTable(Table):
column_a = Numeric()
column_b = Numeric(digits=(3, 2))
class TestNumeric(TestCase):
def setUp(self):
MyTable.create_table().run_sync()
def tearDown(self):
MyTable.alter().drop_table().run_sync()
def test_creation(self):
row = MyTable(column_a=Decimal(1.23), column_b=Decimal(1.23))
row.save().run_sync()
_row = MyTable.objects().first().run_sync()
self.assertTrue(type(_row.column_a) == Decimal)
self.assertTrue(type(_row.column_b) == Decimal)
self.assertAlmostEqual(_row.column_a, Decimal(1.23))
self.assertEqual(_row.column_b, Decimal("1.23"))