Пример #1
0
    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])
Пример #2
0
    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])
Пример #3
0
    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]))
Пример #4
0
    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])
Пример #5
0
    def test_add_two_parameters(self):
        dataset = Dataset(
                self.session,
                "Foo Name",
                title=self._TITLE,
                create=True,
                independents=self._INDEPENDENTS,
                dependents=self._DEPENDENTS)

        dataset.param_listeners.add('listener')
        dataset.addParameters([('param 2', 'data 2'), ('param 3', 'data 3')])
        self.hub.onNewParameter.assert_called_with(None, set(['listener']))
        self.assertEqual(['param 2', 'param 3'], dataset.getParamNames())
        self.assertEqual('data 2', dataset.getParameter('param 2'))
        self.assertEqual('data 3', dataset.getParameter('param 3'))
Пример #6
0
    def test_init_create_simple(self):
        dataset = Dataset(self.session,
                          "Foo Name",
                          title=self._TITLE,
                          create=True,
                          independents=self._INDEPENDENTS,
                          dependents=self._DEPENDENTS)

        self.assertEqual('2.0.0', dataset.version())

        self.assertEqual('*(v[mA],v[Ghz],v[V])', dataset.getRowType())
        self.assertEqual('(*v[mA],*v[Ghz],*v[V])', dataset.getTransposeType())

        # Check dependents added correctly
        dependents = dataset.getDependents()
        self.assertEqual(len(self._DEPENDENTS), len(dependents))
        self.assertEqual(self._DEPENDENTS[0][0], dependents[0].label)
        self.assertEqual(self._DEPENDENTS[0][1], dependents[0].legend)
        self.assertEqual(self._DEPENDENTS[0][2], dependents[0].unit)

        # Check independents added correctly
        independents = dataset.getIndependents()
        self.assertEqual(len(self._INDEPENDENTS), len(independents))
        self.assertEqual(self._INDEPENDENTS[0][0], independents[0].label)
        self.assertEqual(self._INDEPENDENTS[0][1], independents[0].unit)
        self.assertEqual(self._INDEPENDENTS[1][0], independents[1].label)
        self.assertEqual(self._INDEPENDENTS[1][1], independents[1].unit)
Пример #7
0
    def test_add_comment(self):
        dataset = Dataset(
                self.session,
                "Foo Name",
                title=self._TITLE,
                create=True,
                independents=self._INDEPENDENTS,
                dependents=self._DEPENDENTS)

        dataset.comment_listeners.add('listener')
        dataset.addComment('user 1', 'comment 1')

        self.hub.onCommentsAvailable.assert_called_with(None, set(['listener']))

        retreived_comment, count = dataset.getComments(None, 0)
        self.assertEqual(1, count)
        self.assertEqual('user 1', retreived_comment[0][1])
        self.assertEqual('comment 1', retreived_comment[0][2])
Пример #8
0
    def test_add_comment(self):
        dataset = Dataset(self.session,
                          "Foo Name",
                          title=self._TITLE,
                          create=True,
                          independents=self._INDEPENDENTS,
                          dependents=self._DEPENDENTS)

        dataset.comment_listeners.add('listener')
        dataset.addComment('user 1', 'comment 1')

        self.hub.onCommentsAvailable.assert_called_with(
            None, set(['listener']))

        retreived_comment, count = dataset.getComments(None, 0)
        self.assertEqual(1, count)
        self.assertEqual('user 1', retreived_comment[0][1])
        self.assertEqual('comment 1', retreived_comment[0][2])
Пример #9
0
    def test_init_create_simple(self):
        dataset = Dataset(
                self.session,
                "Foo Name",
                title=self._TITLE,
                create=True,
                independents=self._INDEPENDENTS,
                dependents=self._DEPENDENTS)

        self.assertEqual('2.0.0', dataset.version())

        self.assertEqual('*(v[mA],v[Ghz],v[V])', dataset.getRowType())
        self.assertEqual('(*v[mA],*v[Ghz],*v[V])', dataset.getTransposeType())

        # Check dependents added correctly
        dependents = dataset.getDependents()
        self.assertEqual(len(self._DEPENDENTS), len(dependents))
        self.assertEqual(self._DEPENDENTS[0][0], dependents[0].label)
        self.assertEqual(self._DEPENDENTS[0][1], dependents[0].legend)
        self.assertEqual(self._DEPENDENTS[0][2], dependents[0].unit)

        # Check independents added correctly
        independents = dataset.getIndependents()
        self.assertEqual(len(self._INDEPENDENTS), len(independents))
        self.assertEqual(self._INDEPENDENTS[0][0], independents[0].label)
        self.assertEqual(self._INDEPENDENTS[0][1], independents[0].unit)
        self.assertEqual(self._INDEPENDENTS[1][0], independents[1].label)
        self.assertEqual(self._INDEPENDENTS[1][1], independents[1].unit)
Пример #10
0
    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])
Пример #11
0
    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])
Пример #12
0
    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]))
