def test_keep_streaming(self): dataset = Dataset( self.session, "Foo Name", title=self._TITLE, create=True, independents=self._INDEPENDENTS, dependents=self._DEPENDENTS) data = self._get_records_simple([(1, 2, 3)], dataset.data.dtype) dataset.addData(data) listener = 'listener' # Start streaming the listener dataset.keepStreaming(listener, 0) # Check the listener is notified of the data already available self.hub.onDataAvailable.assert_called_with(None, [listener]) self.hub.reset_mock() # Keep streaming for more data added dataset.keepStreaming(listener, 1) # Add more data. dataset.addData(data) # Trigger the listener again. self.hub.onDataAvailable.assert_called_with(None, set([listener]))
def test_add_data_extended(self): dataset = Dataset( self.session, "Foo Name", title=self._TITLE, create=True, independents=self._EXT_INDEPENDENTS, dependents=self._EXT_DEPENDENTS, extended=True) dataset.listeners.add('foo listener') row_1 = (1, [[0, 1], [1, 0]], [[0, 1], [2, 3], [4, 5]]) row_2 = (2, [[1, 0], [1, 0]], [[6, 7], [8, 3], [2, 1]]) data = self._get_records_extended([row_1, row_2], dataset.data.dtype) # Add the data. dataset.addData(data) self.hub.onDataAvailable.assert_called_with(None, set(['foo listener'])) data_in_dataset, count = dataset.getData(None, 0, simpleOnly=False) self.assertEqual(count, 2) self.assertArrayEqual(row_1[0], data_in_dataset[0][0]) self.assertArrayEqual(row_1[1], data_in_dataset[0][1]) self.assertArrayEqual(row_1[2], data_in_dataset[0][2]) self.assertArrayEqual(row_2[0], data_in_dataset[1][0]) self.assertArrayEqual(row_2[1], data_in_dataset[1][1]) self.assertArrayEqual(row_2[2], data_in_dataset[1][2])
def test_save_reload_data_extended(self): # Set up the dataset dataset = Dataset(self.session, "Foo Name", title=self._TITLE, create=True, independents=self._EXT_INDEPENDENTS, dependents=self._EXT_DEPENDENTS, extended=True) dataset.listeners.add('foo listener') row_1 = (1, [[0, 1], [1, 0]], [[0, 1], [2, 3], [4, 5]]) row_2 = (2, [[1, 0], [1, 0]], [[6, 7], [8, 3], [2, 1]]) data = self._get_records_extended([row_1, row_2], dataset.data.dtype) # Add the data. dataset.addData(data) # Save the dataset dataset.save() # Create a new dataset that loads the data. new_dataset = Dataset(self.session, "Foo Name", title=self._TITLE, extended=True) data_in_dataset, count = new_dataset.getData(None, 0, simpleOnly=False) self.assertEqual(count, 2) self.assertArrayEqual(row_1[0], data_in_dataset[0][0]) self.assertArrayEqual(row_1[1], data_in_dataset[0][1]) self.assertArrayEqual(row_1[2], data_in_dataset[0][2]) self.assertArrayEqual(row_2[0], data_in_dataset[1][0]) self.assertArrayEqual(row_2[1], data_in_dataset[1][1]) self.assertArrayEqual(row_2[2], data_in_dataset[1][2])
def test_add_data_extended(self): dataset = Dataset(self.session, "Foo Name", title=self._TITLE, create=True, independents=self._EXT_INDEPENDENTS, dependents=self._EXT_DEPENDENTS, extended=True) dataset.listeners.add('foo listener') row_1 = (1, [[0, 1], [1, 0]], [[0, 1], [2, 3], [4, 5]]) row_2 = (2, [[1, 0], [1, 0]], [[6, 7], [8, 3], [2, 1]]) data = self._get_records_extended([row_1, row_2], dataset.data.dtype) # Add the data. dataset.addData(data) self.hub.onDataAvailable.assert_called_with(None, set(['foo listener'])) data_in_dataset, count = dataset.getData(None, 0, simpleOnly=False) self.assertEqual(count, 2) self.assertArrayEqual(row_1[0], data_in_dataset[0][0]) self.assertArrayEqual(row_1[1], data_in_dataset[0][1]) self.assertArrayEqual(row_1[2], data_in_dataset[0][2]) self.assertArrayEqual(row_2[0], data_in_dataset[1][0]) self.assertArrayEqual(row_2[1], data_in_dataset[1][1]) self.assertArrayEqual(row_2[2], data_in_dataset[1][2])
def test_add_data_simple(self): dataset = Dataset( self.session, "Foo Name", title=self._TITLE, create=True, independents=self._INDEPENDENTS, dependents=self._DEPENDENTS) dataset.listeners.add('foo listener') data = self._get_records_simple( [(1, 2, 3), (2, 3, 4)], dataset.data.dtype) # Add the data. dataset.addData(data) self.hub.onDataAvailable.assert_called_with(None, set(['foo listener'])) data_in_dataset, count = dataset.getData(None, 0, simpleOnly=True) self.assertEqual(count, 2) self.assertArrayEqual([1, 2, 3], data_in_dataset[0]) self.assertArrayEqual([2, 3, 4], data_in_dataset[1])
def test_add_data_simple(self): dataset = Dataset(self.session, "Foo Name", title=self._TITLE, create=True, independents=self._INDEPENDENTS, dependents=self._DEPENDENTS) dataset.listeners.add('foo listener') data = self._get_records_simple([(1, 2, 3), (2, 3, 4)], dataset.data.dtype) # Add the data. dataset.addData(data) self.hub.onDataAvailable.assert_called_with(None, set(['foo listener'])) data_in_dataset, count = dataset.getData(None, 0, simpleOnly=True) self.assertEqual(count, 2) self.assertArrayEqual([1, 2, 3], data_in_dataset[0]) self.assertArrayEqual([2, 3, 4], data_in_dataset[1])
def test_save_reload_data_extended(self): # Set up the dataset dataset = Dataset( self.session, "Foo Name", title=self._TITLE, create=True, independents=self._EXT_INDEPENDENTS, dependents=self._EXT_DEPENDENTS, extended=True) dataset.listeners.add('foo listener') row_1 = (1, [[0, 1], [1, 0]], [[0, 1], [2, 3], [4, 5]]) row_2 = (2, [[1, 0], [1, 0]], [[6, 7], [8, 3], [2, 1]]) data = self._get_records_extended([row_1, row_2], dataset.data.dtype) # Add the data. dataset.addData(data) # Save the dataset dataset.save() # Create a new dataset that loads the data. new_dataset = Dataset( self.session, "Foo Name", title=self._TITLE, extended=True) data_in_dataset, count = new_dataset.getData(None, 0, simpleOnly=False) self.assertEqual(count, 2) self.assertArrayEqual(row_1[0], data_in_dataset[0][0]) self.assertArrayEqual(row_1[1], data_in_dataset[0][1]) self.assertArrayEqual(row_1[2], data_in_dataset[0][2]) self.assertArrayEqual(row_2[0], data_in_dataset[1][0]) self.assertArrayEqual(row_2[1], data_in_dataset[1][1]) self.assertArrayEqual(row_2[2], data_in_dataset[1][2])
def test_keep_streaming(self): dataset = Dataset(self.session, "Foo Name", title=self._TITLE, create=True, independents=self._INDEPENDENTS, dependents=self._DEPENDENTS) data = self._get_records_simple([(1, 2, 3)], dataset.data.dtype) dataset.addData(data) listener = 'listener' # Start streaming the listener dataset.keepStreaming(listener, 0) # Check the listener is notified of the data already available self.hub.onDataAvailable.assert_called_with(None, [listener]) self.hub.reset_mock() # Keep streaming for more data added dataset.keepStreaming(listener, 1) # Add more data. dataset.addData(data) # Trigger the listener again. self.hub.onDataAvailable.assert_called_with(None, set([listener]))