-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added integration tests for anomaly detector
- Loading branch information
Showing
5 changed files
with
166 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
lc_classification_step/tests/integration/test_step_anomaly.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import json | ||
import os | ||
from typing import Callable | ||
|
||
import pytest | ||
from apf.consumers import KafkaConsumer | ||
|
||
from lc_classification.core.step import LateClassifier | ||
from tests.test_commons import ( | ||
assert_command_is_correct, | ||
assert_ztf_object_is_correct, | ||
) | ||
|
||
|
||
@pytest.mark.ztf | ||
def test_step_anomaly_result( | ||
kafka_service, | ||
produce_messages, | ||
env_variables_anomaly, | ||
kafka_consumer: Callable[[str], KafkaConsumer], | ||
scribe_consumer: Callable[[], KafkaConsumer], | ||
): | ||
produce_messages("features_anomaly") | ||
env_variables_anomaly( | ||
"anomaly", | ||
"alerce_classifiers.anomaly.model.AnomalyDetector", | ||
{ | ||
"MODEL_PATH": os.getenv("TEST_ANOMALY_MODEL_PATH"), | ||
"FEATURE_QUANTILES_PATH": os.getenv( | ||
"TEST_ANOMALY_QUANTILES_PATH" | ||
), | ||
"MAPPER_CLASS": "alerce_classifiers.anomaly.mapper.AnomalyMapper", | ||
}, | ||
) | ||
|
||
from settings import config | ||
|
||
kconsumer = kafka_consumer("anomaly") | ||
sconsumer = scribe_consumer() | ||
|
||
step = LateClassifier(config=config()) | ||
step.start() | ||
|
||
for message in kconsumer.consume(): | ||
assert_ztf_object_is_correct(message) | ||
kconsumer.commit() | ||
|
||
for message in sconsumer.consume(): | ||
command = json.loads(message["payload"]) | ||
assert_command_is_correct(command) | ||
sconsumer.commit() | ||
|
||
|
||
@pytest.mark.ztf | ||
def test_step_anomaly_no_features_result( | ||
kafka_service, | ||
produce_messages, | ||
env_variables_anomaly, | ||
kafka_consumer: Callable[[str], KafkaConsumer], | ||
scribe_consumer: Callable[[], KafkaConsumer], | ||
): | ||
produce_messages("features_anomaly", force_missing_features=True) | ||
env_variables_anomaly( | ||
"anomaly", | ||
"alerce_classifiers.anomaly.model.AnomalyDetector", | ||
{ | ||
"MODEL_PATH": os.getenv("TEST_ANOMALY_MODEL_PATH"), | ||
"FEATURE_QUANTILES_PATH": os.getenv( | ||
"TEST_ANOMALY_QUANTILES_PATH" | ||
), | ||
"MAPPER_CLASS": "alerce_classifiers.anomaly.mapper.AnomalyMapper", | ||
}, | ||
) | ||
|
||
from settings import config | ||
|
||
kconsumer = kafka_consumer("anomaly") | ||
sconsumer = scribe_consumer() | ||
|
||
step = LateClassifier(config=config()) | ||
step.start() | ||
|
||
for message in kconsumer.consume(): | ||
assert_ztf_object_is_correct(message) | ||
kconsumer.commit() | ||
|
||
for message in sconsumer.consume(): | ||
command = json.loads(message["payload"]) | ||
assert_command_is_correct(command) | ||
sconsumer.commit() |