1
+ from importlib .metadata import version
1
2
from pathlib import Path
2
3
3
4
import pytest
5
+ from packaging .version import Version , parse
4
6
5
7
try :
6
8
import pandas as pd
12
14
PATH = Path (__file__ ).parent / "data"
13
15
14
16
17
+ @pytest .fixture (scope = "module" , autouse = True )
18
+ def pandas_monkeypatch ():
19
+ if parse (version ("pandas" )) >= Version ("2.2.0" ):
20
+ yield
21
+ else :
22
+ from python_calamine .pandas import pandas_monkeypatch
23
+
24
+ pandas_monkeypatch ()
25
+ yield
26
+
27
+
15
28
@pytest .mark .skipif (not pd , reason = "pandas is required" )
16
- def test_ods_pandas (pandas_monkeypatch , expected_df_ods ):
29
+ def test_ods_pandas (expected_df_ods ):
17
30
result = pd .read_excel (PATH / "base.ods" , sheet_name = "Sheet1" , engine = "calamine" )
18
31
19
32
tm .assert_frame_equal (result , expected_df_ods )
20
33
21
34
22
35
@pytest .mark .skipif (not pd , reason = "pandas is required" )
23
36
@pytest .mark .xfail (reason = "OdfReader can't parse timedelta" )
24
- def test_ods_odfpy_pandas (pandas_monkeypatch ):
37
+ def test_ods_odfpy_pandas ():
25
38
result_calamine = pd .read_excel (
26
39
PATH / "base.ods" , sheet_name = "Sheet1" , engine = "calamine"
27
40
)
@@ -38,14 +51,14 @@ def test_ods_odfpy_pandas(pandas_monkeypatch):
38
51
39
52
40
53
@pytest .mark .skipif (not pd , reason = "pandas is required" )
41
- def test_xls_pandas (pandas_monkeypatch , expected_df_excel ):
54
+ def test_xls_pandas (expected_df_excel ):
42
55
result = pd .read_excel (PATH / "base.xls" , sheet_name = "Sheet1" , engine = "calamine" )
43
56
44
57
tm .assert_frame_equal (result , expected_df_excel )
45
58
46
59
47
60
@pytest .mark .skipif (not pd , reason = "pandas is required" )
48
- def test_xls_xlrd_pandas (pandas_monkeypatch ):
61
+ def test_xls_xlrd_pandas ():
49
62
result_calamine = pd .read_excel (
50
63
PATH / "base.xls" , sheet_name = "Sheet1" , engine = "calamine"
51
64
)
@@ -63,14 +76,14 @@ def test_xls_xlrd_pandas(pandas_monkeypatch):
63
76
64
77
65
78
@pytest .mark .skipif (not pd , reason = "pandas is required" )
66
- def test_xlsb_pandas (pandas_monkeypatch , expected_df_excel ):
79
+ def test_xlsb_pandas (expected_df_excel ):
67
80
result = pd .read_excel (PATH / "base.xlsb" , sheet_name = "Sheet1" , engine = "calamine" )
68
81
69
82
tm .assert_frame_equal (result , expected_df_excel )
70
83
71
84
72
85
@pytest .mark .skipif (not pd , reason = "pandas is required" )
73
- def test_xlsb_pyxlsb_pandas (pandas_monkeypatch ):
86
+ def test_xlsb_pyxlsb_pandas ():
74
87
result_calamine = pd .read_excel (
75
88
PATH / "base.xlsb" , sheet_name = "Sheet1" , engine = "calamine"
76
89
)
@@ -88,14 +101,14 @@ def test_xlsb_pyxlsb_pandas(pandas_monkeypatch):
88
101
89
102
90
103
@pytest .mark .skipif (not pd , reason = "pandas is required" )
91
- def test_xlsx_pandas (pandas_monkeypatch , expected_df_excel ):
104
+ def test_xlsx_pandas (expected_df_excel ):
92
105
result = pd .read_excel (PATH / "base.xlsx" , sheet_name = "Sheet1" , engine = "calamine" )
93
106
94
107
tm .assert_frame_equal (result , expected_df_excel )
95
108
96
109
97
110
@pytest .mark .skipif (not pd , reason = "pandas is required" )
98
- def test_xlsb_openpyxl_pandas (pandas_monkeypatch ):
111
+ def test_xlsb_openpyxl_pandas ():
99
112
result_calamine = pd .read_excel (
100
113
PATH / "base.xlsx" , sheet_name = "Sheet1" , engine = "calamine"
101
114
)
0 commit comments