1
1
import numpy as np
2
- import pytest
3
2
4
3
import pandas ._config .config as cf
5
4
@@ -120,16 +119,8 @@ def test_ambiguous_width(self):
120
119
121
120
122
121
class TestTableSchemaRepr :
123
- @classmethod
124
- def setup_class (cls ):
125
- pytest .importorskip ("IPython" )
126
-
127
- from IPython .core .interactiveshell import InteractiveShell
128
-
129
- cls .display_formatter = InteractiveShell .instance ().display_formatter
130
-
131
- def test_publishes (self ):
132
-
122
+ def test_publishes (self , ip ):
123
+ ipython = ip .instance (config = ip .config )
133
124
df = pd .DataFrame ({"A" : [1 , 2 ]})
134
125
objects = [df ["A" ], df , df ] # dataframe / series
135
126
expected_keys = [
@@ -140,13 +131,13 @@ def test_publishes(self):
140
131
opt = pd .option_context ("display.html.table_schema" , True )
141
132
for obj , expected in zip (objects , expected_keys ):
142
133
with opt :
143
- formatted = self .display_formatter .format (obj )
134
+ formatted = ipython .display_formatter .format (obj )
144
135
assert set (formatted [0 ].keys ()) == expected
145
136
146
137
with_latex = pd .option_context ("display.latex.repr" , True )
147
138
148
139
with opt , with_latex :
149
- formatted = self .display_formatter .format (obj )
140
+ formatted = ipython .display_formatter .format (obj )
150
141
151
142
expected = {
152
143
"text/plain" ,
@@ -156,7 +147,7 @@ def test_publishes(self):
156
147
}
157
148
assert set (formatted [0 ].keys ()) == expected
158
149
159
- def test_publishes_not_implemented (self ):
150
+ def test_publishes_not_implemented (self , ip ):
160
151
# column MultiIndex
161
152
# GH 15996
162
153
midx = pd .MultiIndex .from_product ([["A" , "B" ], ["a" , "b" , "c" ]])
@@ -165,7 +156,7 @@ def test_publishes_not_implemented(self):
165
156
opt = pd .option_context ("display.html.table_schema" , True )
166
157
167
158
with opt :
168
- formatted = self .display_formatter .format (df )
159
+ formatted = ip . instance ( config = ip . config ) .display_formatter .format (df )
169
160
170
161
expected = {"text/plain" , "text/html" }
171
162
assert set (formatted [0 ].keys ()) == expected
@@ -184,9 +175,9 @@ def test_config_default_off(self):
184
175
185
176
assert result is None
186
177
187
- def test_enable_data_resource_formatter (self ):
178
+ def test_enable_data_resource_formatter (self , ip ):
188
179
# GH 10491
189
- formatters = self .display_formatter .formatters
180
+ formatters = ip . instance ( config = ip . config ) .display_formatter .formatters
190
181
mimetype = "application/vnd.dataresource+json"
191
182
192
183
with pd .option_context ("display.html.table_schema" , True ):
@@ -202,4 +193,4 @@ def test_enable_data_resource_formatter(self):
202
193
assert "application/vnd.dataresource+json" in formatters
203
194
assert formatters [mimetype ].enabled
204
195
# smoke test that it works
205
- self .display_formatter .format (cf )
196
+ ip . instance ( config = ip . config ) .display_formatter .format (cf )
0 commit comments