Skip to content

Commit

Permalink
Eliminate spurious tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matteobachetti committed Jan 31, 2025
1 parent be64555 commit e937fa0
Showing 1 changed file with 0 additions and 77 deletions.
77 changes: 0 additions & 77 deletions stingray/tests/test_varenergyspectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,80 +591,3 @@ def test_lagspectrum_invalid_warns(self):

assert np.all(np.isnan(lag.spectrum))
assert np.all(np.isnan(lag.spectrum_error))


class TestRoundTrip:
@classmethod
def setup_class(cls):
tstart = 0.0
tend = 100.0
nphot = 1000
alltimes = np.random.uniform(tstart, tend, nphot)
alltimes.sort()
cls.events = EventList(
alltimes, energy=np.random.uniform(0.3, 12, nphot), gti=[[tstart, tend]]
)
cls.vespec = DummyVarEnergy(
cls.events, [0.0, 10000], (0.5, 5, 10, "lin"), [0.3, 10], bin_time=0.1
)
cls.vespec.spectrum = np.zeros_like(cls.vespec.energy)
cls.vespec.spectrum_error = np.zeros_like(cls.vespec.energy)

def _check_equal(self, so, table):
for attr in ["energy", "spectrum", "spectrum_error"]:
assert np.allclose(getattr(so, attr), table[attr])

if hasattr(table, "meta"):
for attr in ["freq_interval"]:
assert getattr(so, attr) == table.meta[attr]
if hasattr(table, "attrs"):
for attr in ["freq_interval"]:
assert getattr(so, attr) == table.attrs[attr]

def test_astropy_export(self):
so = self.vespec
ts = so.to_astropy_table()
self._check_equal(so, ts)
with pytest.raises(NotImplementedError):
so.from_astropy_table(ts)

@pytest.mark.skipif("not _HAS_XARRAY")
def test_xarray_export(self):
so = self.vespec
ts = so.to_xarray()
self._check_equal(so, ts)
with pytest.raises(NotImplementedError):
so.from_xarray(ts)

@pytest.mark.skipif("not _HAS_PANDAS")
def test_pandas_export(self):
so = self.vespec
ts = so.to_pandas()
self._check_equal(so, ts)
with pytest.raises(NotImplementedError):
so.from_pandas(ts)

@pytest.mark.skipif("not _HAS_H5PY")
def test_hdf_export(self):
so = self.vespec
so.write("dummy.hdf5")
new_so = Table.read("dummy.hdf5")
os.unlink("dummy.hdf5")
self._check_equal(so, new_so)

@pytest.mark.parametrize("fmt", ["ascii.ecsv", "ascii", "fits"])
def test_file_export(self, fmt):
so = self.vespec
with pytest.warns(UserWarning, match=".* output does not serialize the metadata"):
so.write("dummy", fmt=fmt)
new_so = Table.read("dummy", format=fmt)
os.unlink("dummy")
self._check_equal(so, new_so)

@pytest.mark.parametrize("fmt", ["pickle"])
def test_file_export_pickle(self, fmt):
so = self.vespec
so.write("dummy", fmt=fmt)
new_so = so.read("dummy", fmt=fmt)
os.unlink("dummy")
self._check_equal(so, new_so.to_astropy_table())

0 comments on commit e937fa0

Please sign in to comment.