@pytest.mark.slowtest
@testing.requires_testing_data
def test_render_report():
    'Test rendering -*.fif files for mne report.'
    tempdir = _TempDir()
    raw_fname_new = op.join(tempdir, 'temp_raw.fif')
    ms_fname_new = op.join(tempdir, 'temp_ms_raw.fif')
    event_fname_new = op.join(tempdir, 'temp_raw-eve.fif')
    cov_fname_new = op.join(tempdir, 'temp_raw-cov.fif')
    fwd_fname_new = op.join(tempdir, 'temp_raw-fwd.fif')
    inv_fname_new = op.join(tempdir, 'temp_raw-inv.fif')
    for (a, b) in [[raw_fname, raw_fname_new], [ms_fname, ms_fname_new], [event_fname, event_fname_new], [cov_fname, cov_fname_new], [fwd_fname, fwd_fname_new], [inv_fname, inv_fname_new]]:
        shutil.copyfile(a, b)
    epochs_fname = op.join(tempdir, 'temp-epo.fif')
    evoked_fname = op.join(tempdir, 'temp-ave.fif')
    raw = read_raw_fif(raw_fname_new, preload=True)
    raw.pick_channels(['MEG 0111', 'MEG 0121'])
    raw.del_proj()
    epochs = Epochs(raw, read_events(event_fname), 1, (- 0.2), 0.2)
    epochs.save(epochs_fname, overwrite=True)
    epochs.average().crop(0.1, 0.2).save(evoked_fname)
    report = Report(info_fname=raw_fname_new, subjects_dir=subjects_dir)
    with pytest.warns(RuntimeWarning, match='Cannot render MRI'):
        report.parse_folder(data_path=tempdir, on_error='raise')
    assert repr(report)
    fnames = glob.glob(op.join(tempdir, '*.fif'))
    for fname in fnames:
        assert (op.basename(fname) in [op.basename(x) for x in report.fnames])
        assert (''.join(report.html).find(op.basename(fname)) != (- 1))
    assert_equal(len(report.fnames), len(fnames))
    assert_equal(len(report.html), len(report.fnames))
    assert_equal(len(report.fnames), len(report))
    report.data_path = tempdir
    fname = op.join(tempdir, 'report.html')
    report.save(fname=fname, open_browser=False)
    assert op.isfile(fname)
    with open(fname, 'rb') as fid:
        html = fid.read().decode('utf-8')
    assert ('(MaxShield on)' in html)
    assert_equal(len(report.html), len(fnames))
    assert_equal(len(report.html), len(report.fnames))
    report.save(fname=op.join(tempdir, 'report2.html'), open_browser=False)
    assert op.isfile(op.join(tempdir, 'report2.html'))
    report.save(fname=op.join(tempdir, 'report.html'), open_browser=False, overwrite=True)
    assert op.isfile(op.join(tempdir, 'report.html'))
    pattern = ['*raw.fif', '*eve.fif']
    with pytest.warns(RuntimeWarning, match='Cannot render MRI'):
        report.parse_folder(data_path=tempdir, pattern=pattern)
    assert repr(report)
    fnames = (glob.glob(op.join(tempdir, '*.raw')) + glob.glob(op.join(tempdir, '*.raw')))
    for fname in fnames:
        assert (op.basename(fname) in [op.basename(x) for x in report.fnames])
        assert (''.join(report.html).find(op.basename(fname)) != (- 1))
    pytest.raises(ValueError, Report, image_format='foo')
    pytest.raises(ValueError, Report, image_format=None)
    report = Report(info_fname=raw_fname_new, subjects_dir=subjects_dir, image_format='svg')
    with pytest.warns(RuntimeWarning, match='Cannot render MRI'):
        report.parse_folder(data_path=tempdir, on_error='raise')
    report.add_figs_to_section(np.zeros((2, 3, 3)), 'caption', 'section')
    with pytest.raises(TypeError, match='Each fig must be a'):
        report.add_figs_to_section('foo', 'caption', 'section')
    with pytest.raises(TypeError, match='Each fig must be a'):
        report.add_figs_to_section(['foo'], 'caption', 'section')
