1
0
mirror of https://github.com/TheLocehiliosan/yadm synced 2026-03-02 03:49:29 +00:00

Refactor symlink code

Update variable names, favoring the terminology used by `ln`.
* source (original file containing data)
* target (the symlink file, pointing to source)
This commit is contained in:
Tim Byrne
2019-11-25 07:44:44 -06:00
parent 61576a6ae1
commit 5634c09a8a
3 changed files with 93 additions and 92 deletions

View File

@@ -8,16 +8,16 @@ INIT_VARS = """
local_host=testhost
local_user=testuser
alt_scores=()
alt_filenames=()
alt_targets=()
alt_sources=()
alt_template_cmds=()
"""
REPORT_RESULTS = """
echo "SIZE:${#alt_scores[@]}"
echo "SCORES:${alt_scores[@]}"
echo "FILENAMES:${alt_filenames[@]}"
echo "TARGETS:${alt_targets[@]}"
echo "SOURCES:${alt_sources[@]}"
"""
@@ -27,7 +27,7 @@ def test_dont_record_zeros(runner, yadm):
script = f"""
YADM_TEST=1 source {yadm}
{INIT_VARS}
record_score "0" "testfile" "testtarget"
record_score "0" "testtgt" "testsrc"
{REPORT_RESULTS}
"""
run = runner(command=['bash'], inp=script)
@@ -35,8 +35,8 @@ def test_dont_record_zeros(runner, yadm):
assert run.err == ''
assert 'SIZE:0\n' in run.out
assert 'SCORES:\n' in run.out
assert 'FILENAMES:\n' in run.out
assert 'TARGETS:\n' in run.out
assert 'SOURCES:\n' in run.out
def test_new_scores(runner, yadm):
@@ -45,9 +45,9 @@ def test_new_scores(runner, yadm):
script = f"""
YADM_TEST=1 source {yadm}
{INIT_VARS}
record_score "1" "file_one" "targ_one"
record_score "2" "file_two" "targ_two"
record_score "4" "file_three" "targ_three"
record_score "1" "tgt_one" "src_one"
record_score "2" "tgt_two" "src_two"
record_score "4" "tgt_three" "src_three"
{REPORT_RESULTS}
"""
run = runner(command=['bash'], inp=script)
@@ -55,8 +55,8 @@ def test_new_scores(runner, yadm):
assert run.err == ''
assert 'SIZE:3\n' in run.out
assert 'SCORES:1 2 4\n' in run.out
assert 'FILENAMES:file_one file_two file_three\n' in run.out
assert 'TARGETS:targ_one targ_two targ_three\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
@pytest.mark.parametrize('difference', ['lower', 'equal', 'higher'])
@@ -64,7 +64,7 @@ def test_existing_scores(runner, yadm, difference):
"""Test existing scores"""
expected_score = '2'
expected_target = 'existing_target'
expected_src = 'existing_src'
if difference == 'lower':
score = '1'
elif difference == 'equal':
@@ -72,15 +72,15 @@ def test_existing_scores(runner, yadm, difference):
else:
score = '4'
expected_score = '4'
expected_target = 'new_target'
expected_src = 'new_src'
script = f"""
YADM_TEST=1 source {yadm}
{INIT_VARS}
alt_scores=(2)
alt_filenames=("testfile")
alt_targets=("existing_target")
record_score "{score}" "testfile" "new_target"
alt_targets=("testtgt")
alt_sources=("existing_src")
record_score "{score}" "testtgt" "new_src"
{REPORT_RESULTS}
"""
run = runner(command=['bash'], inp=script)
@@ -88,21 +88,21 @@ def test_existing_scores(runner, yadm, difference):
assert run.err == ''
assert 'SIZE:1\n' in run.out
assert f'SCORES:{expected_score}\n' in run.out
assert 'FILENAMES:testfile\n' in run.out
assert f'TARGETS:{expected_target}\n' in run.out
assert 'TARGETS:testtgt\n' in run.out
assert f'SOURCES:{expected_src}\n' in run.out
def test_existing_template(runner, yadm):
"""Record nothing if a template command is registered for this file"""
"""Record nothing if a template command is registered for this target"""
script = f"""
YADM_TEST=1 source {yadm}
{INIT_VARS}
alt_scores=(1)
alt_filenames=("testfile")
alt_targets=()
alt_targets=("testtgt")
alt_sources=()
alt_template_cmds=("existing_template")
record_score "2" "testfile" "new_target"
record_score "2" "testtgt" "new_src"
{REPORT_RESULTS}
"""
run = runner(command=['bash'], inp=script)
@@ -110,5 +110,5 @@ def test_existing_template(runner, yadm):
assert run.err == ''
assert 'SIZE:1\n' in run.out
assert 'SCORES:1\n' in run.out
assert 'FILENAMES:testfile\n' in run.out
assert 'TARGETS:\n' in run.out
assert 'TARGETS:testtgt\n' in run.out
assert 'SOURCES:\n' in run.out

View File

@@ -1,16 +1,16 @@
"""Unit tests: record_template"""
INIT_VARS = """
alt_filenames=()
alt_template_cmds=()
alt_targets=()
alt_template_cmds=()
alt_sources=()
"""
REPORT_RESULTS = """
echo "SIZE:${#alt_filenames[@]}"
echo "FILENAMES:${alt_filenames[@]}"
echo "SIZE:${#alt_targets[@]}"
echo "TARGETS:${alt_targets[@]}"
echo "CMDS:${alt_template_cmds[@]}"
echo "TARGS:${alt_targets[@]}"
echo "SOURCES:${alt_sources[@]}"
"""
@@ -20,18 +20,18 @@ def test_new_template(runner, yadm):
script = f"""
YADM_TEST=1 source {yadm}
{INIT_VARS}
record_template "file_one" "cmd_one" "targ_one"
record_template "file_two" "cmd_two" "targ_two"
record_template "file_three" "cmd_three" "targ_three"
record_template "tgt_one" "cmd_one" "src_one"
record_template "tgt_two" "cmd_two" "src_two"
record_template "tgt_three" "cmd_three" "src_three"
{REPORT_RESULTS}
"""
run = runner(command=['bash'], inp=script)
assert run.success
assert run.err == ''
assert 'SIZE:3\n' in run.out
assert 'FILENAMES:file_one file_two file_three\n' in run.out
assert 'TARGETS:tgt_one tgt_two tgt_three\n' in run.out
assert 'CMDS:cmd_one cmd_two cmd_three\n' in run.out
assert 'TARGS:targ_one targ_two targ_three\n' in run.out
assert 'SOURCES:src_one src_two src_three\n' in run.out
def test_existing_template(runner, yadm):
@@ -40,16 +40,16 @@ def test_existing_template(runner, yadm):
script = f"""
YADM_TEST=1 source {yadm}
{INIT_VARS}
alt_filenames=("testfile")
alt_targets=("testtgt")
alt_template_cmds=("existing_cmd")
alt_targets=("existing_targ")
record_template "testfile" "new_cmd" "new_targ"
alt_sources=("existing_src")
record_template "testtgt" "new_cmd" "new_src"
{REPORT_RESULTS}
"""
run = runner(command=['bash'], inp=script)
assert run.success
assert run.err == ''
assert 'SIZE:1\n' in run.out
assert 'FILENAMES:testfile\n' in run.out
assert 'TARGETS:testtgt\n' in run.out
assert 'CMDS:new_cmd\n' in run.out
assert 'TARGS:new_targ\n' in run.out
assert 'SOURCES:new_src\n' in run.out