Beispiel #1
0
    def test_query_nds2_availability(self):
        # mock NDS2 query
        ndsb = mocks.nds2_buffer(self.NAMES[0], [], 0, 64, 'm')
        availability = [
            mocks.nds2_availability(self.NAMES[0], [(0, 10), (20, 30)]),
        ]
        conn = mocks.nds2_connection(buffers=[ndsb])
        conn.get_availability.return_value = availability
        with mock.patch('nds2.connection') as ndsc:
            ndsc.return_value = conn

            avail = self.TEST_CLASS.query_nds2_availability(
                [self.NAMES[0]], 0, 30, host='test')

            assert isinstance(avail, SegmentListDict)
            utils.assert_segmentlist_equal(avail[self.NAMES[0]],
                                           [(0, 10), (20, 30)])
Beispiel #2
0
 def test_from_nds2_buffer(self):
     nds_buffer = mocks.nds2_buffer('X1:TEST', self.data, 1000000000,
                                    self.data.shape[0], 'm')
     a = self.TEST_CLASS.from_nds2_buffer(nds_buffer)
     assert isinstance(a, self.TEST_CLASS)
     utils.assert_array_equal(a.value, self.data)
     assert a.unit == units.m
     assert a.t0 == 1000000000 * units.s
     assert a.dt == units.s / self.data.shape[0]
     assert a.name == 'X1:TEST'
     assert a.channel == Channel('X1:TEST',
                                 sample_rate=self.data.shape[0],
                                 unit='m',
                                 type='raw',
                                 dtype='float32')
     b = self.TEST_CLASS.from_nds2_buffer(nds_buffer, sample_rate=128)
     assert b.dt == 1 / 128. * units.s
Beispiel #3
0
    def test_query_nds2(self):
        # mock NDS2 query
        buffers = []
        for name, fs in zip(self.NAMES[:-1], self.SAMPLE_RATES[:-1]):
            buffers.append(mocks.nds2_buffer(name, [], 0, fs, 'm'))
        conn = mocks.nds2_connection(buffers=buffers)
        with mock.patch('nds2.connection') as ndsc:
            ndsc.return_value = conn

            # test query_nds2
            c = self.TEST_CLASS.query_nds2(self.NAMES[:-1], host='test')
            assert len(c) == len(self.NAMES) - 1
            assert c[0].name == self.NAMES[0]
            assert c[0].sample_rate == self.SAMPLE_RATES[0] * units.Hz

            # check errors
            assert len(
                self.TEST_CLASS.query_nds2([self.NAMES[-1]], host='test')) == 0
Beispiel #4
0
    def test_query_nds2(self):
        # mock NDS2 query
        buffers = []
        for name, fs in zip(self.NAMES[:-1], self.SAMPLE_RATES[:-1]):
            buffers.append(mocks.nds2_buffer(name, [], 0, fs, 'm'))
        conn = mocks.nds2_connection(buffers=buffers)
        with mock.patch('nds2.connection') as ndsc:
            ndsc.return_value = conn

            # test query_nds2
            c = self.TEST_CLASS.query_nds2(self.NAMES[:-1], host='test')
            assert len(c) == len(self.NAMES) - 1
            assert c[0].name == self.NAMES[0]
            assert c[0].sample_rate == self.SAMPLE_RATES[0] * units.Hz

            # check errors
            assert len(
                self.TEST_CLASS.query_nds2([self.NAMES[-1]], host='test')) == 0
Beispiel #5
0
    def test_query_nds2_availability(self):
        # mock NDS2 query
        ndsb = mocks.nds2_buffer(self.NAMES[0], [], 0, 64, 'm')
        availability = [
            mocks.nds2_availability(self.NAMES[0], [(0, 10), (20, 30)]),
        ]
        conn = mocks.nds2_connection(buffers=[ndsb])
        conn.get_availability.return_value = availability
        with mock.patch('nds2.connection') as ndsc:
            ndsc.return_value = conn

            avail = self.TEST_CLASS.query_nds2_availability([self.NAMES[0]],
                                                            0,
                                                            30,
                                                            host='test')

            assert isinstance(avail, SegmentListDict)
            utils.assert_segmentlist_equal(avail[self.NAMES[0]], [(0, 10),
                                                                  (20, 30)])
Beispiel #6
0
    def test_query_nds2(self, name):
        # mock NDS2 query
        ndsb = mocks.nds2_buffer('X1:TEST-CHANNEL', [], 0, 64, 'm')
        if ndsb.name == name:
            buffers = [ndsb]
        else:
            buffers = []
        conn = mocks.nds2_connection(buffers=buffers)
        with mock.patch('nds2.connection') as ndsc, \
                mock.patch('nds2.buffer', ndsb):
            ndsc.return_value = conn

            # test query_nds2
            if buffers:
                c = self.TEST_CLASS.query_nds2(name, host='test')
                assert c.name == name
                assert c.sample_rate == 64 * units.Hz
                assert c.unit == units.m
                assert c.dtype == numpy.dtype('float32')
                assert c.type == 'raw'
            else:
                with pytest.raises(ValueError):
                    c = self.TEST_CLASS.query_nds2(name, host='test')
Beispiel #7
0
    def test_query_nds2(self, name):
        # mock NDS2 query
        ndsb = mocks.nds2_buffer('X1:TEST-CHANNEL', [], 0, 64, 'm')
        if ndsb.name == name:
            buffers = [ndsb]
        else:
            buffers = []
        conn = mocks.nds2_connection(buffers=buffers)
        with mock.patch('nds2.connection') as ndsc, \
                mock.patch('nds2.buffer', ndsb):
            ndsc.return_value = conn

            # test query_nds2
            if buffers:
                c = self.TEST_CLASS.query_nds2(name, host='test')
                assert c.name == name
                assert c.sample_rate == 64 * units.Hz
                assert c.unit == units.m
                assert c.dtype == numpy.dtype('float32')
                assert c.type == 'raw'
            else:
                with pytest.raises(ValueError):
                    c = self.TEST_CLASS.query_nds2(name, host='test')