Skip to content

Commit

Permalink
FIX: More comprehensive tests
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Nov 24, 2020
1 parent a372544 commit df49ea6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
1 change: 0 additions & 1 deletion mne/io/edf/edf.py
Expand Up @@ -569,7 +569,6 @@ def _read_edf_header(fname, exclude):
try:
meas_date = datetime(year, month, day, hour, minute, sec,
tzinfo=timezone.utc)
print(meas_date)
except ValueError:
warn(f'Invalid date encountered ({year:04d}-{month:02d}-'
f'{day:02d} {hour:02d}:{minute:02d}:{sec:02d}).')
Expand Down
28 changes: 22 additions & 6 deletions mne/io/edf/tests/test_edf.py
Expand Up @@ -414,30 +414,46 @@ def test_edf_annot_sub_s_onset():

def test_invalid_date(tmpdir):
"""Test handling of invalid date in EDF header."""
tempdir = str(tmpdir)
with open(edf_path, 'rb') as f: # read valid test file
edf = bytearray(f.read())

# original date in header is 29.04.14 (2014-04-29) at pos 168:176
# but we also use Startdate if available,
# which starts at byte 88 and is b'Startdate 29-APR-2014 X X X'
# create invalid date 29.02.14 (2014 is not a leap year)

# one wrong: no warning
edf[101:104] = b'FEB'
assert edf[172] == ord('4')
fname = op.join(str(tmpdir), "temp.edf")
with open(fname, "wb") as f:
f.write(edf)
read_raw_edf(fname)

# other wrong: no warning
edf[101:104] = b'APR'
edf[172] = ord('2')
with open(fname, "wb") as f:
f.write(edf)
read_raw_edf(fname)

# both wrong: warning
edf[101:104] = b'FEB'
edf[172] = ord('2')
with open(op.join(tempdir, "temp.edf"), "wb") as f:
with open(fname, "wb") as f:
f.write(edf)
with pytest.warns(RuntimeWarning, match='Invalid date'):
read_raw_edf(op.join(tempdir, "temp.edf"), preload=True)
read_raw_edf(fname)

# another invalid date 29.00.14 (0 is not a month)
assert edf[101:104] == b'FEB'
edf[172] = ord('0')
with open(op.join(tempdir, "temp.edf"), "wb") as f:
with open(fname, "wb") as f:
f.write(edf)
with pytest.warns(RuntimeWarning, match='Invalid date'):
read_raw_edf(op.join(tempdir, "temp.edf"), preload=True)
read_raw_edf(fname)


def test_empty_chars():
"""Test blank char support."""
# from gitter
assert _edf_str_int(b'1819\x00 ') == 1819

0 comments on commit df49ea6

Please sign in to comment.