Exemple #1
0
    def test_collection_null_support(self):
        """
        Test that null values in collection are decoded properly.

        @jira_ticket PYTHON-1123
        """
        int_list = ListType.apply_parameters([Int32Type])
        value = (
            int32_pack(2) +  # num items
            int32_pack(-1) +  # size of item1
            int32_pack(4) +  # size of item2
            int32_pack(42)  # item2
        )
        self.assertEqual([None, 42], int_list.deserialize(value, 3))

        set_list = SetType.apply_parameters([Int32Type])
        self.assertEqual({None, 42}, set(set_list.deserialize(value, 3)))

        value = (
            int32_pack(2) +  # num items
            int32_pack(4) +  # key size of item1
            int32_pack(42) +  # key item1
            int32_pack(-1) +  # value size of item1
            int32_pack(-1) +  # key size of item2
            int32_pack(4) +  # value size of item2
            int32_pack(42)  # value of item2
        )

        map_list = MapType.apply_parameters([Int32Type, Int32Type])
        self.assertEqual(
            [(42, None), (None, 42)],
            map_list.deserialize(value, 3)._items  # OrderedMapSerializedKey
        )
    def test_casstype_parameterized(self):
        self.assertEqual(LongType.cass_parameterized_type_with(()), 'LongType')
        self.assertEqual(LongType.cass_parameterized_type_with((), full=True), 'org.apache.cassandra.db.marshal.LongType')
        self.assertEqual(SetType.cass_parameterized_type_with([DecimalType], full=True), 'org.apache.cassandra.db.marshal.SetType(org.apache.cassandra.db.marshal.DecimalType)')

        self.assertEqual(LongType.cql_parameterized_type(), 'bigint')

        subtypes = (cassandra.cqltypes.UTF8Type, cassandra.cqltypes.UTF8Type)
        self.assertEqual('map<text, text>',
                         cassandra.cqltypes.MapType.apply_parameters(subtypes).cql_parameterized_type())
Exemple #3
0
    def test_casstype_parameterized(self):
        self.assertEqual(LongType.cass_parameterized_type_with(()), 'LongType')
        self.assertEqual(LongType.cass_parameterized_type_with((), full=True), 'org.apache.cassandra.db.marshal.LongType')
        self.assertEqual(SetType.cass_parameterized_type_with([DecimalType], full=True), 'org.apache.cassandra.db.marshal.SetType(org.apache.cassandra.db.marshal.DecimalType)')

        self.assertEqual(LongType.cql_parameterized_type(), 'bigint')

        subtypes = (cassandra.cqltypes.UTF8Type, cassandra.cqltypes.UTF8Type)
        self.assertEqual('map<text, text>',
                         cassandra.cqltypes.MapType.apply_parameters(subtypes).cql_parameterized_type())
Exemple #4
0
    def test_cassandratype(self):
        """
        Smoke test cass_parameterized_type_with
        """

        self.assertEqual(LongType.cass_parameterized_type_with(()), "LongType")
        self.assertEqual(
            LongType.cass_parameterized_type_with((), full=True), "org.apache.cassandra.db.marshal.LongType"
        )
        self.assertEqual(
            SetType.cass_parameterized_type_with([DecimalType], full=True),
            "org.apache.cassandra.db.marshal.SetType(org.apache.cassandra.db.marshal.DecimalType)",
        )

        self.assertEqual(LongType.cql_parameterized_type(), "bigint")
        self.assertEqual(
            cassandra.cqltypes.MapType.apply_parameters(
                cassandra.cqltypes.UTF8Type, cassandra.cqltypes.UTF8Type
            ).cql_parameterized_type(),
            "map<text, text>",
        )