From d153378b4c6650f30626177c750a4107c92407ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Zimmermann?= <101292599+ekneg54@users.noreply.github.com> Date: Thu, 15 Feb 2024 12:54:56 +0100 Subject: [PATCH] fix call auto_rule_corpus_tester with config tuple instead of str (#527) Co-authored-by: dtrai2 --- CHANGELOG.md | 5 +++-- logprep/util/auto_rule_tester/auto_rule_corpus_tester.py | 8 ++++---- tests/unit/util/test_auto_rule_corpus_tester.py | 8 ++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a831445d..76d7c4fc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,11 +8,12 @@ ### Improvements ### Bugfix +* fix loading of configuration inside the `AutoRuleCorpusTester` for `logprep test integration` ## v10.0.2 ### Bugfix * fix versioneer import -* fix logprep does not complain about missing PROMETHEUS_MULTIPROC_DIR +* fix logprep does not complain about missing PROMETHEUS_MULTIPROC_DIR ## v10.0.1 ### Bugfix @@ -46,7 +47,7 @@ * make store_custom in s3, opensearch and elasticsearch connector not call `batch_finished_callback` to prevent data loss that could be caused by partially processed events * remove the `schema_and_rule_checker` module * rewrite Logprep Configuration object see documentation for more details -* rewrite Runner +* rewrite Runner * delete MultiProcessingPipeline class to simplify multiprocesing * add FDA to the quickstart setup * bump versions for `fastapi` and `aiohttp` to address CVEs diff --git a/logprep/util/auto_rule_tester/auto_rule_corpus_tester.py b/logprep/util/auto_rule_tester/auto_rule_corpus_tester.py index ec8014038..fdc0b02dd 100644 --- a/logprep/util/auto_rule_tester/auto_rule_corpus_tester.py +++ b/logprep/util/auto_rule_tester/auto_rule_corpus_tester.py @@ -129,7 +129,7 @@ class RuleCorpusTester: _tmp_dir: str """ Temporary directory where test files will be saved temporarily """ - _original_config_path: str + _original_config_paths: tuple[str] """ Path to the original configuration that should be tested """ _input_test_data_path: str @@ -149,8 +149,8 @@ class TestCase: report: List = Factory(list) warnings: str = field(default="") - def __init__(self, config_path, input_test_data_path): - self._original_config_path = config_path + def __init__(self, config_paths: tuple[str], input_test_data_path: str): + self._original_config_paths = config_paths self._input_test_data_path = input_test_data_path self.log_capture_string = None @@ -193,7 +193,7 @@ def _pipeline(self): patched_config.input = { "patched_input": {"type": "json_input", "documents_path": str(merged_input_file_path)} } - config = Configuration.from_sources([self._original_config_path]) + config = Configuration.from_sources(self._original_config_paths) input_config = config.input connector_name = list(input_config.keys())[0] if "preprocessing" in input_config[connector_name]: diff --git a/tests/unit/util/test_auto_rule_corpus_tester.py b/tests/unit/util/test_auto_rule_corpus_tester.py index 2f03bea83..062ac80e1 100644 --- a/tests/unit/util/test_auto_rule_corpus_tester.py +++ b/tests/unit/util/test_auto_rule_corpus_tester.py @@ -15,7 +15,7 @@ @pytest.fixture(name="corpus_tester") def fixture_auto_rule_corpus_tester(): - config_path = "tests/testdata/config/config.yml" + config_path = ("tests/testdata/config/config.yml",) data_dir = "will be overwritten in test cases" corpus_tester = RuleCorpusTester(config_path, data_dir) return corpus_tester @@ -385,7 +385,7 @@ def test_run_with_two_processors_that_have_different_extra_outputs( ) test_config_path = tmp_path / "test_config.yml" test_config_path.write_text(json.dumps(config), encoding="utf8") - corpus_tester = RuleCorpusTester(str(test_config_path), "") + corpus_tester = RuleCorpusTester([str(test_config_path)], "") test_data = { "input": { "message": "A B", @@ -450,7 +450,7 @@ def test_corpus_tests_dont_share_cache_between_runs_by_resetting_processors( # the cache realizes it as an existing pseudonym already. write_test_case_data_tmp_files(test_data_dir, "test_case_one", test_case_data) write_test_case_data_tmp_files(test_data_dir, "test_case_two", test_case_data) - config_path = "tests/testdata/config/config.yml" + config_path = ["tests/testdata/config/config.yml"] corpus_tester = RuleCorpusTester(config_path, test_data_dir) corpus_tester.run() console_output, console_error = capsys.readouterr() @@ -482,7 +482,7 @@ def test_warnings_are_printed_inside_the_detailed_reports(self, mock_exit, tmp_p test_data_dir = tmp_path / "test_data" os.makedirs(test_data_dir, exist_ok=True) write_test_case_data_tmp_files(test_data_dir, "test_case_one", test_case_data) - config_path = "tests/testdata/config/config.yml" + config_path = ["tests/testdata/config/config.yml"] corpus_tester = RuleCorpusTester(config_path, test_data_dir) corpus_tester.run() console_output, console_error = capsys.readouterr()