def test_config_from_json_no_topic_name(self): """Tests that an error is raised when there is no topic name.""" cfg = [{ 'start': '2016-01-09T19:00:00', 'end': '2016-01-09T21:00:00', 'topic_id': 1 }] try: gendata.config_options_from_json(cfg) self.fail('Expected a ValueError') except ValueError: # expected pass
def test_config_from_json_topic_id_override(self): """Tests that topic ID overrides take precedence.""" cfg = [{ 'start': '2016-01-09T19:00:00', 'end': '2016-01-09T21:00:00', 'topic_id': 1, 'topic_name': 'Topic name' }] expected = GendataTestCase.default_data_options( datetime.datetime(2016, 1, 9, 19), datetime.datetime(2016, 1, 9, 21), 33, 'Topic name') actual = gendata.config_options_from_json(cfg, topic_id_override=33) self.assertEqual([expected], actual)
def test_config_from_json(self): """Tests that a valid config list is returned.""" cfg = [{ 'start': '2016-01-09T19:00:00', 'end': '2016-01-09T21:00:00', 'topic_id': 1, 'topic_name': 'Topic name' }] actual = gendata.config_options_from_json(cfg) opts = GendataTestCase.default_data_options( datetime.datetime(2016, 1, 9, 19), datetime.datetime(2016, 1, 9, 21), 1, 'Topic name') self.assertEqual([opts], actual)
def test_config_from_json_spread_override(self): """Tests that spread overrides take precedence.""" cfg = [{ 'start': '2016-01-09T19:00:00', 'end': '2016-01-09T21:00:00', 'topic_id': 1, 'topic_name': 'Topic name', 'spread': 0.1 }] expected = gendata.DataOptions(datetime.datetime(2016, 1, 9, 19), datetime.datetime(2016, 1, 9, 21), 1, 'Topic name', gendata.DEFAULT_SAMPLE_RATE, gendata.DEFAULT_PERIOD, gendata.DEFAULT_AMPLITUDE_COS, gendata.DEFAULT_AMPLITUDE_SIN, gendata.DEFAULT_AMPLITUDE_OFFSET, 0.33) actual = gendata.config_options_from_json(cfg, spread_override=0.33) self.assertEqual([expected], actual)
def test_config_from_json_empty(self): """Tests that an empty list is returned for empty configs.""" cfg = [] opts = gendata.config_options_from_json(cfg) self.assertEqual([], opts)