From 1db87601617c41b3c4ff6dd3821c158122b66c70 Mon Sep 17 00:00:00 2001 From: Eric Larson Date: Fri, 1 Sep 2017 15:28:07 -0400 Subject: [PATCH] FIX: Fix tests --- environment.yml | 1 + mne/io/__init__.py | 2 +- mne/io/meas_info.py | 16 +++++++++++++--- mne/io/tests/test_meas_info.py | 2 +- mne/report.py | 5 ++--- mne/utils.py | 12 +++++++----- 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/environment.yml b/environment.yml index 651baee9b44..a082161bc01 100644 --- a/environment.yml +++ b/environment.yml @@ -31,6 +31,7 @@ dependencies: - nose - pytest - pytest-cov + - pytest-sugar - sphinx_bootstrap_theme - numpydoc - sphinx-gallery diff --git a/mne/io/__init__.py b/mne/io/__init__.py index 62ad74d3fca..af8c1e33128 100644 --- a/mne/io/__init__.py +++ b/mne/io/__init__.py @@ -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 diff --git a/mne/io/meas_info.py b/mne/io/meas_info.py index 07638fd7e96..c3eb0b01ba7 100644 --- a/mne/io/meas_info.py +++ b/mne/io/meas_info.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Authors: Alexandre Gramfort # Matti Hamalainen # Teon Brooks @@ -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 @@ -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. @@ -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')) @@ -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))) diff --git a/mne/io/tests/test_meas_info.py b/mne/io/tests/test_meas_info.py index 435b2d2215d..9ab8b17b4a2 100644 --- a/mne/io/tests/test_meas_info.py +++ b/mne/io/tests/test_meas_info.py @@ -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() diff --git a/mne/report.py b/mne/report.py index 0f0983734df..2e445971ec1 100644 --- a/mne/report.py +++ b/mne/report.py @@ -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 @@ -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'] diff --git a/mne/utils.py b/mne/utils.py index 229ee176056..cca6bf17183 100644 --- a/mne/utils.py +++ b/mne/utils.py @@ -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): @@ -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):