Skip to content

Commit

Permalink
Merge pull request #1056 from duncanmmacleod/gwf-errors
Browse files Browse the repository at this point in the history
Added tests for frameCPP errors and fixed a bug
  • Loading branch information
Duncan Macleod committed Feb 25, 2019
2 parents e1e37d4 + 9394e5e commit 83e1429
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gwpy/timeseries/io/gwf/framecpp.py
Expand Up @@ -47,7 +47,7 @@
r'0 through (?P<nframes>\d+)\Z',
)
FRERR_NO_CHANNEL_OF_TYPE = re.compile(
r'\ANo Fr(Adc|Proc|Sim)Data structures with the name (?P<channel>\S+)\Z',
r'\ANo Fr(Adc|Proc|Sim)Data structures with the name ',
)

# get frameCPP type mapping
Expand Down Expand Up @@ -261,7 +261,7 @@ def _get_frdata(stream, num, name, ctype=None):
if FRERR_NO_CHANNEL_OF_TYPE.match(str(exc)):
continue
raise
raise ValueError("no Fr{Adc,Proc,Sim}Data structures with the "
raise ValueError("no Fr{{Adc,Proc,Sim}}Data structures with the "
"name {0}".format(name))


Expand Down
24 changes: 24 additions & 0 deletions gwpy/timeseries/tests/test_timeseries.py
Expand Up @@ -219,6 +219,30 @@ def read_(**kwargs):
comb, array.append(a2, inplace=False),
exclude=['channel'])

@pytest.mark.parametrize('api', [
pytest.param(
'framecpp',
marks=utils.skip_missing_dependency('LDAStools.frameCPP')),
])
def test_read_write_gwf_error(self, api, losc):
with utils.TemporaryFilename(suffix=".gwf") as tmp:
losc.write(tmp, format="gwf.{}".format(api))
with pytest.raises(ValueError) as exc:
self.TEST_CLASS.read(tmp, "another channel",
format="gwf.{}".format(api))
assert str(exc.value) == (
"no Fr{Adc,Proc,Sim}Data structures with the "
"name another channel"
)

with pytest.raises(ValueError) as exc:
self.TEST_CLASS.read(tmp, losc.name,
start=losc.span[0]-1, end=losc.span[0],
format="gwf.{}".format(api))
assert str(exc.value).startswith(
"Failed to read {0!r} from {1!r}".format(losc.name, tmp)
)

@pytest.mark.parametrize('ext', ('hdf5', 'h5'))
@pytest.mark.parametrize('channel', [
None,
Expand Down

0 comments on commit 83e1429

Please sign in to comment.