Skip to content

Commit

Permalink
Update test_get_multi_columns
Browse files Browse the repository at this point in the history
  • Loading branch information
gordthompson committed Sep 9, 2024
1 parent ef4ff2d commit 3751042
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 114 deletions.
2 changes: 1 addition & 1 deletion sqlalchemy_cockroachdb/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def __init__(self):

class CockroachDBDialect(PGDialect):
name = "cockroachdb"
supports_comments = False
supports_comments = True
supports_empty_insert = True
supports_multivalues_insert = True
supports_sequences = False
Expand Down
243 changes: 130 additions & 113 deletions test/test_suite_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@
from sqlalchemy.testing.suite import (
BizarroCharacterFKResolutionTest as _BizarroCharacterFKResolutionTest,
)
from sqlalchemy.testing.suite import ComponentReflectionTest as _ComponentReflectionTest
from sqlalchemy.testing.suite import (
ComponentReflectionTest as _ComponentReflectionTest,
)
from sqlalchemy.testing.suite import HasIndexTest as _HasIndexTest
from sqlalchemy.testing.suite import HasTableTest as _HasTableTest
from sqlalchemy.testing.suite import InsertBehaviorTest as _InsertBehaviorTest
from sqlalchemy.testing.suite import IsolationLevelTest as _IsolationLevelTest
from sqlalchemy.testing.suite import LongNameBlowoutTest as _LongNameBlowoutTest
from sqlalchemy.testing.suite import (
LongNameBlowoutTest as _LongNameBlowoutTest,
)
from sqlalchemy.testing.suite import NumericTest as _NumericTest
from sqlalchemy.testing.suite import QuotedNameArgumentTest as _QuotedNameArgumentTest
from sqlalchemy.testing.suite import (
QuotedNameArgumentTest as _QuotedNameArgumentTest,
)
from sqlalchemy.testing.suite import TrueDivTest as _TrueDivTest
from sqlalchemy.testing.suite import UnicodeSchemaTest as _UnicodeSchemaTest

Expand All @@ -27,17 +33,13 @@ class BizarroCharacterFKResolutionTest(_BizarroCharacterFKResolutionTest):
argnames="tablename",
)
def test_fk_ref(self, connection, metadata, use_composite, tablename, columnname):
if not (
config.db.dialect.driver == "asyncpg" and not config.db.dialect._is_v231plus
):
if not (config.db.dialect.driver == "asyncpg" and not config.db.dialect._is_v231plus):
super().test_fk_ref(connection, metadata, use_composite, tablename, columnname)


class ComponentReflectionTest(_ComponentReflectionTest):
def test_get_indexes(self, connection):
if not (
config.db.dialect.driver == "asyncpg" and not config.db.dialect._is_v231plus
):
if not (config.db.dialect.driver == "asyncpg" and not config.db.dialect._is_v231plus):
super().test_get_indexes(connection, None, None)

