Skip to content

Commit 2f93c34

Browse files
Improve test to use pytest.importorskip for pandas
Co-authored-by: Gui-FernandesBR <[email protected]>
1 parent ed26a4a commit 2f93c34

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

tests/unit/test_flight_data_exporter.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import json
88

99
import numpy as np
10+
import pytest
1011

1112
from rocketpy.simulation import FlightDataExporter
1213

@@ -225,30 +226,25 @@ def test_export_data_csv_column_names_no_leading_spaces(flight_calisto, tmp_path
225226
assert ", " not in header_line, "Header should not contain ', ' (comma-space)"
226227

227228
# Verify with pandas that columns are accessible without leading spaces
228-
try:
229-
import pandas as pd
230-
231-
df = pd.read_csv(file_name)
232-
columns = df.columns.tolist()
233-
234-
# First column should be '# Time (s)'
235-
assert columns[0] == "# Time (s)"
236-
237-
# Other columns should NOT have leading spaces
238-
for col in columns[1:]:
239-
assert not col.startswith(" "), f"Column '{col}' has leading space"
240-
241-
# Verify columns are accessible with expected names (no leading spaces)
242-
assert "Z (m)" in columns
243-
assert "Vz (m/s)" in columns
244-
assert "Altitude AGL (m)" in columns
245-
246-
# Verify we can access data using column names without spaces
247-
_ = df["# Time (s)"]
248-
_ = df["Z (m)"]
249-
_ = df["Vz (m/s)"]
250-
_ = df["Altitude AGL (m)"]
251-
252-
except ImportError:
253-
# pandas not available, skip pandas-specific test
254-
pass
229+
pd = pytest.importorskip("pandas")
230+
231+
df = pd.read_csv(file_name)
232+
columns = df.columns.tolist()
233+
234+
# First column should be '# Time (s)'
235+
assert columns[0] == "# Time (s)"
236+
237+
# Other columns should NOT have leading spaces
238+
for col in columns[1:]:
239+
assert not col.startswith(" "), f"Column '{col}' has leading space"
240+
241+
# Verify columns are accessible with expected names (no leading spaces)
242+
assert "Z (m)" in columns
243+
assert "Vz (m/s)" in columns
244+
assert "Altitude AGL (m)" in columns
245+
246+
# Verify we can access data using column names without spaces
247+
_ = df["# Time (s)"]
248+
_ = df["Z (m)"]
249+
_ = df["Vz (m/s)"]
250+
_ = df["Altitude AGL (m)"]

0 commit comments

Comments
 (0)