Example #1
0
    def test_setters(self):
        data_set = DataSet()
        self.assertEqual('', data_set.name)
        self.assertIsInstance(data_set.time_stamp, datetime.datetime)
        self.assertIsNone(data_set.user_data)
        self.assertEqual("", data_set.default_array_name)

        data_set.name = 'TheName'
        data_set.time_stamp = datetime.datetime(2018, 12, 24, 18)
        data_set.user_data = {'Data': 'stuff'}
        data_set.default_array_name = 'TheDefault'

        self.assertEqual('TheName', data_set.name)
        self.assertEqual(datetime.datetime(2018, 12, 24, 18),
                         data_set.time_stamp)
        self.assertDictEqual({'Data': 'stuff'}, data_set.user_data)
        self.assertEqual("TheDefault", data_set.default_array_name)
Example #2
0
    def test_save_to_storage(self):
        data_set = DataSet()
        data_set.name = 'TheName'
        data_set.time_stamp = datetime.datetime(2018, 12, 24, 18)
        data_set.user_data = {'Data': 'stuff'}
        data_set.default_array_name = 'TheDefault'
        data_set.add_array(self.data_array)

        writer = MagicMock()
        data_set.add_storage_writer(writer)

        expected_calls = [
            call.sync_metadata_to_storage('name', 'TheName'),
            call.sync_metadata_to_storage('time_stamp',
                                          datetime.datetime(2018, 12, 24, 18)),
            call.sync_metadata_to_storage('user_data', {'Data': 'stuff'}),
            call.sync_metadata_to_storage('default_array_name', 'TheDefault')
        ]
        writer.assert_has_calls(expected_calls)
        writer.sync_add_data_array_to_storage.assert_called()
Example #3
0
    def test_metadata_triggers_update(self):
        name = 'Bobo'
        user_data = PythonJsonStructure(data='plata', snapshot=False)
        timestamp = datetime.datetime(2019, 12, 24)
        default_array_name = 'ThatsAGoodName'

        io_reader, io_writer = MemoryDataSetIOFactory.get_reader_writer_pair()
        data_set_consumer = DataSet(storage_reader=io_reader)
        data_set_producer = DataSet(storage_writer=io_writer)

        data_set_producer.name = name
        data_set_producer.user_data = user_data
        data_set_producer.time_stamp = timestamp
        data_set_producer.default_array_name = default_array_name

        data_set_consumer.sync_from_storage(-1)

        self.assertEqual(name, data_set_consumer.name)
        self.assertDictEqual(user_data, data_set_consumer.user_data)
        self.assertEqual(timestamp, data_set_consumer.time_stamp)
        self.assertEqual(default_array_name,
                         data_set_consumer.default_array_name)