Example #1
0
 def execute(code, reset=False):
     _nbclient.reset_execution_trackers()
     with _nbclient.setup_kernel():
         assert _nbclient.kc is not None
         cell = Bunch(cell_type='code', metadata={}, source=dedent(code))
         _nbclient.execute_cell(cell, 0, execution_count=0)
         _nbclient.set_widgets_metadata()
Example #2
0
def test_strip_dev(version, want, have_unstripped, monkeypatch):
    """Test that stripping dev works."""
    monkeypatch.setattr(mne.utils.check, 'import_module',
                        lambda x: Bunch(__version__=version))
    got_have_unstripped, same_version = check_version(version,
                                                      want,
                                                      strip=False,
                                                      return_version=True)
    assert same_version == version
    assert got_have_unstripped is have_unstripped
    have, simpler_version = check_version(
        'foo', want, return_version=True)  # strip=True is the default
    assert have, (simpler_version, version)

    def looks_stable(version):
        try:
            [int(x) for x in version.split('.')]
        except ValueError:
            return False
        else:
            return True

    if looks_stable(version):
        assert 'dev' not in version
        assert 'rc' not in version
        assert simpler_version == version
    else:
        assert simpler_version != version
    assert 'dev' not in simpler_version
    assert 'rc' not in simpler_version
    assert not simpler_version.endswith('.')
    assert looks_stable(simpler_version)
Example #3
0
    def _read_dig_montage(
        hsp=None, hpi=None, elp=None, point_names=None, unit='auto',
        fif=None, egi=None, bvct=None, transform=True, dev_head_t=False,
    ):
        """Unfolds the `read_dig_montage` old behavior of the call below.

        montage = read_dig_montage(hsp, hpi, elp, names,
                                   transform=True, dev_head_t=False)
        """
        assert isinstance(hsp, str), 'original call hsp was string'
        assert op.splitext(hpi)[-1] == '.sqd', 'original call hpi was .sqd'
        assert isinstance(elp, str), 'original call elp was string'

        hsp = _read_dig_points(hsp, unit=unit)
        hpi = read_mrk(hpi)
        elp = _read_dig_points(elp, unit=unit)

        data = Bunch(nasion=None, lpa=None, rpa=None,
                     hsp=hsp, hpi=hpi, elp=elp, coord_frame='unknown',
                     point_names=point_names, dig_ch_pos=None)

        data = _fix_data_fiducials(data)
        data = _transform_to_head_call(data)
        with pytest.deprecated_call():
            montage = DigMontage(**data)

        return montage
Example #4
0
def test_get_montage_info_with_ch_type():
    """Test that the channel types are properly returned."""
    mat = pymatreader.read_mat(raw_fname_onefile_mat, uint16_codec=None)
    n = len(mat['EEG']['chanlocs']['labels'])
    mat['EEG']['chanlocs']['type'] = ['eeg'] * (n - 2) + ['eog'] + ['stim']
    mat['EEG']['chanlocs'] = _dol_to_lod(mat['EEG']['chanlocs'])
    mat['EEG'] = Bunch(**mat['EEG'])
    ch_names, ch_types, montage = _get_montage_information(mat['EEG'], False)
    assert len(ch_names) == len(ch_types) == n
    assert ch_types == ['eeg'] * (n - 2) + ['eog'] + ['stim']
    assert montage is None

    # test unknown type warning
    mat = pymatreader.read_mat(raw_fname_onefile_mat, uint16_codec=None)
    n = len(mat['EEG']['chanlocs']['labels'])
    mat['EEG']['chanlocs']['type'] = ['eeg'] * (n - 2) + ['eog'] + ['unknown']
    mat['EEG']['chanlocs'] = _dol_to_lod(mat['EEG']['chanlocs'])
    mat['EEG'] = Bunch(**mat['EEG'])
    with pytest.warns(RuntimeWarning, match='Unknown types found'):
        ch_names, ch_types, montage = \
            _get_montage_information(mat['EEG'], False)
Example #5
0
def test_scraper(tmpdir):
    """Test report scraping."""
    r = Report()
    fig1, fig2 = _get_example_figures()
    r.add_figs_to_section(fig1, 'a', 'mysection')
    r.add_figs_to_section(fig2, 'b', 'mysection')
    # Mock a Sphinx + sphinx_gallery config
    app = Bunch(builder=Bunch(srcdir=str(tmpdir),
                              outdir=op.join(str(tmpdir), '_build', 'html')))
    scraper = _ReportScraper()
    scraper.app = app
    gallery_conf = dict(src_dir=app.builder.srcdir, builder_name='html')
    img_fname = op.join(app.builder.srcdir, 'auto_examples', 'images',
                        'sg_img.png')
    target_file = op.join(app.builder.srcdir, 'auto_examples', 'sg.py')
    os.makedirs(op.dirname(img_fname))
    os.makedirs(app.builder.outdir)
    block_vars = dict(image_path_iterator=(img for img in [img_fname]),
                      example_globals=dict(a=1),
                      target_file=target_file)
    # Nothing yet
    block = None
    rst = scraper(block, block_vars, gallery_conf)
    assert rst == ''
    # Still nothing
    block_vars['example_globals']['r'] = r
    rst = scraper(block, block_vars, gallery_conf)
    # Once it's saved, add it
    assert rst == ''
    fname = op.join(str(tmpdir), 'my_html.html')
    r.save(fname, open_browser=False)
    rst = scraper(block, block_vars, gallery_conf)
    out_html = op.join(app.builder.outdir, 'auto_examples', 'my_html.html')
    assert not op.isfile(out_html)
    os.makedirs(op.join(app.builder.outdir, 'auto_examples'))
    scraper.copyfiles()
    assert op.isfile(out_html)
    assert rst.count('"') == 6
    assert "<iframe" in rst
    assert op.isfile(img_fname.replace('png', 'svg'))