Skip to content

Commit ea11522

Browse files
committed
Merge pull request #114 from tvincentNuoDB/master
Added tests for numeic edge cases
2 parents 7949c45 + 0330be3 commit ea11522

File tree

1 file changed

+65
-22
lines changed

1 file changed

+65
-22
lines changed

tests/nuodb_basic_test.py

Lines changed: 65 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,84 @@ 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+
158+
except DataError as err:
159+
if "CONVERSION_ERROR" not in str(err):
160+
self.fail()
161+
pass
162+
163+
finally:
164+
try:
165+
cursor.execute("DROP TABLE t IF EXISTS")
166+
finally:
167+
con.close()
168+
169+
#Test the edge cases of the small decimal type
170+
def test_small_decimal(self):
171+
numbers = (
172+
32767,
173+
-32768,
174+
0x7fff,
175+
-0x8000,
176+
)
177+
for number in numbers:
178+
self._test_decimal_fixture(number, 4, 0)
179+
#Test Invalid values
180+
self._test_faulty_decimal_fixture(32768, 4, 0)
181+
self._test_faulty_decimal_fixture(-32769, 4, 0)
182+
183+
#Test the edge cases of the integer type
184+
def test_integer(self):
185+
numbers = (
186+
2147483647,
187+
-2147483648,
188+
0x7FFFFFFF,
189+
-0x80000000,
190+
)
191+
for number in numbers:
192+
self._test_decimal_fixture(number, 9, 0)
193+
#Test Invalid values
194+
self._test_faulty_decimal_fixture(2147483648, 4, 0)
195+
self._test_faulty_decimal_fixture(-2147483649, 4, 0)
196+
197+
#Test the edge cases of the small decimal type
198+
def test_big_integer(self):
199+
numbers = (
200+
9223372036854775807,
201+
-9223372036854775808,
202+
0x7FFFFFFFFFFFFFFF,
203+
-0x8000000000000000,
204+
)
205+
for number in numbers:
206+
self._test_decimal_fixture(number, 20, 0)
207+
#Test Invalid values
208+
self._test_faulty_decimal_fixture(9223372036854775808, 4, 0)
209+
self._test_faulty_decimal_fixture(-9223372036854775809, 4, 0)
210+
156211
def test_many_significant_digits(self):
157212
self._test_decimal_fixture(decimal.Decimal("31943874831932418390.01"), 38, 12)
158213
self._test_decimal_fixture(decimal.Decimal("-31943874831932418390.01"), 38, 12)
159214

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-
#
215+
169216
def test_numeric_no_decimal(self):
170217
self._test_decimal_fixture(decimal.Decimal("1.000"), 5, 3)
171218

172219
# This test case produces at least three different defects, perhaps
173220
# more under the covers.
174221
def test_enotation_decimal_large(self):
175222
numbers = (
176-
# Yields: AssertionError: '400000000.00' != '4E+8'
177223
decimal.Decimal('4E+8'),
178-
# Yields: DataError: 'CONVERSION_ERROR: conversion from type "bytes" to "numeric" is not implemented'
179224
decimal.Decimal("5748E+15"),
180-
# Yields: DataError: 'INVALID_UTF8: invalid UTF-8 code sequence'
181225
decimal.Decimal('1.521E+15'),
182-
# Yields: DataError: 'INVALID_UTF8: invalid UTF-8 code sequence'
183226
decimal.Decimal('00000000000000.1E+12'),
184227
)
185228
for number in numbers:

0 commit comments

Comments
 (0)