Skip to content

Commit 75b989f

Browse files
committed
Added tests for numeic edge cases
1 parent cb00e43 commit 75b989f

File tree

1 file changed

+61
-22
lines changed

1 file changed

+61
-22
lines changed

tests/nuodb_basic_test.py

Lines changed: 61 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from .nuodb_base import NuoBase
1818
from .mock_tzs import EscapingTimestamp
1919
from .mock_tzs import Local
20+
from pynuodb.exception import DataError
2021

2122

2223
class NuoDBBasicTest(NuoBase):
@@ -144,42 +145,80 @@ def _test_decimal_fixture(self, value, precision, scale):
144145
finally:
145146
con.close()
146147

147-
# This test demonstrates the broken implementation of putScaledInt
148-
# which results in:
149-
#
150-
# DataError: 'INVALID_UTF8: invalid UTF-8 code sequence'
151-
#
152-
# Run separately via:
153-
#
154-
# py.test -k "test_many_significant_digits"
155-
#
148+
def _test_faulty_decimal_fixture(self, value, precision, scale):
149+
con = self._connect()
150+
cursor = con.cursor()
151+
cursor.execute("DROP TABLE CASCADE t IF EXISTS")
152+
try:
153+
cursor.execute("CREATE TABLE t (x NUMERIC(%s,%s))" % (precision, scale))
154+
DataError
155+
cursor.execute("INSERT INTO t (x) VALUES (?)", (value,))
156+
cursor.execute("SELECT * FROM t")
157+
except DataError:
158+
pass
159+
finally:
160+
try:
161+
cursor.execute("DROP TABLE t IF EXISTS")
162+
finally:
163+
con.close()
164+
165+
#Test the edge cases of the small decimal type
166+
def test_small_decimal(self):
167+
numbers = (
168+
32767,
169+
-32768,
170+
0x7fff,
171+
-0x8000,
172+
)
173+
for number in numbers:
174+
self._test_decimal_fixture(number, 4, 0)
175+
#Test Invalid values
176+
self._test_faulty_decimal_fixture(32768, 4, 0)
177+
self._test_faulty_decimal_fixture(-32769, 4, 0)
178+
179+
#Test the edge cases of the integer type
180+
def test_integer(self):
181+
numbers = (
182+
2147483647,
183+
-2147483648,
184+
0x7FFFFFFF,
185+
-0x80000000,
186+
)
187+
for number in numbers:
188+
self._test_decimal_fixture(number, 9, 0)
189+
#Test Invalid values
190+
self._test_faulty_decimal_fixture(2147483648, 4, 0)
191+
self._test_faulty_decimal_fixture(-2147483649, 4, 0)
192+
193+
#Test the edge cases of the small decimal type
194+
def test_big_integer(self):
195+
numbers = (
196+
9223372036854775807,
197+
-9223372036854775808,
198+
0x7FFFFFFFFFFFFFFF,
199+
-0x8000000000000000,
200+
)
201+
for number in numbers:
202+
self._test_decimal_fixture(number, 20, 0)
203+
#Test Invalid values
204+
self._test_faulty_decimal_fixture(9223372036854775808, 4, 0)
205+
self._test_faulty_decimal_fixture(-9223372036854775809, 4, 0)
206+
156207
def test_many_significant_digits(self):
157208
self._test_decimal_fixture(decimal.Decimal("31943874831932418390.01"), 38, 12)
158209
self._test_decimal_fixture(decimal.Decimal("-31943874831932418390.01"), 38, 12)
159210

160-
# This test demonstrates the broken implementation of getScaledInt
161-
# which results in:
162-
#
163-
# "1" instead of "1.000"
164-
#
165-
# Run separately via:
166-
#
167-
# py.test -k "test_numeric_no_decimal"
168-
#
211+
169212
def test_numeric_no_decimal(self):
170213
self._test_decimal_fixture(decimal.Decimal("1.000"), 5, 3)
171214

172215
# This test case produces at least three different defects, perhaps
173216
# more under the covers.
174217
def test_enotation_decimal_large(self):
175218
numbers = (
176-
# Yields: AssertionError: '400000000.00' != '4E+8'
177219
decimal.Decimal('4E+8'),
178-
# Yields: DataError: 'CONVERSION_ERROR: conversion from type "bytes" to "numeric" is not implemented'
179220
decimal.Decimal("5748E+15"),
180-
# Yields: DataError: 'INVALID_UTF8: invalid UTF-8 code sequence'
181221
decimal.Decimal('1.521E+15'),
182-
# Yields: DataError: 'INVALID_UTF8: invalid UTF-8 code sequence'
183222
decimal.Decimal('00000000000000.1E+12'),
184223
)
185224
for number in numbers:

0 commit comments

Comments
 (0)