Skip to content

Commit 5250e1b

Browse files
committed
Make test_sql.py other connectable tests parallelizable 2
1 parent 4147a77 commit 5250e1b

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

pandas/tests/io/test_sql.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,25 +1508,28 @@ def test_read_view_postgres(conn, request):
15081508

15091509
def test_read_view_sqlite(sqlite_buildin):
15101510
# GH 52969
1511-
create_table = """
1512-
CREATE TABLE groups (
1511+
table_uuid = table_uuid_gen("groups")
1512+
view_uuid = table_uuid_gen("group_view")
1513+
1514+
create_table = f"""
1515+
CREATE TABLE {table_uuid} (
15131516
group_id INTEGER,
15141517
name TEXT
15151518
);
15161519
"""
1517-
insert_into = """
1518-
INSERT INTO groups VALUES
1520+
insert_into = f"""
1521+
INSERT INTO {table_uuid} VALUES
15191522
(1, 'name');
15201523
"""
1521-
create_view = """
1522-
CREATE VIEW group_view
1524+
create_view = f"""
1525+
CREATE VIEW {view_uuid}
15231526
AS
1524-
SELECT * FROM groups;
1527+
SELECT * FROM {table_uuid};
15251528
"""
15261529
sqlite_buildin.execute(create_table)
15271530
sqlite_buildin.execute(insert_into)
15281531
sqlite_buildin.execute(create_view)
1529-
result = pd.read_sql("SELECT * FROM group_view", sqlite_buildin)
1532+
result = pd.read_sql(f"SELECT * FROM {view_uuid}", sqlite_buildin)
15301533
expected = DataFrame({"group_id": [1], "name": "name"})
15311534
tm.assert_frame_equal(result, expected)
15321535

@@ -3947,9 +3950,10 @@ def sqlite_builtin_detect_types():
39473950
def test_roundtripping_datetimes_detect_types(sqlite_builtin_detect_types):
39483951
# https://github.com/pandas-dev/pandas/issues/55554
39493952
conn = sqlite_builtin_detect_types
3953+
table_uuid = table_uuid_gen("test")
39503954
df = DataFrame({"t": [datetime(2020, 12, 31, 12)]}, dtype="datetime64[ns]")
3951-
df.to_sql("test", conn, if_exists="replace", index=False)
3952-
result = pd.read_sql("select * from test", conn).iloc[0, 0]
3955+
df.to_sql(table_uuid, conn, if_exists="replace", index=False)
3956+
result = pd.read_sql(f"select * from {table_uuid}", conn).iloc[0, 0]
39533957
assert result == Timestamp("2020-12-31 12:00:00.000000")
39543958

39553959

@@ -4238,8 +4242,10 @@ def test_xsqlite_basic(sqlite_buildin):
42384242
columns=Index(list("ABCD")),
42394243
index=date_range("2000-01-01", periods=10, freq="B"),
42404244
)
4241-
assert sql.to_sql(frame, name="test_table", con=sqlite_buildin, index=False) == 10
4242-
result = sql.read_sql("select * from test_table", sqlite_buildin)
4245+
table_uuid = table_uuid_gen("test_table")
4246+
table_uuid2 = table_uuid_gen("test_table2")
4247+
assert sql.to_sql(frame, name=table_uuid, con=sqlite_buildin, index=False) == 10
4248+
result = sql.read_sql(f"select * from {table_uuid}", sqlite_buildin)
42434249

42444250
# HACK! Change this once indexes are handled properly.
42454251
result.index = frame.index
@@ -4251,8 +4257,8 @@ def test_xsqlite_basic(sqlite_buildin):
42514257
frame2 = frame.copy()
42524258
new_idx = Index(np.arange(len(frame2)), dtype=np.int64) + 10
42534259
frame2["Idx"] = new_idx.copy()
4254-
assert sql.to_sql(frame2, name="test_table2", con=sqlite_buildin, index=False) == 10
4255-
result = sql.read_sql("select * from test_table2", sqlite_buildin, index_col="Idx")
4260+
assert sql.to_sql(frame2, name=table_uuid2, con=sqlite_buildin, index=False) == 10
4261+
result = sql.read_sql(f"select * from {table_uuid2}", sqlite_buildin, index_col="Idx")
42564262
expected = frame.copy()
42574263
expected.index = new_idx
42584264
expected.index.name = "Idx"

0 commit comments

Comments
 (0)