Skip to content

Commit

Permalink
FIX: Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Sep 1, 2017
1 parent 00d3ce8 commit 1db8760
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies:
- nose
- pytest
- pytest-cov
- pytest-sugar
- sphinx_bootstrap_theme
- numpydoc
- sphinx-gallery
Expand Down
2 changes: 1 addition & 1 deletion mne/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .open import fiff_open, show_fiff, _fiff_get_fid
from .meas_info import (read_fiducials, write_fiducials, read_info, write_info,
_empty_info, _merge_info, _force_update_info, Info,
anonymize_info)
anonymize_info, _stamp_to_dt)

from .proj import make_eeg_average_ref_proj, Projection
from .tag import _loc_to_coil_trans, _coil_trans_to_loc, _loc_to_eeg_loc
Expand Down
16 changes: 13 additions & 3 deletions mne/io/meas_info.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Authors: Alexandre Gramfort <[email protected]>
# Matti Hamalainen <[email protected]>
# Teon Brooks <[email protected]>
Expand All @@ -6,7 +7,7 @@

from collections import Counter
from copy import deepcopy
from datetime import datetime as dt
import datetime
import os.path as op
import re

Expand Down Expand Up @@ -55,6 +56,15 @@ def _summarize_str(st):
return st[:56][::-1].split(',', 1)[-1][::-1] + ', ...'


def _stamp_to_dt(stamp):
"""Convert timestamp to datetime object in Windows-friendly way."""
# The min on windows is 86400
stamp = np.array(stamp, int) # usually comes as int32
assert stamp.shape == (2,)
return (datetime.datetime.utcfromtimestamp(stamp[0]) +
datetime.timedelta(0, 0, stamp[1])) # day, sec, μs


# XXX Eventually this should be de-duplicated with the MNE-MATLAB stuff...
class Info(dict):
"""Measurement information.
Expand Down Expand Up @@ -398,7 +408,7 @@ def __repr__(self):
entr = _summarize_str(entr)
elif k == 'meas_date' and np.iterable(v):
# first entry in meas_date is meaningful
entr = dt.fromtimestamp(v[0]).strftime('%Y-%m-%d %H:%M:%S')
entr = _stamp_to_dt(v).strftime('%Y-%m-%d %H:%M:%S') + ' GMT'
elif k == 'kit_system_id' and v is not None:
from .kit.constants import SYSNAMES as KIT_SYSNAMES
entr = '%i (%s)' % (v, KIT_SYSNAMES.get(v, 'unknown'))
Expand Down Expand Up @@ -675,7 +685,7 @@ def _write_dig_points(fname, dig_points):
if ext == '.txt':
with open(fname, 'wb') as fid:
version = __version__
now = dt.now().strftime("%I:%M%p on %B %d, %Y")
now = datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y")
fid.write(b("% Ascii 3D points file created by mne-python version "
"{version} at {now}\n".format(version=version,
now=now)))
Expand Down
2 changes: 1 addition & 1 deletion mne/io/tests/test_meas_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_info():
info_str = '%s' % obj.info
assert_equal(len(info_str.split('\n')), len(obj.info.keys()) + 2)
assert_true(all(k in info_str for k in obj.info.keys()))
assert '2002-12-03 14:01:10' in repr(obj.info)
assert '2002-12-03 19:01:10 GMT' in repr(obj.info), repr(obj.info)

# Test read-only fields
info = raw.info.copy()
Expand Down
5 changes: 2 additions & 3 deletions mne/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
import time
from glob import glob
import base64
from datetime import datetime as dt

import numpy as np

from . import read_evokeds, read_events, pick_types, read_cov
from .io import Raw, read_info
from .io import Raw, read_info, _stamp_to_dt
from .utils import (_TempDir, logger, verbose, get_subjects_dir, warn,
_import_mlab)
from .viz import plot_events, plot_alignment, plot_cov
Expand Down Expand Up @@ -1570,7 +1569,7 @@ def _render_raw(self, raw_fname):
ecg = 'Not available'
meas_date = raw.info['meas_date']
if meas_date is not None:
meas_date = dt.fromtimestamp(meas_date[0]).strftime("%B %d, %Y")
meas_date = _stamp_to_dt(meas_date).strftime("%B %d, %Y") + ' GMT'
tmin = raw.first_samp / raw.info['sfreq']
tmax = raw.last_samp / raw.info['sfreq']

Expand Down
12 changes: 7 additions & 5 deletions mne/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,9 +783,10 @@ def has_freesurfer():

def requires_nibabel(vox2ras_tkr=False):
"""Check for nibabel."""
import pytest
extra = ' with vox2ras_tkr support' if vox2ras_tkr else ''
return np.testing.dec.skipif(not has_nibabel(vox2ras_tkr),
'Requires nibabel%s' % extra)
return pytest.mark.skipif(not has_nibabel(vox2ras_tkr),
reason='Requires nibabel%s' % extra)


def buggy_mkl_svd(function):
Expand All @@ -805,9 +806,10 @@ def dec(*args, **kwargs):

def requires_version(library, min_version):
"""Check for a library version."""
return np.testing.dec.skipif(not check_version(library, min_version),
'Requires %s version >= %s'
% (library, min_version))
import pytest
return pytest.mark.skipif(not check_version(library, min_version),
reason=('Requires %s version >= %s'
% (library, min_version)))


def requires_module(function, name, call=None):
Expand Down

0 comments on commit 1db8760

Please sign in to comment.