diff options
| author | mike bayer <mike_mp@zzzcomputing.com> | 2022-06-16 02:30:04 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2022-06-16 02:30:04 +0000 |
| commit | efd4e6dd8a73b956c860d796606f8e6ad652c292 (patch) | |
| tree | fc4e387f37e421d54068310eab5a01facb5f91c8 /test | |
| parent | 964c26feecc7607d6d3a66240c3f33f4ae9215d4 (diff) | |
| parent | 46c0fa56e904f6a00e56343302c4cb39955fa038 (diff) | |
| download | sqlalchemy-efd4e6dd8a73b956c860d796606f8e6ad652c292.tar.gz | |
Merge "implement literal stringification for arrays" into main
Diffstat (limited to 'test')
| -rw-r--r-- | test/dialect/postgresql/test_types.py | 20 | ||||
| -rw-r--r-- | test/requirements.py | 12 | ||||
| -rw-r--r-- | test/sql/test_types.py | 41 |
3 files changed, 62 insertions, 11 deletions
diff --git a/test/dialect/postgresql/test_types.py b/test/dialect/postgresql/test_types.py index 266263d5f..fd4b91db1 100644 --- a/test/dialect/postgresql/test_types.py +++ b/test/dialect/postgresql/test_types.py @@ -19,6 +19,7 @@ from sqlalchemy import Float from sqlalchemy import func from sqlalchemy import inspect from sqlalchemy import Integer +from sqlalchemy import literal from sqlalchemy import MetaData from sqlalchemy import null from sqlalchemy import Numeric @@ -52,6 +53,7 @@ from sqlalchemy.orm import Session from sqlalchemy.sql import bindparam from sqlalchemy.sql import operators from sqlalchemy.sql import sqltypes +from sqlalchemy.testing import expect_raises_message from sqlalchemy.testing import fixtures from sqlalchemy.testing.assertions import assert_raises from sqlalchemy.testing.assertions import assert_raises_message @@ -64,6 +66,7 @@ from sqlalchemy.testing.assertsql import RegexSQL from sqlalchemy.testing.schema import pep435_enum from sqlalchemy.testing.suite import test_types as suite from sqlalchemy.testing.util import round_decimal +from sqlalchemy.types import UserDefinedType class FloatCoercionTest(fixtures.TablesTest, AssertsExecutionResults): @@ -1230,6 +1233,23 @@ class ArrayTest(AssertsCompiledSQL, fixtures.TestBase): render_postcompile=True, ) + def test_array_literal_render_no_inner_render(self): + class MyType(UserDefinedType): + cache_ok = True + + def get_col_spec(self, **kw): + return "MYTYPE" + + with expect_raises_message( + NotImplementedError, + r"Don't know how to literal-quote value \[1, 2, 3\]", + ): + self.assert_compile( + select(literal([1, 2, 3], ARRAY(MyType()))), + "nothing", + literal_binds=True, + ) + def test_array_in_str_psycopg2_cast(self): expr = column("x", postgresql.ARRAY(String(15))).in_( [["one", "two"], ["three", "four"]] diff --git a/test/requirements.py b/test/requirements.py index 2d0876158..bea861a83 100644 --- a/test/requirements.py +++ b/test/requirements.py @@ -969,12 +969,7 @@ class DefaultRequirements(SuiteRequirements): @property def array_type(self): - return only_on( - [ - lambda config: against(config, "postgresql") - and not against(config, "+pg8000") - ] - ) + return only_on([lambda config: against(config, "postgresql")]) @property def json_type(self): @@ -1356,10 +1351,7 @@ class DefaultRequirements(SuiteRequirements): @property def postgresql_jsonb(self): - return only_on("postgresql >= 9.4") + skip_if( - lambda config: config.db.dialect.driver == "pg8000" - and config.db.dialect._dbapi_version <= (1, 10, 1) - ) + return only_on("postgresql >= 9.4") @property def native_hstore(self): diff --git a/test/sql/test_types.py b/test/sql/test_types.py index ef3915726..04aa4e000 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -93,6 +93,7 @@ from sqlalchemy.testing.schema import Column from sqlalchemy.testing.schema import pep435_enum from sqlalchemy.testing.schema import Table from sqlalchemy.testing.util import picklers +from sqlalchemy.types import UserDefinedType def _all_dialect_modules(): @@ -2904,7 +2905,7 @@ class JSONTest(fixtures.TestBase): eq_(bindproc(expr.right.value), "'five'") -class ArrayTest(fixtures.TestBase): +class ArrayTest(AssertsCompiledSQL, fixtures.TestBase): def _myarray_fixture(self): class MyArray(ARRAY): pass @@ -2957,6 +2958,44 @@ class ArrayTest(fixtures.TestBase): assert isinstance(arrtable.c.intarr[1:3].type, MyArray) assert isinstance(arrtable.c.strarr[1:3].type, MyArray) + def test_array_literal_simple(self): + self.assert_compile( + select(literal([1, 2, 3], ARRAY(Integer))), + "SELECT [1, 2, 3] AS anon_1", + literal_binds=True, + dialect="default", + ) + + def test_array_literal_complex(self): + self.assert_compile( + select( + literal( + [["one", "two"], ["thr'ee", "réve🐍 illé"]], + ARRAY(String, dimensions=2), + ) + ), + "SELECT [['one', 'two'], ['thr''ee', 'réve🐍 illé']] AS anon_1", + literal_binds=True, + dialect="default", + ) + + def test_array_literal_render_no_inner_render(self): + class MyType(UserDefinedType): + cache_ok = True + + def get_col_spec(self, **kw): + return "MYTYPE" + + with expect_raises_message( + NotImplementedError, + r"Don't know how to literal-quote value \[1, 2, 3\]", + ): + self.assert_compile( + select(literal([1, 2, 3], ARRAY(MyType()))), + "nothing", + literal_binds=True, + ) + MyCustomType = MyTypeDec = None |
