|
| 1 | +# !/usr/bin/env python |
1 | 2 | # Copyright (c) 2017 The sqlalchemy-bigquery Authors |
2 | 3 | # |
3 | 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy of |
|
17 | 18 | # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
18 | 19 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
19 | 20 |
|
20 | | -# -*- coding: utf-8 -*- |
21 | | - |
22 | 21 | import datetime |
23 | 22 | import decimal |
24 | 23 |
|
25 | 24 | from google.cloud.bigquery import TimePartitioning |
26 | 25 | import packaging.version |
27 | 26 | import pytest |
28 | | -from pytz import timezone |
29 | 27 | import sqlalchemy |
30 | | -from sqlalchemy import case, func, inspect, not_, types |
31 | | -from sqlalchemy.engine import create_engine |
| 28 | +from sqlalchemy import ( |
| 29 | + Column, |
| 30 | + MetaData, |
| 31 | + Table, |
| 32 | + case, |
| 33 | + create_engine, |
| 34 | + func, |
| 35 | + inspect, |
| 36 | + literal_column, |
| 37 | + not_, |
| 38 | + select, |
| 39 | + types, |
| 40 | +) |
32 | 41 | from sqlalchemy.exc import NoSuchTableError |
33 | 42 | from sqlalchemy.ext.declarative import declarative_base |
34 | 43 | from sqlalchemy.orm import sessionmaker |
35 | | -from sqlalchemy.schema import Column, MetaData, Table |
36 | | -from sqlalchemy.sql import expression, literal_column, select |
| 44 | +from sqlalchemy.sql import expression |
37 | 45 |
|
38 | 46 | import sqlalchemy_bigquery |
39 | 47 |
|
40 | | -ONE_ROW_CONTENTS_EXPANDED = [ |
| 48 | +SQLALCHEMY_VERSION = packaging.version.parse(sqlalchemy.__version__) |
| 49 | + |
| 50 | +ONE_ROW_CONTENTS = [ |
41 | 51 | 588, |
42 | | - datetime.datetime(2013, 10, 10, 11, 27, 16, tzinfo=timezone("UTC")), |
| 52 | + datetime.datetime(2013, 10, 10, 11, 27, 16, tzinfo=datetime.timezone.utc), |
43 | 53 | "W 52 St & 11 Ave", |
44 | 54 | 40.76727216, |
45 | 55 | decimal.Decimal("40.76727216"), |
|
48 | 58 | datetime.datetime(2013, 10, 10, 11, 27, 16), |
49 | 59 | datetime.time(11, 27, 16), |
50 | 60 | b"\xef", |
51 | | - {"age": 100, "name": "John Doe"}, |
52 | | - "John Doe", |
53 | | - 100, |
54 | | - {"record": {"age": 200, "name": "John Doe 2"}}, |
55 | | - {"age": 200, "name": "John Doe 2"}, |
56 | | - "John Doe 2", |
57 | | - 200, |
| 61 | + {"name": "John Doe", "age": 100}, |
| 62 | + {"record": {"name": "John Doe 2", "age": 200}}, |
58 | 63 | [1, 2, 3], |
59 | 64 | ] |
60 | | - |
61 | | -ONE_ROW_CONTENTS = [ |
| 65 | +ONE_ROW_CONTENTS_EXPANDED = [ |
62 | 66 | 588, |
63 | | - datetime.datetime(2013, 10, 10, 11, 27, 16, tzinfo=timezone("UTC")), |
| 67 | + datetime.datetime(2013, 10, 10, 11, 27, 16, tzinfo=datetime.timezone.utc), |
64 | 68 | "W 52 St & 11 Ave", |
65 | 69 | 40.76727216, |
66 | 70 | decimal.Decimal("40.76727216"), |
|
70 | 74 | datetime.time(11, 27, 16), |
71 | 75 | b"\xef", |
72 | 76 | {"name": "John Doe", "age": 100}, |
| 77 | + "John Doe", |
| 78 | + 100, |
73 | 79 | {"record": {"name": "John Doe 2", "age": 200}}, |
| 80 | + {"name": "John Doe 2", "age": 200}, |
| 81 | + "John Doe 2", |
| 82 | + 200, |
74 | 83 | [1, 2, 3], |
75 | 84 | ] |
76 | | - |
77 | 85 | ONE_ROW_CONTENTS_DML = [ |
78 | 86 | 588, |
79 | | - datetime.datetime(2013, 10, 10, 11, 27, 16, tzinfo=timezone("UTC")), |
| 87 | + datetime.datetime(2013, 10, 10, 11, 27, 16, tzinfo=datetime.timezone.utc), |
80 | 88 | "test", |
81 | 89 | 40.76727216, |
82 | 90 | decimal.Decimal("40.76727216"), |
83 | 91 | False, |
84 | 92 | datetime.date(2013, 10, 10), |
85 | 93 | datetime.datetime(2013, 10, 10, 11, 27, 16), |
86 | 94 | datetime.time(11, 27, 16), |
87 | | - "test_bytes", |
| 95 | + b"\xef", |
88 | 96 | ] |
89 | 97 |
|
90 | 98 | SAMPLE_COLUMNS = [ |
@@ -227,7 +235,6 @@ def test_engine_with_dataset(engine_using_test_dataset, bigquery_dataset): |
227 | 235 | with engine_using_test_dataset.connect() as conn: |
228 | 236 | rows = conn.execute(sqlalchemy.text("SELECT * FROM sample_one_row")).fetchall() |
229 | 237 | assert list(rows[0]) == ONE_ROW_CONTENTS |
230 | | - |
231 | 238 | table_one_row = Table( |
232 | 239 | "sample_one_row", MetaData(), autoload_with=engine_using_test_dataset |
233 | 240 | ) |
@@ -474,6 +481,10 @@ def test_custom_expression( |
474 | 481 | assert len(result) > 0 |
475 | 482 |
|
476 | 483 |
|
| 484 | +@pytest.mark.skipif( |
| 485 | + SQLALCHEMY_VERSION >= packaging.version.parse("2.0"), |
| 486 | + reason="Needs to be revisited as part of ensuring full SQL 2.0 compliance.", |
| 487 | +) |
477 | 488 | def test_compiled_query_literal_binds( |
478 | 489 | engine, engine_using_test_dataset, table, table_using_test_dataset, query |
479 | 490 | ): |
|
0 commit comments