Exemplo n.º 1
0
    def test_clock(self):
        """Test clock integration."""

        clock = CountClock()
        clock.counter = 10  # ensures that clock gets reset.

        device = _MockConnector(data=self.mock_data,
                                device_spec=self.device_spec)
        daq = DataAcquisitionClient(connector=device,
                                    buffer_name='buffer_client_test_clock.db',
                                    raw_data_file_name=None,
                                    delete_archive=True,
                                    clock=clock)
        with daq:
            time.sleep(0.1)

        # Get all records from buffer
        data = daq.get_data()

        # NOTE: we can't make any assertions about the Clock, since it is
        # copied when it's passed to the acquisition thread.
        self.assertTrue(len(data) > 0)
        for i, record in enumerate(data):
            self.assertEqual(record.timestamp, float(i + 1))

        daq.cleanup()
Exemplo n.º 2
0
    def test_daq_with_no_buffer(self):
        """get_data should return an empty list if daq._buf is None
        data length should return 0
        """

        device = _MockConnector(data=self.mock_data,
                                device_spec=self.device_spec)
        daq = DataAcquisitionClient(connector=device,
                                    delete_archive=True,
                                    raw_data_file_name=None)
        daq.start_acquisition()
        time.sleep(0.1)
        daq.stop_acquisition()

        # Make sure we are able to stop the buffer process
        buf_temp = daq._buf

        daq._buf = None

        # test get_data
        data = daq.get_data()
        self.assertEqual(data, [])

        # test get_data_len
        data_length = daq.get_data_len()
        self.assertEqual(data_length, 0)

        # test offset
        offset = daq.offset
        self.assertEqual(offset, None)

        daq._buf = buf_temp
        daq.cleanup()
Exemplo n.º 3
0
    def test_get_data(self):
        """Data should be queryable."""

        device = _MockDevice(data=self.mock_data, channels=self.mock_channels)
        daq = DataAcquisitionClient(device=device,
                                    processor=NullProcessor())
        daq.start_acquisition()
        time.sleep(0.1)
        daq.stop_acquisition()

        # Get all records
        data = daq.get_data()
        self.assertTrue(
            len(data) > 0, "DataAcquisitionClient should have data.")
        for i, record in enumerate(data):
            self.assertEqual(record.data, self.mock_data[i])

        daq.cleanup()
Exemplo n.º 4
0
    def test_get_data(self):
        """Data should be queryable."""

        device = _MockConnector(data=self.mock_data,
                                device_spec=self.device_spec)
        daq = DataAcquisitionClient(connector=device,
                                    delete_archive=True,
                                    raw_data_file_name=None)
        daq.start_acquisition()
        time.sleep(0.1)
        daq.stop_acquisition()

        # Get all records
        data = daq.get_data()
        self.assertTrue(
            len(data) > 0, "DataAcquisitionClient should have data.")
        for i, record in enumerate(data):
            self.assertEqual(record.data, self.mock_data[i])

        daq.cleanup()
Exemplo n.º 5
0
    def test_clock(self):
        """Test clock integration."""

        clock = CountClock()
        clock.counter = 10  # ensures that clock gets reset.
        daq = DataAcquisitionClient(
            device=_MockDevice(data=self.mock_data,
                               channels=self.mock_channels),
            processor=NullProcessor(),
            buffer_name='buffer_client_test_clock.db',
            clock=clock)
        with daq:
            time.sleep(0.1)

        # Get all records from buffer
        data = daq.get_data()

        # NOTE: we can't make any assertions about the Clock, since it is
        # copied when it's passed to the acquisition thread.
        self.assertTrue(len(data) > 0)
        for i, record in enumerate(data):
            self.assertEqual(record.timestamp, float(i + 1))

        daq.cleanup()