Skip to content

Commit e24e2e2

Browse files
authored
Fixes for pytest 9.0 (#624)
Signed-off-by: Adam Glustein <adam.glustein@point72.com>
1 parent 4d54ae2 commit e24e2e2

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

csp/tests/adapters/test_kafka.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ def get_data(start_offset, expected_count):
314314
)["data"]
315315
assert len(res) == len(expected)
316316

317-
@pytest.mark.skipif(not os.environ.get("CSP_TEST_KAFKA"), reason="Skipping kafka adapter tests")
318317
@pytest.fixture(autouse=True)
319318
def test_raw_pubsub(self, kafkaadapter):
320319
@csp.node

csp/tests/adapters/test_perspective.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
from csp.adapters.perspective import PerspectiveAdapter
88
from csp.impl.pandas_perspective import CspPerspectiveMultiTable, CspPerspectiveTable
99
from csp.impl.perspective_common import PerspectiveWidget, is_perspective3
10+
11+
HAS_PERSPECTIVE = True
1012
except ImportError:
11-
raise unittest.SkipTest("skipping perspective tests")
13+
HAS_PERSPECTIVE = False
1214

1315

1416
class MyStruct(csp.Struct):
@@ -30,6 +32,7 @@ def my_graph(output={}):
3032

3133

3234
class TestPerspectiveAdapter(unittest.TestCase):
35+
@unittest.skipIf(not HAS_PERSPECTIVE, "Test requires perspective")
3336
def test_adapter(self):
3437
output = {}
3538
csp.run(my_graph, output, starttime=datetime.utcnow(), endtime=timedelta(seconds=1))

csp/tests/impl/test_pandas_perspective.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
from csp.impl.perspective_common import PerspectiveWidget, is_perspective3
1919

2020
_PERSPECTIVE_3 = is_perspective3()
21+
HAS_PERSPECTIVE = True
2122
except ImportError:
22-
raise unittest.SkipTest("skipping perspective tests")
23+
HAS_PERSPECTIVE = False
2324

2425

2526
class TestCspPerspectiveTable(unittest.TestCase):
@@ -66,11 +67,13 @@ def check_table_history(self, table, target, index_col, time_col):
6667
print(target)
6768
pd.testing.assert_frame_equal(df, target)
6869

70+
@unittest.skipIf(not HAS_PERSPECTIVE, "Test requires perspective and ipywidgets")
6971
def test_not_running(self):
7072
table = CspPerspectiveTable(self.df)
7173
self.assertRaises(ValueError, table.stop)
7274
self.assertRaises(ValueError, table.join)
7375

76+
@unittest.skipIf(not HAS_PERSPECTIVE, "Test requires perspective and ipywidgets")
7477
def test_keep_history(self):
7578
target = self.df.csp.run(starttime=datetime(2020, 1, 1), endtime=timedelta(seconds=4))
7679

@@ -96,6 +99,7 @@ def test_keep_history(self):
9699

97100
self.assertRaises(ValueError, CspPerspectiveTable, self.df, time_col=None, keep_history=True)
98101

102+
@unittest.skipIf(not HAS_PERSPECTIVE, "Test requires perspective and ipywidgets")
99103
def test_run_multiple(self):
100104
table = CspPerspectiveTable(self.df)
101105
table.start(starttime=datetime(2020, 1, 1), endtime=timedelta(seconds=2))
@@ -110,6 +114,7 @@ def test_run_multiple(self):
110114
df2 = table.to_df()
111115
self.assertEqual(len(df2), 2 * len(df1))
112116

117+
@unittest.skipIf(not HAS_PERSPECTIVE, "Test requires perspective and ipywidgets")
113118
def test_limit(self):
114119
table = CspPerspectiveTable(self.df, limit=3)
115120
table.start(starttime=datetime(2020, 1, 1), endtime=timedelta(seconds=20))
@@ -131,6 +136,7 @@ def test_limit(self):
131136

132137
self.assertRaises(ValueError, CspPerspectiveTable, self.df, keep_history=False, limit=3)
133138