Test rendering -*.fif files for mne report.
@pytest.mark.slowtest
@testing.requires_testing_data
def test_render_report():
    
    tempdir = _TempDir()
    raw_fname_new = op.join(tempdir, 'temp_raw.fif')
    ms_fname_new = op.join(tempdir, 'temp_ms_raw.fif')
    event_fname_new = op.join(tempdir, 'temp_raw-eve.fif')
    cov_fname_new = op.join(tempdir, 'temp_raw-cov.fif')
    fwd_fname_new = op.join(tempdir, 'temp_raw-fwd.fif')
    inv_fname_new = op.join(tempdir, 'temp_raw-inv.fif')
    for (a, b) in [[raw_fname, raw_fname_new], [ms_fname, ms_fname_new], [event_fname, event_fname_new], [cov_fname, cov_fname_new], [fwd_fname, fwd_fname_new], [inv_fname, inv_fname_new]]:
        shutil.copyfile(a, b)
    epochs_fname = op.join(tempdir, 'temp-epo.fif')
    evoked_fname = op.join(tempdir, 'temp-ave.fif')
    raw = read_raw_fif(raw_fname_new, preload=True)
    raw.pick_channels(['MEG 0111', 'MEG 0121'])
    raw.del_proj()
    epochs = Epochs(raw, read_events(event_fname), 1, (- 0.2), 0.2)
    epochs.save(epochs_fname, overwrite=True)
    epochs.average().crop(0.1, 0.2).save(evoked_fname)
    report = Report(info_fname=raw_fname_new, subjects_dir=subjects_dir)
    with pytest.warns(RuntimeWarning, match='Cannot render MRI'):
        report.parse_folder(data_path=tempdir, on_error='raise')
    assert repr(report)
    fnames = glob.glob(op.join(tempdir, '*.fif'))
    for fname in fnames:
        assert (op.basename(fname) in [op.basename(x) for x in report.fnames])
        assert (.join(report.html).find(op.basename(fname)) != (- 1))
    assert_equal(len(report.fnames), len(fnames))
    assert_equal(len(report.html), len(report.fnames))
    assert_equal(len(report.fnames), len(report))
    report.data_path = tempdir
    fname = op.join(tempdir, 'report.html')
    report.save(fname=fname, open_browser=False)
    assert op.isfile(fname)
    with open(fname, 'rb') as fid:
        html = fid.read().decode('utf-8')
    assert ('(MaxShield on)' in html)
    assert_equal(len(report.html), len(fnames))
    assert_equal(len(report.html), len(report.fnames))
    report.save(fname=op.join(tempdir, 'report2.html'), open_browser=False)
    assert op.isfile(op.join(tempdir, 'report2.html'))
    report.save(fname=op.join(tempdir, 'report.html'), open_browser=False, overwrite=True)
    assert op.isfile(op.join(tempdir, 'report.html'))
    pattern = ['*raw.fif', '*eve.fif']
    with pytest.warns(RuntimeWarning, match='Cannot render MRI'):
        report.parse_folder(data_path=tempdir, pattern=pattern)
    assert repr(report)
    fnames = (glob.glob(op.join(tempdir, '*.raw')) + glob.glob(op.join(tempdir, '*.raw')))
    for fname in fnames:
        assert (op.basename(fname) in [op.basename(x) for x in report.fnames])
        assert (.join(report.html).find(op.basename(fname)) != (- 1))
    pytest.raises(ValueError, Report, image_format='foo')
    pytest.raises(ValueError, Report, image_format=None)
    report = Report(info_fname=raw_fname_new, subjects_dir=subjects_dir, image_format='svg')
    with pytest.warns(RuntimeWarning, match='Cannot render MRI'):
        report.parse_folder(data_path=tempdir, on_error='raise')
    report.add_figs_to_section(np.zeros((2, 3, 3)), 'caption', 'section')
    with pytest.raises(TypeError, match='Each fig must be a'):
        report.add_figs_to_section('foo', 'caption', 'section')
    with pytest.raises(TypeError, match='Each fig must be a'):
        report.add_figs_to_section(['foo'], 'caption', 'section')