Skip to content

Commit 0799773

Browse files
authored
TST: refactor iris_view table in SQL test (#43024)
1 parent 7db129e commit 0799773

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

pandas/tests/io/test_sql.py

+18-11
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,6 @@
186186
"mysql": "SELECT * FROM iris WHERE `Name` LIKE '%'",
187187
"postgresql": "SELECT * FROM iris WHERE \"Name\" LIKE '%'",
188188
},
189-
"create_view": {
190-
"sqlite": """
191-
CREATE VIEW iris_view AS
192-
SELECT * FROM iris
193-
"""
194-
},
195189
}
196190

197191

@@ -256,6 +250,23 @@ def create_and_load_iris(conn, iris_file: Path, dialect: str):
256250
conn.execute(stmt)
257251

258252

253+
def create_and_load_iris_view(conn):
254+
stmt = "CREATE VIEW iris_view AS SELECT * FROM iris"
255+
if isinstance(conn, sqlite3.Connection):
256+
cur = conn.cursor()
257+
cur.execute(stmt)
258+
else:
259+
from sqlalchemy import text
260+
from sqlalchemy.engine import Engine
261+
262+
stmt = text(stmt)
263+
if isinstance(conn, Engine):
264+
with conn.connect() as conn:
265+
conn.execute(stmt)
266+
else:
267+
conn.execute(stmt)
268+
269+
259270
@pytest.fixture
260271
def iris_path(datapath):
261272
iris_path = datapath("io", "data", "csv", "iris.csv")
@@ -391,10 +402,6 @@ def load_iris_data(self, iris_path):
391402
else:
392403
create_and_load_iris(self.conn, iris_path, self.flavor)
393404

394-
def _load_iris_view(self):
395-
self.drop_table("iris_view")
396-
self._get_exec().execute(SQL_STRINGS["create_view"][self.flavor])
397-
398405
def _check_iris_loaded_frame(self, iris_frame):
399406
pytype = iris_frame.dtypes[0].type
400407
row = iris_frame.iloc[0]
@@ -697,7 +704,7 @@ def setup_method(self, load_iris_data):
697704
self.load_test_data_and_sql()
698705

699706
def load_test_data_and_sql(self):
700-
self._load_iris_view()
707+
create_and_load_iris_view(self.conn)
701708
self._load_raw_sql()
702709

703710
def test_read_sql_iris(self):

0 commit comments

Comments
 (0)