def test_open_report(tmp_path): """Test the open_report function.""" tempdir = str(tmp_path) hdf5 = op.join(tempdir, 'report.h5') # Test creating a new report through the open_report function fig1 = _get_example_figures()[0] with open_report(hdf5, subjects_dir=subjects_dir) as report: assert report.subjects_dir == subjects_dir assert report.fname == hdf5 report.add_figure(fig=fig1, title='evoked response') # Exiting the context block should have triggered saving to HDF5 assert op.exists(hdf5) # Load the HDF5 version of the report and check equivalence report2 = open_report(hdf5) assert report2.fname == hdf5 assert report2.subjects_dir == report.subjects_dir assert report2.html == report.html assert report2.__getstate__() == report.__getstate__() assert '_fname' not in report2.__getstate__() # Check parameters when loading a report pytest.raises(ValueError, open_report, hdf5, foo='bar') # non-existing pytest.raises(ValueError, open_report, hdf5, subjects_dir='foo') open_report(hdf5, subjects_dir=subjects_dir) # This should work # Check that the context manager doesn't swallow exceptions with pytest.raises(ZeroDivisionError): with open_report(hdf5, subjects_dir=subjects_dir) as report: 1 / 0
def test_open_report(): """Test the open_report function.""" tempdir = _TempDir() hdf5 = op.join(tempdir, 'report.h5') # Test creating a new report through the open_report function fig1 = _get_example_figures()[0] with open_report(hdf5, subjects_dir=subjects_dir) as report: assert report.subjects_dir == subjects_dir assert report._fname == hdf5 report.add_figs_to_section(figs=fig1, captions=['evoked response']) # Exiting the context block should have triggered saving to HDF5 assert op.exists(hdf5) # Load the HDF5 version of the report and check equivalence report2 = open_report(hdf5) assert report2._fname == hdf5 assert report2.subjects_dir == report.subjects_dir assert report2.html == report.html assert report2.__getstate__() == report.__getstate__() assert '_fname' not in report2.__getstate__() # Check parameters when loading a report pytest.raises(ValueError, open_report, hdf5, foo='bar') # non-existing pytest.raises(ValueError, open_report, hdf5, subjects_dir='foo') open_report(hdf5, subjects_dir=subjects_dir) # This should work
def test_open_report(): """Test the open_report function.""" tempdir = _TempDir() hdf5 = op.join(tempdir, 'report.h5') import matplotlib.pyplot as plt fig = plt.plot([1, 2], [1, 2])[0].figure # Test creating a new report through the open_report function with open_report(hdf5, subjects_dir=subjects_dir) as report: assert report.subjects_dir == subjects_dir assert report._fname == hdf5 report.add_figs_to_section(figs=fig, captions=['evoked response']) # Exiting the context block should have triggered saving to HDF5 assert op.exists(hdf5) # Load the HDF5 version of the report and check equivalency report2 = open_report(hdf5) assert report2._fname == hdf5 assert report2.subjects_dir == report.subjects_dir assert report2.html == report.html assert report2.__getstate__() == report.__getstate__() assert '_fname' not in report2.__getstate__() # Check parameters when loading a report pytest.raises(ValueError, open_report, hdf5, foo='bar') # non-existing pytest.raises(ValueError, open_report, hdf5, subjects_dir='foo') open_report(hdf5, subjects_dir=subjects_dir) # This should work