def test_returns_stored_annotations(self): from foundations_events.consumers.annotate import Annotate self.get_metrics_mock annotator = Annotate(self.redis) self._annotate_jobs(annotator, self.annotations, self.job_id) metrics = get_metrics_for_all_jobs(self.project_name) job_metrics = metrics[metrics["job_id"] == self.job_id] job_annotations = job_metrics[list(self.annotations_data_frame)] assert_frame_equal(self.annotations_data_frame, job_annotations)
def test_annotations_for_multiple_jobs_returns_annotations_for_multiple_jobs(self): from foundations_events.consumers.annotate import Annotate annotate = Annotate(self.redis) annotate.call({'job_id': self.job_id, 'key': self.key, 'value': self.value}, None, {}) annotate.call({'job_id': self.job_id_two, 'key': self.key_two, 'value': self.value_two}, None, {}) result_annotations = annotations_for_multiple_jobs(self.redis, [self.job_id, self.job_id_two]) expected_annotations = {self.job_id: {self.key: self.value}, self.job_id_two: {self.key_two: self.value_two}} self.assertEqual(expected_annotations, result_annotations)
def test_returns_stored_annotations_multiple_annotations(self): from foundations_events.consumers.annotate import Annotate import pandas self.get_metrics_mock annotator = Annotate(self.redis) self._annotate_jobs(annotator, self.annotations, self.job_id) self._annotate_jobs(annotator, self.annotations_two, self.job_id_two) metrics = get_metrics_for_all_jobs(self.project_name) job_annotations = metrics[list(self.annotations_data_frame)] expected_data_frame = pandas.concat( [self.annotations_data_frame, self.annotations_data_frame_two], ignore_index=True, ) assert_frame_equal(expected_data_frame, job_annotations)
def test_annotations_for_multiple_jobs_returns_annotations_for_single_job(self): from foundations_events.consumers.annotate import Annotate Annotate(self.redis).call({'job_id': self.job_id, 'key': self.key, 'value': self.value}, None, {}) self.assertEqual({self.job_id: {self.key: self.value}}, annotations_for_multiple_jobs(self.redis, [self.job_id]))
def test_job_annotations_returns_stored_annotations_for_single_job(self): from foundations_events.consumers.annotate import Annotate Annotate(self.redis).call({'job_id': self.job_id, 'key': self.key, 'value': self.value}, None, {}) self.assertEqual({self.key: self.value}, job_annotations(self.redis, self.job_id))
def consumer(self): from foundations_events.consumers.annotate import Annotate self.redis.flushall() return Annotate(self.redis)
def _add_consumers_for_job_annotations(redis): from foundations_events.consumers.annotate import Annotate annotation_consumer = Annotate(redis) _add_listener(annotation_consumer, 'job_tag')