Skip to content

test: fix string compliance tests #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5b1d1b1
test: fix string compliance tests
HemangChothani Mar 11, 2021
0730997
fix: resolve conflict
HemangChothani Mar 11, 2021
1dba2c0
test: add todo note to remove override method and resolve conflict
HemangChothani Mar 17, 2021
55eebbf
Merge branch 'main' of https://github.com/cloudspannerecosystem/pytho…
HemangChothani Mar 18, 2021
de0732d
test: nit
HemangChothani Mar 18, 2021
89ab8d5
Merge branch 'main' into fix_string_compliance_tests
larkee Mar 19, 2021
210f938
test: remove select statements and resolve conflict
HemangChothani Mar 22, 2021
9b52c20
test: nit
HemangChothani Mar 22, 2021
a08a154
fix: nit
HemangChothani Mar 23, 2021
694ec7b
fix: remove override methods and add default value
HemangChothani Mar 24, 2021
703f58c
fix: add default value MAX
HemangChothani Mar 25, 2021
84782a0
Merge branch 'main' of https://github.com/cloudspannerecosystem/pytho…
HemangChothani Apr 1, 2021
0c53c30
test: resolve conflict
HemangChothani Apr 5, 2021
175535c
Merge branch 'main' of https://github.com/cloudspannerecosystem/pytho…
HemangChothani Apr 7, 2021
611605c
Merge branch 'main' into fix_string_compliance_tests
AVaksman Apr 7, 2021
6025d3a
Merge branch 'main' into fix_string_compliance_tests
HemangChothani Apr 8, 2021
814b23a
Merge branch 'main' of https://github.com/cloudspannerecosystem/pytho…
HemangChothani Apr 9, 2021
ab715af
Merge branch 'fix_string_compliance_tests' of https://github.com/clou…
HemangChothani Apr 9, 2021
c4b9420
test: resolve conflict
HemangChothani Apr 15, 2021
81bb2eb
test: resolve conflict
HemangChothani Apr 23, 2021
01a85fe
test: fix nit
HemangChothani Apr 23, 2021
6b0a402
Merge branch 'main' of https://github.com/cloudspannerecosystem/pytho…
HemangChothani Apr 28, 2021
69cfd6b
test: add logic for additional escape ti fox the test
HemangChothani May 4, 2021
b58b718
Merge branch 'main' of https://github.com/cloudspannerecosystem/pytho…
HemangChothani May 4, 2021
bcf939c
test: add condition check for other data type
HemangChothani May 4, 2021
3229b2c
Merge branch 'main' of https://github.com/cloudspannerecosystem/pytho…
HemangChothani May 11, 2021
913710c
test: remove override tests
HemangChothani May 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion google/cloud/sqlalchemy_spanner/sqlalchemy_spanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,32 @@ def visit_empty_set_expr(self, type_):
_type_map_inv[type(type_[0])]
)

def render_literal_value(self, value, type_):
"""Render the value of a bind parameter as a quoted literal.

This is used for statement sections that do not accept bind parameters
on the target driver/database.

This should be implemented by subclasses using the quoting services
of the DBAPI.

Cloud spanner supports prefixed backslash to escape non-alphanumeric characters
in string. Override the method to add additional escape before using it to
generate a SQL statement.
"""
raw = ["\\", "'", '"', "\n", "\t", "\r"]
if type(value) == str and any(single in value for single in raw):
value = 'r"""{}"""'.format(value)
return value
else:
processor = type_._cached_literal_processor(self.dialect)
if processor:
return processor(value)
else:
raise NotImplementedError(
"Don't know how to literal-quote value %r" % value
)


class SpannerDDLCompiler(DDLCompiler):
"""Spanner DDL statements compiler."""
Expand Down Expand Up @@ -183,7 +209,7 @@ def visit_primary_key_constraint(self, constraint):
return None

def visit_unique_constraint(self, constraint):
"""Unique contraints in Spanner are defined with indexes:
"""Unique constraints in Spanner are defined with indexes:
https://cloud.google.com/spanner/docs/secondary-indexes#unique-indexes

The method throws an exception to notify user that in
Expand Down
9 changes: 8 additions & 1 deletion test/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
from sqlalchemy.testing.suite.test_select import OrderByLabelTest as _OrderByLabelTest
from sqlalchemy.testing.suite.test_types import BooleanTest as _BooleanTest
from sqlalchemy.testing.suite.test_types import IntegerTest as _IntegerTest
from sqlalchemy.testing.suite.test_types import StringTest as _StringTest

from sqlalchemy.testing.suite.test_types import _LiteralRoundTripFixture

from sqlalchemy.testing.suite.test_types import ( # noqa: F401, F403
Expand Down Expand Up @@ -535,7 +537,6 @@ def _literal_round_trip(self, type_, input_, output, filter_=None):
)
)
conn.execute(ins)
conn.execute("SELECT 1")

if self.supports_whereclause:
stmt = t.select().where(t.c.x == literal(value))
Expand Down Expand Up @@ -843,3 +844,9 @@ def test_nolength_binary(self):
@pytest.mark.skip("Spanner doesn't support quotes in table names.")
class QuotedNameArgumentTest(_QuotedNameArgumentTest):
pass


class StringTest(_StringTest):
@pytest.mark.skip("Spanner doesn't support non-ascii characters")
def test_literal_non_ascii(self):
pass