23
23
from sqlalchemy import Column , DateTime , Integer , String
24
24
25
25
import google .api_core .exceptions
26
+ from google .cloud .bigquery import SchemaField
26
27
27
28
alembic = pytest .importorskip ("alembic" )
28
29
@@ -43,10 +44,7 @@ def get_table(table_name, data="table"):
43
44
if data == "table" :
44
45
return table
45
46
elif data == "schema" :
46
- return [
47
- repr (s ).replace (", (), None)" , ")" ).replace (", None)" , ")" )
48
- for s in table .schema
49
- ]
47
+ return table .schema
50
48
else :
51
49
raise ValueError (data )
52
50
except google .api_core .exceptions .NotFound :
@@ -78,9 +76,9 @@ def test_alembic_scenario(alembic_table):
78
76
Column ("description" , String (200 )),
79
77
)
80
78
assert alembic_table ("account" , "schema" ) == [
81
- " SchemaField('id', ' INTEGER', ' REQUIRED', None, (), ())" ,
82
- " SchemaField(' name', ' STRING(50)', ' REQUIRED', ' The name', (), ())" ,
83
- " SchemaField(' description', ' STRING(200)', 'NULLABLE', None, (), ())" ,
79
+ SchemaField ("id" , " INTEGER" , " REQUIRED" ) ,
80
+ SchemaField (" name" , " STRING(50)" , " REQUIRED" , description = " The name" ) ,
81
+ SchemaField (" description" , " STRING(200)" ) ,
84
82
]
85
83
86
84
op .bulk_insert (
@@ -103,11 +101,10 @@ def test_alembic_scenario(alembic_table):
103
101
)
104
102
105
103
assert alembic_table ("account" , "schema" ) == [
106
- "SchemaField('id', 'INTEGER', 'REQUIRED', None, (), ())" ,
107
- "SchemaField('name', 'STRING(50)', 'REQUIRED', 'The name', (), ())" ,
108
- "SchemaField('description', 'STRING(200)', 'NULLABLE', None, (), ())" ,
109
- "SchemaField('last_transaction_date', 'DATETIME', 'NULLABLE', 'when updated'"
110
- ", (), ())" ,
104
+ SchemaField ("id" , "INTEGER" , "REQUIRED" ),
105
+ SchemaField ("name" , "STRING(50)" , "REQUIRED" , description = "The name" ),
106
+ SchemaField ("description" , "STRING(200)" ),
107
+ SchemaField ("last_transaction_date" , "DATETIME" , description = "when updated" ),
111
108
]
112
109
113
110
op .create_table (
@@ -123,8 +120,8 @@ def test_alembic_scenario(alembic_table):
123
120
124
121
op .drop_column ("account_w_comment" , "description" )
125
122
assert alembic_table ("account_w_comment" , "schema" ) == [
126
- " SchemaField('id', ' INTEGER', ' REQUIRED', None, (), ())" ,
127
- " SchemaField(' name', ' STRING(50)', ' REQUIRED', ' The name', (), ())" ,
123
+ SchemaField ("id" , " INTEGER" , " REQUIRED" ) ,
124
+ SchemaField (" name" , " STRING(50)" , " REQUIRED" , description = " The name" ) ,
128
125
]
129
126
130
127
op .drop_table ("account_w_comment" )
@@ -133,11 +130,10 @@ def test_alembic_scenario(alembic_table):
133
130
op .rename_table ("account" , "accounts" )
134
131
assert alembic_table ("account" ) is None
135
132
assert alembic_table ("accounts" , "schema" ) == [
136
- "SchemaField('id', 'INTEGER', 'REQUIRED', None, (), ())" ,
137
- "SchemaField('name', 'STRING(50)', 'REQUIRED', 'The name', (), ())" ,
138
- "SchemaField('description', 'STRING(200)', 'NULLABLE', None, (), ())" ,
139
- "SchemaField('last_transaction_date', 'DATETIME', 'NULLABLE', 'when updated'"
140
- ", (), ())" ,
133
+ SchemaField ("id" , "INTEGER" , "REQUIRED" ),
134
+ SchemaField ("name" , "STRING(50)" , "REQUIRED" , description = "The name" ),
135
+ SchemaField ("description" , "STRING(200)" ),
136
+ SchemaField ("last_transaction_date" , "DATETIME" , description = "when updated" ),
141
137
]
142
138
op .drop_table ("accounts" )
143
139
assert alembic_table ("accounts" ) is None
@@ -157,9 +153,9 @@ def test_alembic_scenario(alembic_table):
157
153
# nullable:
158
154
op .alter_column ("transactions" , "amount" , True )
159
155
assert alembic_table ("transactions" , "schema" ) == [
160
- " SchemaField(' account', ' INTEGER', ' REQUIRED', None, (), ())" ,
161
- " SchemaField(' transaction_time', ' DATETIME', ' REQUIRED', None, (), ())" ,
162
- " SchemaField(' amount', ' NUMERIC(11, 2)', 'NULLABLE', None, (), ())" ,
156
+ SchemaField (" account" , " INTEGER" , " REQUIRED" ) ,
157
+ SchemaField (" transaction_time" , " DATETIME" , " REQUIRED" ) ,
158
+ SchemaField (" amount" , " NUMERIC(11, 2)" ) ,
163
159
]
164
160
165
161
op .create_table_comment ("transactions" , "Transaction log" )
0 commit comments