diff options
author | Andrew Lewis <nerf@judo.za.org> | 2024-08-20 12:45:12 +0200 |
---|---|---|
committer | Andrew Lewis <nerf@judo.za.org> | 2024-08-20 12:45:12 +0200 |
commit | 1517856521a6f76b1bb2ae2a7f0b24d6c1ed11d3 (patch) | |
tree | 9ebb20c32aa1d38ca9f369539233f91581e5d6b5 | |
parent | 8fe1612bdb6572fc60284190351ed4075d72402a (diff) | |
download | rspamd-1517856521a6f76b1bb2ae2a7f0b24d6c1ed11d3.tar.gz rspamd-1517856521a6f76b1bb2ae2a7f0b24d6c1ed11d3.zip |
[Test] Improve grow_factor tests
-rw-r--r-- | test/functional/cases/450_grow_factor.robot | 17 | ||||
-rw-r--r-- | test/functional/lib/grow_factor.py | 32 | ||||
-rw-r--r-- | test/functional/lua/simple_plus.lua | 4 |
3 files changed, 37 insertions, 16 deletions
diff --git a/test/functional/cases/450_grow_factor.robot b/test/functional/cases/450_grow_factor.robot index 518c3ed82..85ca08c68 100644 --- a/test/functional/cases/450_grow_factor.robot +++ b/test/functional/cases/450_grow_factor.robot @@ -1,6 +1,7 @@ *** Settings *** Suite Setup Rspamd Setup Suite Teardown Rspamd Teardown +Library ${RSPAMD_TESTDIR}/lib/grow_factor.py Library ${RSPAMD_TESTDIR}/lib/rspamd.py Resource ${RSPAMD_TESTDIR}/lib/rspamd.robot Variables ${RSPAMD_TESTDIR}/lib/vars.py @@ -9,29 +10,17 @@ Variables ${RSPAMD_TESTDIR}/lib/vars.py ${CONFIG} ${RSPAMD_TESTDIR}/configs/grow_factor.conf ${HAM_MESSAGE} ${RSPAMD_TESTDIR}/messages/ham.eml ${RSPAMD_SCOPE} Suite -&{RESCORED_SYMBOLS} -... SIMPLE_TEST_001=0.013067 -... SIMPLE_TEST_002=14.374194 -... SIMPLE_TEST_003=6.533724 -... SIMPLE_TEST_004=13.067449 -... SIMPLE_TEST_005=0.013067 -... SIMPLE_TEST_006=0.130674 -... SIMPLE_TEST_007=0.143741 -... SIMPLE_TEST_008=0.156809 -... SIMPLE_TEST_009=0.169876 -... SIMPLE_TEST_010=0.182944 -... SIMPLE_TEST_011=-0.010000 -... SIMPLE_TEST_012=-0.100000 -... SIMPLE_TEST_013=-10.000000 *** Test Cases *** CHECK BASIC Scan File ${HAM_MESSAGE} ... Settings={groups_enabled = [simple_tests]} Expect Required Score 15 + &{RESCORED_SYMBOLS} = Apply Grow Factor 1.1 15 Expect Symbols With Scores &{RESCORED_SYMBOLS} CHECK NOREJECT Scan File ${HAM_MESSAGE} ... Settings={actions { reject = null, "add header" = 15 }, groups_enabled = [simple_tests]} + &{RESCORED_SYMBOLS} = Apply Grow Factor 1.1 15 Expect Symbols With Scores &{RESCORED_SYMBOLS} diff --git a/test/functional/lib/grow_factor.py b/test/functional/lib/grow_factor.py new file mode 100644 index 000000000..486a186e8 --- /dev/null +++ b/test/functional/lib/grow_factor.py @@ -0,0 +1,32 @@ +from robot.libraries.BuiltIn import BuiltIn + +def Apply_Grow_Factor(grow_factor, max_limit): + grow_factor = float(grow_factor) + max_limit = float(max_limit) + expected_result = {} + res = BuiltIn().get_variable_value("${SCAN_RESULT}") + + for sym, p in res["symbols"].items(): + expected_result[sym] = p["score"] + + if grow_factor <= 1.0: + return expected_result + + if max_limit <= 0: + return expected_result + + final_grow_factor = grow_factor + mult = grow_factor - 1.0 + for sym, p in res["symbols"].items(): + if p["score"] <= 0: + continue + mult *= round(p["score"] / max_limit, 2) + final_grow_factor *= round(1.0 + mult, 2) + + if final_grow_factor <= 1.0: + return expected_result + + for sym, p in res["symbols"].items(): + if p["score"] <= 0: + continue + expected_result[sym] = round(p["score"] * final_grow_factor, 2) diff --git a/test/functional/lua/simple_plus.lua b/test/functional/lua/simple_plus.lua index 57aee6ae3..badde685f 100644 --- a/test/functional/lua/simple_plus.lua +++ b/test/functional/lua/simple_plus.lua @@ -1,7 +1,7 @@ local test_symbols = { SIMPLE_TEST_001 = 0.01, - SIMPLE_TEST_002 = 11, - SIMPLE_TEST_003 = 5.0, + SIMPLE_TEST_002 = 5.5, + SIMPLE_TEST_003 = 2.5, SIMPLE_TEST_004 = 10.0, SIMPLE_TEST_005 = 0.01, SIMPLE_TEST_006 = 0.10, |