def test_json(self): """Simple test of the serialized JSON content of a metric.""" name = 'T1' description = 'Test' unit = u.mag reference_doc = 'TEST-1' reference_page = 1 reference_url = 'example.com' m = Metric(name, description, unit, tags=['tagA', 'tagB'], reference_doc=reference_doc, reference_url=reference_url, reference_page=reference_page) j = m.json self.assertEqual(j['name'], name) self.assertEqual(j['description'], description) self.assertEqual(j['unit'], unit) self.assertEqual(j['reference']['doc'], reference_doc) self.assertEqual(j['reference']['page'], reference_page) self.assertEqual(j['reference']['url'], reference_url) self.assertIn('tagA', j['tags']) self.assertIn('tagB', j['tags']) self.assertNotIn('tagC', j['tags']) # rebuild from json m2 = Metric.deserialize(**j) self.assertEqual(m, m2)
def test_load_all_yaml_metrics(self): """Verify that all metrics from testing.yaml can be loaded.""" for metric_name in self.metric_doc: m = Metric.deserialize(metric_name, **self.metric_doc[metric_name]) self.assertIsInstance(m, Metric)