Skip to content

Commit

Permalink
chore: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
niliayu committed Oct 22, 2024
1 parent 6689a60 commit 37fb05f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 45 deletions.
9 changes: 1 addition & 8 deletions python/lib/sift_py/ingestion/config/telemetry.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import annotations

from loguru import logger
from pathlib import Path
from typing import Any, Dict, List, Optional, cast

from loguru import logger
from typing_extensions import Self

from sift_py.ingestion.channel import (
Expand Down Expand Up @@ -84,13 +84,6 @@ def validate_rules(rules: List[RuleConfig]):
)
seen_rule_names.add(rule.name)

# if rule.asset_names:
# logger.warning(
# f"Rule '{rule.name}' has an 'asset_names' field, which is not allowed when defining rules in a telemetry config."
# "Please remove the 'asset_names' field from the rule, or create the rule outside of telemetry config."
# "Proceeding, but the asset_names field will be ignored."
# )

@staticmethod
def validate_flows(flows: List[FlowConfig]):
"""
Expand Down
8 changes: 6 additions & 2 deletions python/lib/sift_py/ingestion/config/telemetry_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from loguru import logger
from pathlib import Path
from typing import Any, Dict, cast

import pytest
import yaml
from loguru import logger
from pytest_mock import MockerFixture, MockFixture

import sift_py.ingestion.config.telemetry
Expand All @@ -26,6 +26,7 @@

_mock_path = _mock_path_imp(sift_py.ingestion.config.telemetry)


@pytest.fixture
def caplog(caplog):
"""Needed to capture loguru logs per: https://github.com/Delgan/loguru/pull/572"""
Expand Down Expand Up @@ -323,7 +324,10 @@ def test_telemetry_config_validations_not_allowed_fields(mocker: MockerFixture,
mock_read_and_validate.return_value = yaml_config

TelemetryConfig.try_from_yaml(Path())
assert "Please remove the 'asset_names' or 'tag_names' field from the rule, or create the rule outside of telemetry config." in caplog.text
assert (
"Please remove the 'asset_names' or 'tag_names' field from the rule, or create the rule outside of telemetry config."
in caplog.text
)


TEST_YAML_CONFIG_STR = """
Expand Down
66 changes: 32 additions & 34 deletions python/lib/sift_py/ingestion/config/yaml/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ def test__validate_rule():
}
)


with pytest.raises(YamlConfigError, match="Expected 'name' to be <str> but it is <int>"):
load._validate_rule(
{
Expand Down Expand Up @@ -349,41 +348,40 @@ def test__validate_rule():
)

with pytest.raises(YamlConfigError, match="Expected 'asset_names' to be"):
load._validate_rule(
{
"name": "overheat_rule",
"description": "some_description",
"expression": "$1 > 10 && $2 > 10",
"type": "review",
"assignee": "[email protected]",
"tags": ["foo", "bar"],
"channel_references": [
{"$1": {"name": "voltage", "data_type": "double"}},
{"$2": {"name": "vehicle_state", "data_type": "double"}},
],
"rule_client_key": "overheat_rule_key",
"asset_names": 123,
}
)
load._validate_rule(
{
"name": "overheat_rule",
"description": "some_description",
"expression": "$1 > 10 && $2 > 10",
"type": "review",
"assignee": "[email protected]",
"tags": ["foo", "bar"],
"channel_references": [
{"$1": {"name": "voltage", "data_type": "double"}},
{"$2": {"name": "vehicle_state", "data_type": "double"}},
],
"rule_client_key": "overheat_rule_key",
"asset_names": 123,
}
)

with pytest.raises(YamlConfigError, match="Expected 'tag_names' to be"):
load._validate_rule(
{
"name": "overheat_rule",
"description": "some_description",
"expression": "$1 > 10 && $2 > 10",
"type": "review",
"assignee": "[email protected]",
"tags": ["foo", "bar"],
"channel_references": [
{"$1": {"name": "voltage", "data_type": "double"}},
{"$2": {"name": "vehicle_state", "data_type": "double"}},
],
"rule_client_key": "overheat_rule_key",
"tag_names": 123,
}
)

load._validate_rule(
{
"name": "overheat_rule",
"description": "some_description",
"expression": "$1 > 10 && $2 > 10",
"type": "review",
"assignee": "[email protected]",
"tags": ["foo", "bar"],
"channel_references": [
{"$1": {"name": "voltage", "data_type": "double"}},
{"$2": {"name": "vehicle_state", "data_type": "double"}},
],
"rule_client_key": "overheat_rule_key",
"tag_names": 123,
}
)

with pytest.raises(YamlConfigError, match="should not have any other properties set"):
load._validate_rule(
Expand Down
1 change: 0 additions & 1 deletion python/lib/sift_py/ingestion/rule/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def test_rule_namespace():
"rule_client_key": "another_valid_rule_client_key",
"asset_names": ["asset2"],
"tag_names": ["tag2"],

},
]
}
Expand Down

0 comments on commit 37fb05f

Please sign in to comment.