Skip to content

TST: refactor iris_view table creation in SQL test #43024

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 1 commit into from
Aug 13, 2021
Merged
Changes from all commits
Commits
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
29 changes: 18 additions & 11 deletions pandas/tests/io/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,6 @@
"mysql": "SELECT * FROM iris WHERE `Name` LIKE '%'",
"postgresql": "SELECT * FROM iris WHERE \"Name\" LIKE '%'",
},
"create_view": {
"sqlite": """
CREATE VIEW iris_view AS
SELECT * FROM iris
"""
},
}


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


def create_and_load_iris_view(conn):
stmt = "CREATE VIEW iris_view AS SELECT * FROM iris"
if isinstance(conn, sqlite3.Connection):
cur = conn.cursor()
cur.execute(stmt)
else:
from sqlalchemy import text
from sqlalchemy.engine import Engine

stmt = text(stmt)
if isinstance(conn, Engine):
with conn.connect() as conn:
conn.execute(stmt)
else:
conn.execute(stmt)


@pytest.fixture
def iris_path(datapath):
iris_path = datapath("io", "data", "csv", "iris.csv")
Expand Down Expand Up @@ -391,10 +402,6 @@ def load_iris_data(self, iris_path):
else:
create_and_load_iris(self.conn, iris_path, self.flavor)

def _load_iris_view(self):
self.drop_table("iris_view")
self._get_exec().execute(SQL_STRINGS["create_view"][self.flavor])

def _check_iris_loaded_frame(self, iris_frame):
pytype = iris_frame.dtypes[0].type
row = iris_frame.iloc[0]
Expand Down Expand Up @@ -697,7 +704,7 @@ def setup_method(self, load_iris_data):
self.load_test_data_and_sql()

def load_test_data_and_sql(self):
self._load_iris_view()
create_and_load_iris_view(self.conn)
self._load_raw_sql()

def test_read_sql_iris(self):
Expand Down