Пример #13
0
    def test_add_two_parameters(self):
        dataset = Dataset(self.session,
                          "Foo Name",
                          title=self._TITLE,
                          create=True,
                          independents=self._INDEPENDENTS,
                          dependents=self._DEPENDENTS)

        dataset.param_listeners.add('listener')
        dataset.addParameters([('param 2', 'data 2'), ('param 3', 'data 3')])
        self.hub.onNewParameter.assert_called_with(None, set(['listener']))
        self.assertEqual(['param 2', 'param 3'], dataset.getParamNames())
        self.assertEqual('data 2', dataset.getParameter('param 2'))
        self.assertEqual('data 3', dataset.getParameter('param 3'))
Пример #14
0
    def test_init_create_extended(self):
        dataset = Dataset(self.session,
                          "Foo Name",
                          title=self._TITLE,
                          create=True,
                          independents=self._EXT_INDEPENDENTS,
                          dependents=self._EXT_DEPENDENTS,
                          extended=True)

        self.assertEqual('3.0.0', dataset.version())

        self.assertEqual('*(v[ns],*2c[V]{2,2},*2i{3,2})', dataset.getRowType())
        self.assertEqual('(*v[ns],*3c[V]{N,2,2},*3i{N,3,2})',
                         dataset.getTransposeType())

        # Check dependents added correctly
        dependents = dataset.getDependents()
        self.assertEqual(len(self._DEPENDENTS), len(dependents))
        self.assertEqual(self._EXT_DEPENDENTS[0][0], dependents[0].label)
        self.assertEqual(self._EXT_DEPENDENTS[0][1], dependents[0].legend)
        self.assertArrayEqual(self._EXT_DEPENDENTS[0][2], dependents[0].shape)
        self.assertEqual(self._EXT_DEPENDENTS[0][3], dependents[0].datatype)
        self.assertEqual(self._EXT_DEPENDENTS[0][4], dependents[0].unit)

        # Check independents added correctly
        independents = dataset.getIndependents()
        self.assertEqual(len(self._INDEPENDENTS), len(independents))
        self.assertEqual(self._EXT_INDEPENDENTS[0][0], independents[0].label)
        self.assertArrayEqual(self._EXT_INDEPENDENTS[0][1],
                              independents[0].shape)
        self.assertEqual(self._EXT_INDEPENDENTS[0][2],
                         independents[0].datatype)
        self.assertEqual(self._EXT_INDEPENDENTS[0][3], independents[0].unit)

        self.assertEqual(self._EXT_INDEPENDENTS[1][0], independents[1].label)
        self.assertArrayEqual(self._EXT_INDEPENDENTS[1][1],
                              independents[1].shape)
        self.assertEqual(self._EXT_INDEPENDENTS[1][2],
                         independents[1].datatype)
        self.assertEqual(self._EXT_INDEPENDENTS[1][3], independents[1].unit)
Пример #15
0
    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])
Пример #16
0
    def test_init_create_extended(self):
        dataset = Dataset(
                self.session,
                "Foo Name",
                title=self._TITLE,
                create=True,
                independents=self._EXT_INDEPENDENTS,
                dependents=self._EXT_DEPENDENTS,
                extended=True)

        self.assertEqual('3.0.0', dataset.version())

        self.assertEqual('*(v[ns],*2c[V]{2,2},*2i{3,2})', dataset.getRowType())
        self.assertEqual('(*v[ns],*3c[V]{N,2,2},*3i{N,3,2})', dataset.getTransposeType())

        # Check dependents added correctly
        dependents = dataset.getDependents()
        self.assertEqual(len(self._DEPENDENTS), len(dependents))
        self.assertEqual(self._EXT_DEPENDENTS[0][0], dependents[0].label)
        self.assertEqual(self._EXT_DEPENDENTS[0][1], dependents[0].legend)
        self.assertArrayEqual(self._EXT_DEPENDENTS[0][2], dependents[0].shape)
        self.assertEqual(self._EXT_DEPENDENTS[0][3], dependents[0].datatype)
        self.assertEqual(self._EXT_DEPENDENTS[0][4], dependents[0].unit)

        # Check independents added correctly
        independents = dataset.getIndependents()
        self.assertEqual(len(self._INDEPENDENTS), len(independents))
        self.assertEqual(self._EXT_INDEPENDENTS[0][0], independents[0].label)
        self.assertArrayEqual(self._EXT_INDEPENDENTS[0][1], independents[0].shape)
        self.assertEqual(self._EXT_INDEPENDENTS[0][2], independents[0].datatype)
        self.assertEqual(self._EXT_INDEPENDENTS[0][3], independents[0].unit)

        self.assertEqual(self._EXT_INDEPENDENTS[1][0], independents[1].label)
        self.assertArrayEqual(self._EXT_INDEPENDENTS[1][1], independents[1].shape)
        self.assertEqual(self._EXT_INDEPENDENTS[1][2], independents[1].datatype)
        self.assertEqual(self._EXT_INDEPENDENTS[1][3], independents[1].unit)