Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HardNorth committed Oct 23, 2024
1 parent 37981ad commit 46c45c5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 31 deletions.
5 changes: 2 additions & 3 deletions app/machine_learning/boosting_featurizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ def __init__(self, results: list[tuple[dict[str, Any], dict[str, Any]]], config:
if "calculate_similarities" not in self.config or self.config["calculate_similarities"]:
self.similarity_calculator.find_similarity(processed_results, fields_to_calc_similarity)
self.raw_results = processed_results
self.total_normalized_score = 0.0
self.all_results = self.normalize_results(processed_results)
self.scores_by_type = None
self.defect_type_predict_model = None
self.used_model_info = set()
self.features_to_recalculate_always = set([51, 58] + list(range(67, 74)))
self.total_normalized_score = 0.0

def find_most_relevant_by_type(self) -> dict[str, dict[str, Any]]:
"""Find most relevant log by issue type from OpenSearch query result.
Expand Down Expand Up @@ -257,8 +257,7 @@ def predict_particular_defect_type(self) -> dict[str, float]:
compared_log = search_rs["compared_log"]
det_message = compared_log["_source"][DATA_FIELD]
mr_hit = search_rs["mrHit"]
issue_type_to_compare: str = mr_hit["_source"]["issue_type"]
result[issue_type] = 0.0
issue_type_to_compare: str = mr_hit["_source"]["issue_type"].lower()
try:
if issue_type_to_compare.startswith('nd') or issue_type_to_compare.startswith('ti'):
continue
Expand Down
54 changes: 26 additions & 28 deletions test/service/test_analyzer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,39 +312,37 @@ def test_analyze_logs(self):
]

for idx, test in enumerate(tests):
with sure.ensure('Error in the test case index: {0}', idx):
self._start_server(test["test_calls"])
config = self.get_default_search_config()
app_config = self.app_config
if "app_config" in test:
app_config = test["app_config"]
analyzer_service = AutoAnalyzerService(self.model_chooser,
app_config=app_config,
search_cfg=config)
_boosting_decision_maker = BoostingDecisionMaker(object_saving.create_filesystem(""), '', features=[0])
_boosting_decision_maker.predict = MagicMock(return_value=test["boost_predict"])
if "msearch_results" in test:
analyzer_service.es_client.es_client.msearch = MagicMock(
return_value={"responses": test["msearch_results"]})
analyzer_service.model_chooser.choose_model = MagicMock(
return_value=_boosting_decision_maker)
print(f'Running test case idx: {idx}')
self._start_server(test["test_calls"])
config = self.get_default_search_config()
app_config = self.app_config
if "app_config" in test:
app_config = test["app_config"]
analyzer_service = AutoAnalyzerService(self.model_chooser, app_config=app_config, search_cfg=config)
_boosting_decision_maker = BoostingDecisionMaker(object_saving.create_filesystem(""), '', features=[0])
_boosting_decision_maker.predict = MagicMock(return_value=test["boost_predict"])
if "msearch_results" in test:
analyzer_service.es_client.es_client.msearch = MagicMock(
return_value={"responses": test["msearch_results"]})
analyzer_service.model_chooser.choose_model = MagicMock(
return_value=_boosting_decision_maker)

launches = [launch_objects.Launch(**launch)
for launch in json.loads(test["index_rq"])]
if "analyzer_config" in test:
for launch in launches:
launch.analyzerConfig = test["analyzer_config"]
response = analyzer_service.analyze_logs(launches)
launches = [launch_objects.Launch(**launch)
for launch in json.loads(test["index_rq"])]
if "analyzer_config" in test:
for launch in launches:
launch.analyzerConfig = test["analyzer_config"]
response = analyzer_service.analyze_logs(launches)

response.should.have.length_of(test["expected_count"])
assert len(response) == test["expected_count"]

if test["expected_issue_type"] != "":
response[0].issueType.should.equal(test["expected_issue_type"])
if test["expected_issue_type"] != "":
assert response[0].issueType == test["expected_issue_type"]

if "expected_id" in test:
response[0].relevantItem.should.equal(test["expected_id"])
if "expected_id" in test:
assert response[0].relevantItem == test["expected_id"]

TestAutoAnalyzerService.shutdown_server(test["test_calls"])
TestAutoAnalyzerService.shutdown_server(test["test_calls"])


if __name__ == '__main__':
Expand Down

0 comments on commit 46c45c5

Please sign in to comment.