Пример #1
0
    def test_to_server(self, gdm_mock):
        mock_dm = MockDataManager()
        mock_dm.needs_restart = True
        gdm_mock.return_value = mock_dm

        data = DataSet(location='Venus',
                       data_manager=True,
                       mode=DataMode.PUSH_TO_SERVER)
        self.assertEqual(mock_dm.needs_restart, False, data)
        self.assertEqual(mock_dm.data_set, data)
        self.assertEqual(data.data_manager, mock_dm)
        self.assertEqual(data.mode, DataMode.PUSH_TO_SERVER)

        # cannot write except in LOCAL mode
        with self.assertRaises(RuntimeError):
            data.write()

        # now do what the DataServer does with this DataSet: init_on_server
        # fails until there is an array
        with self.assertRaises(RuntimeError):
            data.init_on_server()

        data.add_array(MockArray())
        data.init_on_server()
        self.assertEqual(data.noise.ready, True)

        # we can only add a given array_id once
        with self.assertRaises(ValueError):
            data.add_array(MockArray())
Пример #2
0
    def test_from_server(self, gdm_mock):
        mock_dm = MockDataManager()
        gdm_mock.return_value = mock_dm
        mock_dm.location = 'Mars'
        mock_dm.live_data = MockLive()

        # wrong location or False location - converts to local
        data = DataSet(location='Jupiter',
                       data_manager=True,
                       mode=DataMode.PULL_FROM_SERVER)
        self.assertEqual(data.mode, DataMode.LOCAL)

        data = DataSet(location=False,
                       data_manager=True,
                       mode=DataMode.PULL_FROM_SERVER)
        self.assertEqual(data.mode, DataMode.LOCAL)

        # location matching server - stays in server mode
        data = DataSet(location='Mars',
                       data_manager=True,
                       mode=DataMode.PULL_FROM_SERVER,
                       formatter=MockFormatter())
        self.assertEqual(data.mode, DataMode.PULL_FROM_SERVER)
        self.assertEqual(data.arrays, MockLive.arrays)

        # cannot write except in LOCAL mode
        with self.assertRaises(RuntimeError):
            data.write()

        # cannot finalize in PULL_FROM_SERVER mode
        with self.assertRaises(RuntimeError):
            data.finalize()

        # now test when the server says it's not there anymore
        mock_dm.location = 'Saturn'
        data.sync()
        self.assertEqual(data.mode, DataMode.LOCAL)
        self.assertEqual(data.has_read_data, True)

        # now it's LOCAL so we *can* write.
        data.write()
        self.assertEqual(data.has_written_data, True)

        # location=False: write, read and sync are noops.
        data.has_read_data = False
        data.has_written_data = False
        data.location = False
        data.write()
        data.read()
        data.sync()
        self.assertEqual(data.has_read_data, False)
        self.assertEqual(data.has_written_data, False)