Skip to content

Commit efdff03

Browse files
authored
CI/TST: Use tmp_path for excel test (#57516)
* Revert "CI: Run excel tests on single cpu for windows (#57486)" This reverts commit 9c02050. * Use tmp_path fixture * uuid4? * Don't remove, pytest cleans itself up eventually
1 parent 2b82b86 commit efdff03

File tree

8 files changed

+836
-864
lines changed

8 files changed

+836
-864
lines changed

Diff for: pandas/tests/io/excel/test_odf.py

-5
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@
33
import numpy as np
44
import pytest
55

6-
from pandas.compat import is_platform_windows
7-
86
import pandas as pd
97
import pandas._testing as tm
108

119
pytest.importorskip("odf")
1210

13-
if is_platform_windows():
14-
pytestmark = pytest.mark.single_cpu
15-
1611

1712
@pytest.fixture(autouse=True)
1813
def cd_and_set_engine(monkeypatch, datapath):

Diff for: pandas/tests/io/excel/test_odswriter.py

+49-49
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,62 @@
33
datetime,
44
)
55
import re
6+
import uuid
67

78
import pytest
89

9-
from pandas.compat import is_platform_windows
10-
1110
import pandas as pd
12-
import pandas._testing as tm
1311

1412
from pandas.io.excel import ExcelWriter
1513

1614
odf = pytest.importorskip("odf")
1715

18-
if is_platform_windows():
19-
pytestmark = pytest.mark.single_cpu
20-
2116

2217
@pytest.fixture
2318
def ext():
2419
return ".ods"
2520

2621

27-
def test_write_append_mode_raises(ext):
22+
@pytest.fixture
23+
def tmp_excel(ext, tmp_path):
24+
tmp = tmp_path / f"{uuid.uuid4()}{ext}"
25+
tmp.touch()
26+
return str(tmp)
27+
28+
29+
def test_write_append_mode_raises(tmp_excel):
2830
msg = "Append mode is not supported with odf!"
2931

30-
with tm.ensure_clean(ext) as f:
31-
with pytest.raises(ValueError, match=msg):
32-
ExcelWriter(f, engine="odf", mode="a")
32+
with pytest.raises(ValueError, match=msg):
33+
ExcelWriter(tmp_excel, engine="odf", mode="a")
3334

3435

3536
@pytest.mark.parametrize("engine_kwargs", [None, {"kwarg": 1}])
36-
def test_engine_kwargs(ext, engine_kwargs):
37+
def test_engine_kwargs(tmp_excel, engine_kwargs):
3738
# GH 42286
3839
# GH 43445
3940
# test for error: OpenDocumentSpreadsheet does not accept any arguments
40-
with tm.ensure_clean(ext) as f:
41-
if engine_kwargs is not None:
42-
error = re.escape(
43-
"OpenDocumentSpreadsheet() got an unexpected keyword argument 'kwarg'"
44-
)
45-
with pytest.raises(
46-
TypeError,
47-
match=error,
48-
):
49-
ExcelWriter(f, engine="odf", engine_kwargs=engine_kwargs)
50-
else:
51-
with ExcelWriter(f, engine="odf", engine_kwargs=engine_kwargs) as _:
52-
pass
53-
54-
55-
def test_book_and_sheets_consistent(ext):
41+
if engine_kwargs is not None:
42+
error = re.escape(
43+
"OpenDocumentSpreadsheet() got an unexpected keyword argument 'kwarg'"
44+
)
45+
with pytest.raises(
46+
TypeError,
47+
match=error,
48+
):
49+
ExcelWriter(tmp_excel, engine="odf", engine_kwargs=engine_kwargs)
50+
else:
51+
with ExcelWriter(tmp_excel, engine="odf", engine_kwargs=engine_kwargs) as _:
52+
pass
53+
54+
55+
def test_book_and_sheets_consistent(tmp_excel):
5656
# GH#45687 - Ensure sheets is updated if user modifies book
57-
with tm.ensure_clean(ext) as f:
58-
with ExcelWriter(f) as writer:
59-
assert writer.sheets == {}
60-
table = odf.table.Table(name="test_name")
61-
writer.book.spreadsheet.addElement(table)
62-
assert writer.sheets == {"test_name": table}
57+
with ExcelWriter(tmp_excel) as writer:
58+
assert writer.sheets == {}
59+
table = odf.table.Table(name="test_name")
60+
writer.book.spreadsheet.addElement(table)
61+
assert writer.sheets == {"test_name": table}
6362

6463

6564
@pytest.mark.parametrize(
@@ -78,7 +77,9 @@ def test_book_and_sheets_consistent(ext):
7877
(date(2010, 10, 10), "date", "date-value", "2010-10-10"),
7978
],
8079
)
81-
def test_cell_value_type(ext, value, cell_value_type, cell_value_attribute, cell_value):
80+
def test_cell_value_type(
81+
tmp_excel, value, cell_value_type, cell_value_attribute, cell_value
82+
):
8283
# GH#54994 ODS: cell attributes should follow specification
8384
# http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html#refTable13
8485
from odf.namespaces import OFFICENS
@@ -89,18 +90,17 @@ def test_cell_value_type(ext, value, cell_value_type, cell_value_attribute, cell
8990

9091
table_cell_name = TableCell().qname
9192

92-
with tm.ensure_clean(ext) as f:
93-
pd.DataFrame([[value]]).to_excel(f, header=False, index=False)
94-
95-
with pd.ExcelFile(f) as wb:
96-
sheet = wb._reader.get_sheet_by_index(0)
97-
sheet_rows = sheet.getElementsByType(TableRow)
98-
sheet_cells = [
99-
x
100-
for x in sheet_rows[0].childNodes
101-
if hasattr(x, "qname") and x.qname == table_cell_name
102-
]
103-
104-
cell = sheet_cells[0]
105-
assert cell.attributes.get((OFFICENS, "value-type")) == cell_value_type
106-
assert cell.attributes.get((OFFICENS, cell_value_attribute)) == cell_value
93+
pd.DataFrame([[value]]).to_excel(tmp_excel, header=False, index=False)
94+
95+
with pd.ExcelFile(tmp_excel) as wb:
96+
sheet = wb._reader.get_sheet_by_index(0)
97+
sheet_rows = sheet.getElementsByType(TableRow)
98+
sheet_cells = [
99+
x
100+
for x in sheet_rows[0].childNodes
101+
if hasattr(x, "qname") and x.qname == table_cell_name
102+
]
103+
104+
cell = sheet_cells[0]
105+
assert cell.attributes.get((OFFICENS, "value-type")) == cell_value_type
106+
assert cell.attributes.get((OFFICENS, cell_value_attribute)) == cell_value

0 commit comments

Comments
 (0)