|
11 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
| 14 | +import sys |
| 15 | + |
14 | 16 | from cassandra.marshal import bitlength |
15 | 17 | from cassandra.protocol import MAX_SUPPORTED_VERSION |
16 | 18 |
|
|
25 | 27 | from uuid import UUID |
26 | 28 |
|
27 | 29 | from cassandra.cqltypes import lookup_casstype, DecimalType, UTF8Type, DateType |
28 | | -from cassandra.util import OrderedMap, OrderedMapSerializedKey, sortedset, Time, Date |
| 30 | +from cassandra.util import OrderedMapSerializedKey, sortedset, Time, Date |
29 | 31 |
|
30 | 32 | marshalled_value_pairs = ( |
31 | 33 | # binary form, type, python native type |
@@ -143,8 +145,18 @@ def test_date(self): |
143 | 145 |
|
144 | 146 | def test_decimal(self): |
145 | 147 | # testing implicit numeric conversion |
146 | | - # int, float, tuple(sign, digits, exp) |
| 148 | + # int, tuple(sign, digits, exp), float |
| 149 | + converted_types = (10001, (0, (1, 0, 0, 0, 0, 1), -3), 100.1) |
| 150 | + |
| 151 | + if sys.version_info < (2, 7): |
| 152 | + # Decimal in Python 2.6 does not accept floats for lossless initialization |
| 153 | + # Just verifying expected exception here |
| 154 | + f = converted_types[-1] |
| 155 | + self.assertIsInstance(f, float) |
| 156 | + self.assertRaises(TypeError, DecimalType.to_binary, f, MAX_SUPPORTED_VERSION) |
| 157 | + converted_types = converted_types[:-1] |
| 158 | + |
147 | 159 | for proto_ver in range(1, MAX_SUPPORTED_VERSION + 1): |
148 | | - for n in (10001, 100.1, (0, (1, 0, 0, 0, 0, 1), -3)): |
| 160 | + for n in converted_types: |
149 | 161 | expected = Decimal(n) |
150 | 162 | self.assertEqual(DecimalType.from_binary(DecimalType.to_binary(n, proto_ver), proto_ver), expected) |
0 commit comments