bschoening commented on PR #1290:
URL:
https://github.com/apache/cassandra-python-driver/pull/1290#issuecomment-4348072999
Gemini suggest the following:
@greaterthancass20
def test_export_keyspace_schema_udts(self):
"""
Test udt exports (Modernized for Python 3.10+)
"""
# We still need this: UDTs require Native Protocol v3+
if PROTOCOL_VERSION < 3:
raise unittest.SkipTest(
"Protocol 3.0+ is required for UDT change events, currently
testing against %r"
% (PROTOCOL_VERSION,))
cluster = TestCluster()
session = cluster.connect()
# 1. Setup Schema
session.execute("""
CREATE KEYSPACE export_udts
WITH replication = {'class': 'SimpleStrategy', 'replication_factor':
'1'}
AND durable_writes = true;
""")
session.execute("CREATE TYPE export_udts.street (street_number int,
street_name text)")
session.execute("CREATE TYPE export_udts.zip (zipcode int, zip_plus_4
int)")
session.execute("""
CREATE TYPE export_udts.address (
street_address frozen<street>,
zip_code frozen<zip>)
""")
session.execute("""
CREATE TABLE export_udts.users (
user text PRIMARY KEY,
addresses map<text, frozen<address>>)
""")
# 2. Re-trigger a metadata refresh to ensure the driver has captured the
schema
cluster.metadata.refresh_keyspace_metadata('export_udts')
keyspace_meta = cluster.metadata.keyspaces['export_udts']
export_string = keyspace_meta.export_as_string()
# 3. Modern Assertions
# In 3.10+, dict order is stable. We check for core components.
expected_parts = [
"CREATE KEYSPACE export_udts",
"'class': 'SimpleStrategy'",
"'replication_factor': '1'",
"CREATE TYPE export_udts.street",
"CREATE TYPE export_udts.zip",
"CREATE TYPE export_udts.address",
"CREATE TABLE export_udts.users"
]
for part in expected_parts:
self.assertIn(part, export_string)
# 4. Verify UDT Nesting Order (Address must come after Street/Zip)
street_idx = export_string.find("CREATE TYPE export_udts.street")
zip_idx = export_string.find("CREATE TYPE export_udts.zip")
address_idx = export_string.find("CREATE TYPE export_udts.address")
self.assertTrue(street_idx < address_idx, "Street UDT must be defined
before Address UDT")
self.assertTrue(zip_idx < address_idx, "Zip UDT must be defined before
Address UDT")
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]