1
0
Fork 0
mirror of synced 2024-11-05 01:08:59 -05:00
yadm/test/test_unit_record_score.py

115 lines
3 KiB
Python
Raw Normal View History

2019-10-01 09:12:18 -04:00
"""Unit tests: record_score"""
import pytest
INIT_VARS = """
score=0
local_class=testclass
local_system=testsystem
local_host=testhost
local_user=testuser
alt_scores=()
alt_targets=()
alt_sources=()
2019-10-01 09:12:18 -04:00
alt_template_cmds=()
"""
REPORT_RESULTS = """
echo "SIZE:${#alt_scores[@]}"
echo "SCORES:${alt_scores[@]}"
echo "TARGETS:${alt_targets[@]}"
echo "SOURCES:${alt_sources[@]}"
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}
record_score "0" "testtgt" "testsrc"
2019-10-01 09:12:18 -04:00
{REPORT_RESULTS}
"""
run = runner(command=['bash'], inp=script)
assert run.success
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
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}
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}
"""
run = runner(command=['bash'], inp=script)
assert run.success
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
2019-10-01 09:12:18 -04:00
@pytest.mark.parametrize('difference', ['lower', 'equal', 'higher'])
def test_existing_scores(runner, yadm, difference):
"""Test existing scores"""
expected_score = '2'
expected_src = 'existing_src'
2019-10-01 09:12:18 -04:00
if difference == 'lower':
score = '1'
elif difference == 'equal':
score = '2'
else:
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)
alt_targets=("testtgt")
alt_sources=("existing_src")
record_score "{score}" "testtgt" "new_src"
2019-10-01 09:12:18 -04:00
{REPORT_RESULTS}
"""
run = runner(command=['bash'], inp=script)
assert run.success
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
2019-10-01 09:12:18 -04:00
def test_existing_template(runner, yadm):
"""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)
alt_targets=("testtgt")
alt_sources=()
2019-10-01 09:12:18 -04:00
alt_template_cmds=("existing_template")
record_score "2" "testtgt" "new_src"
2019-10-01 09:12:18 -04:00
{REPORT_RESULTS}
"""
run = runner(command=['bash'], inp=script)
assert run.success
assert run.err == ''
assert 'SIZE:1\n' in run.out
assert 'SCORES:1\n' in run.out
assert 'TARGETS:testtgt\n' in run.out
assert 'SOURCES:\n' in run.out