2019-10-01 09:12:18 -04:00
|
|
|
"""Unit tests: record_score"""
|
2024-11-11 16:30:41 -05:00
|
|
|
|
2019-10-01 09:12:18 -04:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
INIT_VARS = """
|
|
|
|
score=0
|
|
|
|
local_class=testclass
|
|
|
|
local_system=testsystem
|
|
|
|
local_host=testhost
|
|
|
|
local_user=testuser
|
|
|
|
alt_scores=()
|
|
|
|
alt_targets=()
|
2019-11-25 08:44:44 -05:00
|
|
|
alt_sources=()
|
2024-12-15 09:10:02 -05:00
|
|
|
alt_template_processors=()
|
2019-10-01 09:12:18 -04:00
|
|
|
"""
|
|
|
|
|
|
|
|
REPORT_RESULTS = """
|
|
|
|
echo "SIZE:${#alt_scores[@]}"
|
|
|
|
echo "SCORES:${alt_scores[@]}"
|
|
|
|
echo "TARGETS:${alt_targets[@]}"
|
2019-11-25 08:44:44 -05:00
|
|
|
echo "SOURCES:${alt_sources[@]}"
|
2024-12-15 09:10:02 -05:00
|
|
|
echo "TEMPLATE_PROCESSORS:${alt_template_processors[@]}"
|
2019-10-01 09:12:18 -04:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def test_dont_record_zeros(runner, yadm):
|
|
|
|
"""Record nothing if the score is zero"""
|
|
|
|
|
|
|
|
script = f"""
|
|
|
|
YADM_TEST=1 source {yadm}
|
|
|
|
{INIT_VARS}
|
2019-11-25 08:44:44 -05:00
|
|
|
record_score "0" "testtgt" "testsrc"
|
2019-10-01 09:12:18 -04:00
|
|
|
{REPORT_RESULTS}
|
|
|
|
"""
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["bash"], inp=script)
|
2019-10-01 09:12:18 -04:00
|
|
|
assert run.success
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.err == ""
|
|
|
|
assert "SIZE:0\n" in run.out
|
|
|
|
assert "SCORES:\n" in run.out
|
|
|
|
assert "TARGETS:\n" in run.out
|
|
|
|
assert "SOURCES:\n" in run.out
|
2024-12-15 09:10:02 -05:00
|
|
|
assert "TEMPLATE_PROCESSORS:\n" in run.out
|
2019-10-01 09:12:18 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_new_scores(runner, yadm):
|
|
|
|
"""Test new scores"""
|
|
|
|
|
|
|
|
script = f"""
|
|
|
|
YADM_TEST=1 source {yadm}
|
|
|
|
{INIT_VARS}
|
2024-11-28 17:28:32 -05:00
|
|
|
record_score "1" "tgt_one" "src_one" ""
|
|
|
|
record_score "2" "tgt_two" "src_two" ""
|
|
|
|
record_score "4" "tgt_three" "src_three" ""
|
2019-10-01 09:12:18 -04:00
|
|
|
{REPORT_RESULTS}
|
|
|
|
"""
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["bash"], inp=script)
|
2019-10-01 09:12:18 -04:00
|
|
|
assert run.success
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.err == ""
|
|
|
|
assert "SIZE:3\n" in run.out
|
|
|
|
assert "SCORES:1 2 4\n" in run.out
|
|
|
|
assert "TARGETS:tgt_one tgt_two tgt_three\n" in run.out
|
|
|
|
assert "SOURCES:src_one src_two src_three\n" in run.out
|
2024-12-15 09:10:02 -05:00
|
|
|
assert "TEMPLATE_PROCESSORS: \n" in run.out
|
2019-10-01 09:12:18 -04:00
|
|
|
|
|
|
|
|
2023-07-10 15:43:17 -04:00
|
|
|
@pytest.mark.parametrize("difference", ["lower", "equal", "higher"])
|
2019-10-01 09:12:18 -04:00
|
|
|
def test_existing_scores(runner, yadm, difference):
|
|
|
|
"""Test existing scores"""
|
|
|
|
|
2023-07-10 15:43:17 -04:00
|
|
|
expected_score = "2"
|
|
|
|
expected_src = "existing_src"
|
|
|
|
if difference == "lower":
|
|
|
|
score = "1"
|
|
|
|
elif difference == "equal":
|
|
|
|
score = "2"
|
2019-10-01 09:12:18 -04:00
|
|
|
else:
|
2023-07-10 15:43:17 -04:00
|
|
|
score = "4"
|
|
|
|
expected_score = "4"
|
|
|
|
expected_src = "new_src"
|
2019-10-01 09:12:18 -04:00
|
|
|
|
|
|
|
script = f"""
|
|
|
|
YADM_TEST=1 source {yadm}
|
|
|
|
{INIT_VARS}
|
|
|
|
alt_scores=(2)
|
2019-11-25 08:44:44 -05:00
|
|
|
alt_targets=("testtgt")
|
|
|
|
alt_sources=("existing_src")
|
2024-12-15 09:10:02 -05:00
|
|
|
alt_template_processors=("")
|
2024-11-28 17:28:32 -05:00
|
|
|
record_score "{score}" "testtgt" "new_src" ""
|
2019-10-01 09:12:18 -04:00
|
|
|
{REPORT_RESULTS}
|
|
|
|
"""
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["bash"], inp=script)
|
2019-10-01 09:12:18 -04:00
|
|
|
assert run.success
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.err == ""
|
|
|
|
assert "SIZE:1\n" in run.out
|
|
|
|
assert f"SCORES:{expected_score}\n" in run.out
|
|
|
|
assert "TARGETS:testtgt\n" in run.out
|
|
|
|
assert f"SOURCES:{expected_src}\n" in run.out
|
2024-12-15 09:10:02 -05:00
|
|
|
assert "TEMPLATE_PROCESSORS:\n" in run.out
|
2019-10-01 09:12:18 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_existing_template(runner, yadm):
|
2019-11-25 08:44:44 -05:00
|
|
|
"""Record nothing if a template command is registered for this target"""
|
2019-10-01 09:12:18 -04:00
|
|
|
|
|
|
|
script = f"""
|
|
|
|
YADM_TEST=1 source {yadm}
|
|
|
|
{INIT_VARS}
|
|
|
|
alt_scores=(1)
|
2019-11-25 08:44:44 -05:00
|
|
|
alt_targets=("testtgt")
|
2024-11-28 17:28:32 -05:00
|
|
|
alt_sources=("src")
|
2024-12-15 09:10:02 -05:00
|
|
|
alt_template_processors=("existing_template")
|
2024-11-28 17:28:32 -05:00
|
|
|
record_score "2" "testtgt" "new_src" ""
|
2019-10-01 09:12:18 -04:00
|
|
|
{REPORT_RESULTS}
|
|
|
|
"""
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["bash"], inp=script)
|
2019-10-01 09:12:18 -04:00
|
|
|
assert run.success
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.err == ""
|
|
|
|
assert "SIZE:1\n" in run.out
|
|
|
|
assert "SCORES:1\n" in run.out
|
|
|
|
assert "TARGETS:testtgt\n" in run.out
|
2024-11-28 17:28:32 -05:00
|
|
|
assert "SOURCES:src\n" in run.out
|
2024-12-15 09:10:02 -05:00
|
|
|
assert "TEMPLATE_PROCESSORS:existing_template\n" in run.out
|
2020-07-08 03:40:13 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_config_first(runner, yadm):
|
|
|
|
"""Verify YADM_CONFIG is always processed first"""
|
|
|
|
|
2023-07-10 15:43:17 -04:00
|
|
|
config = "yadm_config_file"
|
2020-07-08 03:40:13 -04:00
|
|
|
script = f"""
|
|
|
|
YADM_TEST=1 source {yadm}
|
|
|
|
{INIT_VARS}
|
|
|
|
YADM_CONFIG={config}
|
2024-11-28 17:28:32 -05:00
|
|
|
record_score "1" "tgt_before" "src_before" ""
|
2024-12-15 09:10:02 -05:00
|
|
|
record_score "1" "tgt_tmp" "src_tmp" "processor_tmp"
|
2024-11-28 17:28:32 -05:00
|
|
|
record_score "2" "{config}" "src_config" ""
|
|
|
|
record_score "3" "tgt_after" "src_after" ""
|
2020-07-08 03:40:13 -04:00
|
|
|
{REPORT_RESULTS}
|
|
|
|
"""
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["bash"], inp=script)
|
2020-07-08 03:40:13 -04:00
|
|
|
assert run.success
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.err == ""
|
2024-11-28 17:28:32 -05:00
|
|
|
assert "SIZE:4\n" in run.out
|
|
|
|
assert "SCORES:2 1 1 3\n" in run.out
|
2023-07-10 15:43:17 -04:00
|
|
|
assert f"TARGETS:{config} tgt_before tgt_tmp tgt_after\n" in run.out
|
|
|
|
assert "SOURCES:src_config src_before src_tmp src_after\n" in run.out
|
2024-12-15 09:10:02 -05:00
|
|
|
assert "TEMPLATE_PROCESSORS: processor_tmp \n" in run.out
|
2024-11-28 17:28:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
def test_new_template(runner, yadm):
|
|
|
|
"""Test new template"""
|
|
|
|
|
|
|
|
script = f"""
|
|
|
|
YADM_TEST=1 source {yadm}
|
|
|
|
{INIT_VARS}
|
2024-12-15 09:10:02 -05:00
|
|
|
record_score 0 "tgt_one" "src_one" "processor_one"
|
|
|
|
record_score 0 "tgt_two" "src_two" "processor_two"
|
|
|
|
record_score 0 "tgt_three" "src_three" "processor_three"
|
2024-11-28 17:28:32 -05:00
|
|
|
{REPORT_RESULTS}
|
|
|
|
"""
|
|
|
|
run = runner(command=["bash"], inp=script)
|
|
|
|
assert run.success
|
|
|
|
assert run.err == ""
|
|
|
|
assert "SIZE:3\n" in run.out
|
|
|
|
assert "SCORES:0 0 0\n" in run.out
|
|
|
|
assert "TARGETS:tgt_one tgt_two tgt_three\n" in run.out
|
|
|
|
assert "SOURCES:src_one src_two src_three\n" in run.out
|
2024-12-15 09:10:02 -05:00
|
|
|
assert "TEMPLATE_PROCESSORS:processor_one processor_two processor_three\n" in run.out
|
2024-11-28 17:28:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
def test_overwrite_existing_template(runner, yadm):
|
|
|
|
"""Overwrite existing templates"""
|
|
|
|
|
|
|
|
script = f"""
|
|
|
|
YADM_TEST=1 source {yadm}
|
|
|
|
{INIT_VARS}
|
|
|
|
alt_scores=(0)
|
|
|
|
alt_targets=("testtgt")
|
2024-12-15 09:10:02 -05:00
|
|
|
alt_template_processors=("existing_processor")
|
2024-11-28 17:28:32 -05:00
|
|
|
alt_sources=("existing_src")
|
2024-12-15 09:10:02 -05:00
|
|
|
record_score 0 "testtgt" "new_src" "new_processor"
|
2024-11-28 17:28:32 -05:00
|
|
|
{REPORT_RESULTS}
|
|
|
|
"""
|
|
|
|
run = runner(command=["bash"], inp=script)
|
|
|
|
assert run.success
|
|
|
|
assert run.err == ""
|
|
|
|
assert "SIZE:1\n" in run.out
|
|
|
|
assert "SCORES:0\n" in run.out
|
|
|
|
assert "TARGETS:testtgt\n" in run.out
|
|
|
|
assert "SOURCES:new_src\n" in run.out
|
2024-12-15 09:10:02 -05:00
|
|
|
assert "TEMPLATE_PROCESSORS:new_processor\n" in run.out
|