Skip to content

Commit df809b3

Browse files
committed
Don't test Decimal(float) for python 2.6
1 parent 676d874 commit df809b3

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

tests/unit/test_marshalling.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import sys
15+
1416
from cassandra.marshal import bitlength
1517
from cassandra.protocol import MAX_SUPPORTED_VERSION
1618

@@ -25,7 +27,7 @@
2527
from uuid import UUID
2628

2729
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
2931

3032
marshalled_value_pairs = (
3133
# binary form, type, python native type
@@ -143,8 +145,18 @@ def test_date(self):
143145

144146
def test_decimal(self):
145147
# 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+
147159
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:
149161
expected = Decimal(n)
150162
self.assertEqual(DecimalType.from_binary(DecimalType.to_binary(n, proto_ver), proto_ver), expected)

0 commit comments

Comments
 (0)