Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanDeveloper committed Oct 21, 2024
1 parent 242d77e commit ea1adf0
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/inspector/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 39 additions & 0 deletions tests/test_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
28 changes: 28 additions & 0 deletions tests/test_kafka_consume_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit ea1adf0

Please sign in to comment.