From 9394e5ed8f447c4949a5e32d75343f86bc12570a Mon Sep 17 00:00:00 2001 From: Duncan Macleod Date: Mon, 25 Feb 2019 12:32:34 +0000 Subject: [PATCH] gwpy.timeseries: added tests for frameCPP errors and fixed bugs in error reporting --- gwpy/timeseries/io/gwf/framecpp.py | 4 ++-- gwpy/timeseries/tests/test_timeseries.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/gwpy/timeseries/io/gwf/framecpp.py b/gwpy/timeseries/io/gwf/framecpp.py index c8cdf66da..153962cf1 100644 --- a/gwpy/timeseries/io/gwf/framecpp.py +++ b/gwpy/timeseries/io/gwf/framecpp.py @@ -47,7 +47,7 @@ r'0 through (?P\d+)\Z', ) FRERR_NO_CHANNEL_OF_TYPE = re.compile( - r'\ANo Fr(Adc|Proc|Sim)Data structures with the name (?P\S+)\Z', + r'\ANo Fr(Adc|Proc|Sim)Data structures with the name ', ) # get frameCPP type mapping @@ -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)) diff --git a/gwpy/timeseries/tests/test_timeseries.py b/gwpy/timeseries/tests/test_timeseries.py index c837dd64c..fa8e2437b 100644 --- a/gwpy/timeseries/tests/test_timeseries.py +++ b/gwpy/timeseries/tests/test_timeseries.py @@ -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,