forked from piccolo-orm/piccolo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_smallint.py
More file actions
43 lines (31 loc) · 1.07 KB
/
test_smallint.py
File metadata and controls
43 lines (31 loc) · 1.07 KB
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
import os
from unittest import TestCase
from piccolo.table import Table
from piccolo.columns.column_types import SmallInt
from ..base import postgres_only
class MyTable(Table):
value = SmallInt()
@postgres_only
class TestSmallIntPostgres(TestCase):
"""
Make sure a SmallInt column in Postgres can only store small numbers.
"""
def setUp(self):
MyTable.create_table().run_sync()
def tearDown(self):
MyTable.alter().drop_table().run_sync()
def _test_length(self):
# Can store 2 bytes, but split between positive and negative values.
max_value = int(2 ** 16 / 2) - 1
min_value = max_value * -1
print("Testing max value")
row = MyTable(value=max_value)
row.save().run_sync()
print("Testing min value")
row.value = min_value
row.save().run_sync()
if "TRAVIS" not in os.environ:
# This stalls out on Travis - not sure why.
with self.assertRaises(Exception):
row.value = max_value + 100
row.save().run_sync()