diff --git a/src/inspector/inspector.py b/src/inspector/inspector.py index fcd0bbf..a989743 100644 --- a/src/inspector/inspector.py +++ b/src/inspector/inspector.py @@ -385,7 +385,6 @@ def _inspect_univariate(self, model: str): self.X = self._count_errors( self.messages, self.begin_timestamp, self.end_timestamp ) - print(self.X.shape) ds = CustomDS(self.X, self.X) stream = StreamGenerator(ds.data) diff --git a/tests/test_inspector.py b/tests/test_inspector.py index eea0b71..37d49a7 100644 --- a/tests/test_inspector.py +++ b/tests/test_inspector.py @@ -479,6 +479,45 @@ def test_inspect_multivariate( sut.inspect() self.assertEqual([0, 0], sut.anomalies) + @patch("src.inspector.inspector.logger") + @patch("src.inspector.inspector.KafkaProduceHandler") + @patch("src.inspector.inspector.KafkaConsumeHandler") + @patch( + "src.inspector.inspector.MODELS", + [ + { + "model": "RShashDetector", + "module": "streamad.model", + "model_args": {"window_len": 10}, + } + ], + ) + @patch("src.inspector.inspector.MODE", "multivariate") + def test_inspect_multivariate_window_len( + self, mock_kafka_consume_handler, mock_produce_handler, mock_logger + ): + test_batch = get_batch(None) + test_batch.begin_timestamp = datetime.now() + test_batch.end_timestamp = datetime.now() + timedelta(0, 0, 2) + data = DEFAULT_DATA + data["timestamp"] = datetime.strftime( + test_batch.begin_timestamp + timedelta(0, 0, 1), TIMESTAMP_FORMAT + ) + test_batch.data = [data] + mock_kafka_consume_handler_instance = MagicMock() + mock_kafka_consume_handler.return_value = mock_kafka_consume_handler_instance + mock_kafka_consume_handler_instance.consume_and_return_object.return_value = ( + "test", + test_batch, + ) + mock_produce_handler_instance = MagicMock() + mock_produce_handler.return_value = mock_produce_handler_instance + + sut = Inspector() + sut.get_and_fill_data() + sut.inspect() + self.assertNotEqual([None, None], sut.anomalies) + @patch("src.inspector.inspector.logger") @patch("src.inspector.inspector.KafkaProduceHandler") @patch("src.inspector.inspector.KafkaConsumeHandler") diff --git a/tests/test_kafka_consume_handler.py b/tests/test_kafka_consume_handler.py index c4d69a6..a94ddcc 100644 --- a/tests/test_kafka_consume_handler.py +++ b/tests/test_kafka_consume_handler.py @@ -157,5 +157,33 @@ def test_del_with_existing_consumer(self, mock_consumer): mock_consumer_instance.close.assert_not_called() +class TestDict(unittest.TestCase): + @patch("src.base.kafka_handler.CONSUMER_GROUP_ID", "test_group_id") + @patch( + "src.base.kafka_handler.KAFKA_BROKERS", + [ + { + "hostname": "127.0.0.1", + "port": 9999, + }, + { + "hostname": "127.0.0.2", + "port": 9998, + }, + { + "hostname": "127.0.0.3", + "port": 9997, + }, + ], + ) + @patch("src.base.kafka_handler.Consumer") + def test_dict(self, mock_consumer): + mock_consumer_instance = MagicMock() + mock_consumer.return_value = mock_consumer_instance + + sut = KafkaConsumeHandler(topic="test_topic") + self.assertTrue(sut._is_dicts([{}, {}])) + + if __name__ == "__main__": unittest.main()