@skip("cockroachdb")
Expand All @@ -49,176 +51,201 @@ def test_get_multi_columns(self):
insp = inspect(config.db)
actual = insp.get_multi_columns()
expected = {
(None, "comment_test"): [
(None, "users"): [
{
"autoincrement": True,
"name": "user_id",
"type": INTEGER(),
"nullable": False,
"default": "unique_rowid()",
"autoincrement": True,
"is_hidden": False,
"name": "id",
"nullable": False,
"type": INTEGER(),
"comment": None,
},
{
"autoincrement": False,
"name": "test1",
"type": VARCHAR(length=5),
"nullable": False,
"default": None,
"autoincrement": False,
"is_hidden": False,
"name": "data",
"nullable": True,
"type": VARCHAR(length=20),
"comment": None,
},
{
"autoincrement": False,
"name": "test2",
"type": FLOAT(),
"nullable": False,
"default": None,
"autoincrement": False,
"is_hidden": False,
"name": "d2",
"nullable": True,
"type": VARCHAR(length=20),
"comment": None,
},
{
"autoincrement": False,
"name": "parent_user_id",
"type": INTEGER(),
"nullable": True,
"default": None,
"autoincrement": False,
"is_hidden": False,
"name": "d3",
"nullable": True,
"type": VARCHAR(length=42),
"comment": None,
},
],
(None, "dingalings"): [
(None, "comment_test"): [
{
"autoincrement": True,
"name": "id",
"type": INTEGER(),
"nullable": False,
"default": "unique_rowid()",
"autoincrement": True,
"is_hidden": False,
"name": "dingaling_id",
"nullable": False,
"type": INTEGER(),
"comment": "id comment",
},
{
"autoincrement": False,
"default": None,
"is_hidden": False,
"name": "address_id",
"name": "data",
"type": VARCHAR(length=20),
"nullable": True,
"type": INTEGER(),
},
{
"autoincrement": False,
"default": None,
"is_hidden": False,
"name": "id_user",
"nullable": True,
"type": INTEGER(),
},
{
"autoincrement": False,
"default": None,
"is_hidden": False,
"name": "data",
"nullable": True,
"type": VARCHAR(length=30),
},
],
(None, "email_addresses"): [
{
"autoincrement": True,
"default": "unique_rowid()",
"is_hidden": False,
"name": "address_id",
"nullable": False,
"type": INTEGER(),
"comment": "data % comment",
},
{
"autoincrement": False,
"name": "d2",
"type": VARCHAR(length=20),
"nullable": True,
"default": None,
"autoincrement": False,
"is_hidden": False,
"name": "remote_user_id",
"nullable": True,
"type": INTEGER(),
"comment": "Comment types type speedily ' \" \\ '' Fun!",
},
{
"autoincrement": False,
"name": "d3",
"type": VARCHAR(length=42),
"nullable": True,
"default": None,
"autoincrement": False,
"is_hidden": False,
"name": "email_address",
"nullable": True,
"type": VARCHAR(length=20),
"comment": "Comment\nwith\rescapes",
},
],
(None, "no_constraints"): [
{
"autoincrement": False,
"default": None,
"is_hidden": False,
"name": "data",
"nullable": True,
"type": VARCHAR(length=20),
"nullable": True,
"default": None,
"autoincrement": False,
"is_hidden": False,
"comment": None,
}
],
(None, "noncol_idx_test_nopk"): [
{
"autoincrement": False,
"default": None,
"is_hidden": False,
"name": "q",
"nullable": True,
"type": VARCHAR(length=5),
"nullable": True,
"default": None,
"autoincrement": False,
"is_hidden": False,
"comment": None,
}
],
(None, "noncol_idx_test_pk"): [
{
"autoincrement": True,
"default": "unique_rowid()",
"is_hidden": False,
"name": "id",
"nullable": False,
"type": INTEGER(),
"nullable": False,
"default": "unique_rowid()",
"autoincrement": True,
"is_hidden": False,
"comment": None,
},
{
"autoincrement": False,
"default": None,
"is_hidden": False,
"name": "q",
"nullable": True,
"type": VARCHAR(length=5),
"nullable": True,
"default": None,
"autoincrement": False,
"is_hidden": False,
"comment": None,
},
],
(None, "users"): [
(None, "email_addresses"): [
{
"autoincrement": True,
"name": "address_id",
"type": INTEGER(),
"nullable": False,
"default": "unique_rowid()",
"autoincrement": True,
"is_hidden": False,
"name": "user_id",
"nullable": False,
"type": INTEGER(),
"comment": None,
},
{
"autoincrement": False,
"name": "remote_user_id",
"type": INTEGER(),
"nullable": True,
"default": None,
"autoincrement": False,
"is_hidden": False,
"name": "test1",
"nullable": False,
"type": VARCHAR(length=5),
"comment": None,
},
{
"autoincrement": False,
"name": "email_address",
"type": VARCHAR(length=20),
"nullable": True,
"default": None,
"autoincrement": False,
"is_hidden": False,
"name": "test2",
"comment": None,
},
],
(None, "dingalings"): [
{
"name": "dingaling_id",
"type": INTEGER(),
"nullable": False,
"type": FLOAT(),
"default": "unique_rowid()",
"autoincrement": True,
"is_hidden": False,
"comment": None,
},
{
"name": "address_id",
"type": INTEGER(),
"nullable": True,
"default": None,
"autoincrement": False,
"is_hidden": False,
"comment": None,
},
{
"name": "id_user",
"type": INTEGER(),
"nullable": True,
"default": None,
"autoincrement": False,
"is_hidden": False,
"name": "parent_user_id",
"comment": None,
},
{
"name": "data",
"type": VARCHAR(length=30),
"nullable": True,
"type": INTEGER(),
"default": None,
"autoincrement": False,
"is_hidden": False,
"comment": None,
},
],
}
eq_(len(actual), len(expected))
eq_(actual.keys(), expected.keys())
eq_(len(actual[(None, "comment_test")]), len(expected[(None, "comment_test")]))
eq_(
len(actual[(None, "comment_test")]),
len(expected[(None, "comment_test")]),
)
act = [x for x in actual[(None, "comment_test")] if x["name"] == "data"][0]
exp = [x for x in expected[(None, "comment_test")] if x["name"] == "data"][0]
eq_(act["comment"], exp["comment"])

@skip("cockroachdb")
def test_get_multi_indexes(self):
Expand All @@ -244,13 +271,9 @@ def test_get_view_names(self):
pass

@testing.combinations(True, False, argnames="use_schema")
@testing.combinations(
(True, testing.requires.views), False, argnames="views"
)
@testing.combinations((True, testing.requires.views), False, argnames="views")
def test_metadata(self, connection, use_schema, views):
if not (
config.db.dialect.driver == "asyncpg" and not config.db.dialect._is_v231plus
):
if not (config.db.dialect.driver == "asyncpg" and not config.db.dialect._is_v231plus):
super().test_metadata(connection, use_schema, views, [])

@skip("cockroachdb")
Expand Down Expand Up @@ -310,9 +333,7 @@ class LongNameBlowoutTest(_LongNameBlowoutTest):
argnames="type_",
)
def test_long_convention_name(self, type_, metadata, connection):
if not (
config.db.dialect.driver == "asyncpg" and not config.db.dialect._is_v231plus
):
if not (config.db.dialect.driver == "asyncpg" and not config.db.dialect._is_v231plus):
super().test_long_convention_name(type_, metadata, connection, None)


Expand All @@ -326,9 +347,7 @@ def quote_fixtures(fn):
@quote_fixtures
def test_get_indexes(self, name):
# could not decorrelate subquery
if not (
config.db.dialect.driver == "asyncpg" and not config.db.dialect._is_v231plus
):
if not (config.db.dialect.driver == "asyncpg" and not config.db.dialect._is_v231plus):
super().test_get_indexes(name, None)


Expand Down Expand Up @@ -358,7 +377,5 @@ def test_floordiv_integer_bound(self):

class UnicodeSchemaTest(_UnicodeSchemaTest):
def test_reflect(self, connection):
if not (
config.db.dialect.driver == "asyncpg" and not config.db.dialect._is_v231plus
):
if not (config.db.dialect.driver == "asyncpg" and not config.db.dialect._is_v231plus):
super().test_reflect(connection)

0 comments on commit 3751042

Please sign in to comment.