139+
@unittest.skipIf(not HAS_PERSPECTIVE, "Test requires perspective and ipywidgets")
134140
def test_localize(self):
135141
# In this mode, the timestamp column should be in "local time", not utc
136142
self.df["datetime_col"] = pd.Series(
@@ -159,6 +165,7 @@ def test_localize(self):
159165
target = pd.Series(["2020-01-01 01", "2020-01-01 02", np.nan], dtype="datetime64[ns]", name="datetime_col")
160166
pd.testing.assert_series_equal(utc, target)
161167

168+
@unittest.skipIf(not HAS_PERSPECTIVE, "Test requires perspective and ipywidgets")
162169
def test_snap(self):
163170
index_col = "my_index"
164171
time_col = "my_timestamp"
@@ -186,6 +193,7 @@ def test_snap(self):
186193
out = out.convert_dtypes()
187194
pd.testing.assert_frame_equal(out, target.drop(columns=time_col))
188195

196+
@unittest.skipIf(not HAS_PERSPECTIVE, "Test requires perspective and ipywidgets")
189197
def test_run_types(self):
190198
s_str = pd.Series([csp.const("a") for _ in self.idx], dtype=TsDtype(str), index=self.idx)
191199
s_int = pd.Series([csp.const(0) for _ in self.idx], dtype=TsDtype(int), index=self.idx)
@@ -229,6 +237,7 @@ def test_run_types(self):
229237
)
230238
pd.testing.assert_series_equal(df.dtypes, dtypes)
231239

240+
@unittest.skipIf(not HAS_PERSPECTIVE, "Test requires perspective and ipywidgets")
232241
def test_run_historical(self):
233242
index_col = "my_index"
234243
time_col = "my_timestamp"
@@ -273,6 +282,7 @@ def test_run_historical(self):
273282
if not _PERSPECTIVE_3: # See https://github.com/finos/perspective/pull/2756
274283
pd.testing.assert_frame_equal(out.sort_values([index_col, time_col]), target)
275284

285+
@unittest.skipIf(not HAS_PERSPECTIVE, "Test requires perspective and ipywidgets")
276286
def test_real_time(self):
277287
table = CspPerspectiveTable(self.df, keep_history=False)
278288
table.start(endtime=timedelta(seconds=0.2), realtime=True)
@@ -290,6 +300,7 @@ def test_real_time(self):
290300
self.assertFalse(table.is_running())
291301
self.assertLess(table.to_df()["timestamp"].max(), endtime - timedelta(seconds=2))
292302

303+
@unittest.skipIf(not HAS_PERSPECTIVE, "Test requires perspective and ipywidgets")
293304
def test_empty(self):
294305
table = CspPerspectiveTable(self.df.csp.static_frame(), keep_history=True)
295306
table.start(starttime=datetime(2020, 1, 1), endtime=timedelta(seconds=2))
@@ -306,6 +317,7 @@ def test_empty(self):
306317
df2 = self._adjust_psp3(df2, "index", None)
307318
pd.testing.assert_frame_equal(df2, self.df.csp.static_frame().reset_index())
308319

320+
@unittest.skipIf(not HAS_PERSPECTIVE, "Test requires perspective and ipywidgets")
309321
def test_get_widget(self):
310322
table = CspPerspectiveTable(self.df, index_col="my_index", time_col="my_timestamp")
311323
widget = table.get_widget()
@@ -338,6 +350,7 @@ def test_get_widget(self):
338350
self.assertEqual(widget.sort, [["foo", "asc"]])
339351
self.assertEqual(widget.theme, "Material Dark")
340352

353+
@unittest.skipIf(not HAS_PERSPECTIVE, "Test requires perspective and ipywidgets")
341354
def test_multi_table(self):
342355
tables = {"test1": CspPerspectiveTable(self.df), "test2": CspPerspectiveTable(self.df, keep_history=False)}
343356
tables["test3"] = tables["test1"]
@@ -356,6 +369,7 @@ def test_multi_table(self):
356369
self.assertEqual(len(multi["test2"].to_df()), 3)
357370
self.assertEqual(len(multi["test3"].to_df()), len(multi["test1"].to_df()))
358371

372+
@unittest.skipIf(not HAS_PERSPECTIVE, "Test requires perspective and ipywidgets")
359373
def test_multi_table_widget(self):
360374
tables = {"test1": CspPerspectiveTable(self.df), "test2": CspPerspectiveTable(self.df, keep_history=False)}
361375
tables["test3"] = tables["test1"]

0 commit comments

Comments
 (0)