Skip to content
This repository has been archived by the owner on Jul 7, 2023. It is now read-only.

Commit

Permalink
added produce test with duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
dirodriguezm committed Dec 2, 2020
1 parent 0f72750 commit 455dc19
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
4 changes: 3 additions & 1 deletion features/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ def update_db(self, to_update, out_columns, apply_get_fid):
to_update.columns = out_columns
to_update["fid"] = to_update["name"].apply(apply_get_fid)
to_update["version"] = self.feature_version.version
to_update["name"] = to_update["name"].apply(lambda x: self.check_feature_name(x))
to_update["name"] = to_update["name"].apply(
lambda x: self.check_feature_name(x)
)
to_update.rename(
columns={
"oid": "_oid",
Expand Down
20 changes: 18 additions & 2 deletions tests/unittest/test_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ def test_check_feature_name(self):
@mock.patch.object(FeaturesComputer, "produce")
@mock.patch.object(FeaturesComputer, "add_to_db")
@mock.patch.object(FeaturesComputer, "insert_feature_version")
def test_execute_with_producer(self, insert_feature_version, add_to_db, produce, compute_features):
def test_execute_with_producer(
self, insert_feature_version, add_to_db, produce, compute_features
):
messages = [
{
"oid": "ZTF1",
Expand All @@ -290,7 +292,9 @@ def test_execute_with_producer(self, insert_feature_version, add_to_db, produce,
@mock.patch.object(FeaturesComputer, "produce")
@mock.patch.object(FeaturesComputer, "add_to_db")
@mock.patch.object(FeaturesComputer, "insert_feature_version")
def test_execute_duplicates(self, insert_feature_version, add_to_db, produce, compute_features):
def test_execute_duplicates(
self, insert_feature_version, add_to_db, produce, compute_features
):
message1 = {
"oid": "ZTF1",
"candid": 123,
Expand All @@ -314,3 +318,15 @@ def test_execute_duplicates(self, insert_feature_version, add_to_db, produce, co
mock_feature_version.version = self.step_config["FEATURE_VERSION"]
self.step.execute(messages)
produce.assert_called_once()

def test_produce(self):
alert_data = pd.DataFrame({"oid": ["OID", "OID"], "candid": [123, 123]})
features = pd.DataFrame({"oid": ["OID"], "feature1": 1, "feature2": 2})
features.set_index("oid", inplace=True)
self.step.produce(features, alert_data)
expected_message = {
"features": {"feature1": 1, "feature2": 2},
"oid": "OID",
"candid": 123,
}
self.step.producer.produce.assert_called_with(expected_message, key="OID")

0 comments on commit 455dc19

Please sign in to comment.