|
17 | 17 | from .nuodb_base import NuoBase |
18 | 18 | from .mock_tzs import EscapingTimestamp |
19 | 19 | from .mock_tzs import Local |
| 20 | +from pynuodb.exception import DataError |
20 | 21 |
|
21 | 22 |
|
22 | 23 | class NuoDBBasicTest(NuoBase): |
@@ -144,42 +145,80 @@ def _test_decimal_fixture(self, value, precision, scale): |
144 | 145 | finally: |
145 | 146 | con.close() |
146 | 147 |
|
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 | + |
156 | 207 | def test_many_significant_digits(self): |
157 | 208 | self._test_decimal_fixture(decimal.Decimal("31943874831932418390.01"), 38, 12) |
158 | 209 | self._test_decimal_fixture(decimal.Decimal("-31943874831932418390.01"), 38, 12) |
159 | 210 |
|
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 | + |
169 | 212 | def test_numeric_no_decimal(self): |
170 | 213 | self._test_decimal_fixture(decimal.Decimal("1.000"), 5, 3) |
171 | 214 |
|
172 | 215 | # This test case produces at least three different defects, perhaps |
173 | 216 | # more under the covers. |
174 | 217 | def test_enotation_decimal_large(self): |
175 | 218 | numbers = ( |
176 | | - # Yields: AssertionError: '400000000.00' != '4E+8' |
177 | 219 | decimal.Decimal('4E+8'), |
178 | | - # Yields: DataError: 'CONVERSION_ERROR: conversion from type "bytes" to "numeric" is not implemented' |
179 | 220 | decimal.Decimal("5748E+15"), |
180 | | - # Yields: DataError: 'INVALID_UTF8: invalid UTF-8 code sequence' |
181 | 221 | decimal.Decimal('1.521E+15'), |
182 | | - # Yields: DataError: 'INVALID_UTF8: invalid UTF-8 code sequence' |
183 | 222 | decimal.Decimal('00000000000000.1E+12'), |
184 | 223 | ) |
185 | 224 | for number in numbers: |
|
0 commit comments