From f8d6d2b0e426a88e4e851f46fbe21f60f3a10863 Mon Sep 17 00:00:00 2001 From: Tim Byrne Date: Sun, 17 Nov 2019 13:07:04 -0600 Subject: [PATCH] Change tests to expect relative links --- test/test_alt.py | 34 ++++++++++++++++++++++++++++++---- test/test_compat_alt.py | 19 +++++++++++-------- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/test/test_alt.py b/test/test_alt.py index d616869..359f32d 100644 --- a/test/test_alt.py +++ b/test/test_alt.py @@ -40,7 +40,7 @@ def test_alt_source( link_file = paths.work.join(link_path) if tracked or (encrypt and not exclude): assert link_file.islink() - target = py.path.local(link_file.readlink()) + target = py.path.local(os.path.realpath(link_file)) if target.isfile(): assert link_file.read() == source_file_content assert str(source_file) in linked @@ -53,6 +53,31 @@ def test_alt_source( assert str(source_file) not in linked +@pytest.mark.usefixtures('ds1_copy') +@pytest.mark.parametrize('yadm_alt', [True, False], ids=['alt', 'worktree']) +def test_relative_link(runner, paths, yadm_alt): + """Confirm links created are relative""" + yadm_dir = setup_standard_yadm_dir(paths) + + utils.create_alt_files( + paths, '##default', tracked=True, encrypt=False, exclude=False, + yadm_alt=yadm_alt, yadm_dir=yadm_dir) + run = runner([paths.pgm, '-Y', yadm_dir, 'alt']) + assert run.success + assert run.err == '' + + basepath = yadm_dir.join('alt') if yadm_alt else paths.work + + for link_path in TEST_PATHS: + source_file_content = link_path + '##default' + source_file = basepath.join(source_file_content) + link_file = paths.work.join(link_path) + link = link_file.readlink() + relpath = os.path.relpath( + source_file, start=os.path.dirname(link_file)) + assert link == relpath + + @pytest.mark.usefixtures('ds1_copy') @pytest.mark.parametrize('suffix', [ '##default', @@ -89,7 +114,7 @@ def test_alt_conditions( for link_path in TEST_PATHS: source_file = link_path + suffix assert paths.work.join(link_path).islink() - target = py.path.local(paths.work.join(link_path).readlink()) + target = py.path.local(os.path.realpath(paths.work.join(link_path))) if target.isfile(): assert paths.work.join(link_path).read() == source_file assert str(paths.work.join(source_file)) in linked @@ -146,7 +171,8 @@ def test_auto_alt(runner, yadm_y, paths, autoalt): assert not paths.work.join(link_path).exists() else: assert paths.work.join(link_path).islink() - target = py.path.local(paths.work.join(link_path).readlink()) + target = py.path.local( + os.path.realpath(paths.work.join(link_path))) if target.isfile(): assert paths.work.join(link_path).read() == source_file # no linking output when run via auto-alt @@ -183,7 +209,7 @@ def test_stale_link_removal(runner, yadm_y, paths): for stale_path in TEST_PATHS: source_file = stale_path + '##class.' + tst_class assert paths.work.join(stale_path).islink() - target = py.path.local(paths.work.join(stale_path).readlink()) + target = py.path.local(os.path.realpath(paths.work.join(stale_path))) if target.isfile(): assert paths.work.join(stale_path).read() == source_file assert str(paths.work.join(source_file)) in linked diff --git a/test/test_compat_alt.py b/test/test_compat_alt.py index a2c9ad1..da7a8cf 100644 --- a/test/test_compat_alt.py +++ b/test/test_compat_alt.py @@ -101,7 +101,8 @@ def test_alt(runner, yadm_y, paths, source_file = file_path + precedence[precedence_index] if tracked or (encrypt and not exclude): assert paths.work.join(file_path).islink() - target = py.path.local(paths.work.join(file_path).readlink()) + target = py.path.local( + os.path.realpath(paths.work.join(file_path))) if target.isfile(): assert paths.work.join(file_path).read() == source_file assert str(paths.work.join(source_file)) in linked @@ -203,7 +204,7 @@ def test_wild(request, runner, yadm_y, paths, for file_path in TEST_PATHS: source_file = file_path + wild_suffix assert paths.work.join(file_path).islink() - target = py.path.local(paths.work.join(file_path).readlink()) + target = py.path.local(os.path.realpath(paths.work.join(file_path))) if target.isfile(): assert paths.work.join(file_path).read() == source_file assert str(paths.work.join(source_file)) in linked @@ -228,7 +229,7 @@ def test_wild(request, runner, yadm_y, paths, for file_path in TEST_PATHS: source_file = file_path + std_suffix assert paths.work.join(file_path).islink() - target = py.path.local(paths.work.join(file_path).readlink()) + target = py.path.local(os.path.realpath(paths.work.join(file_path))) if target.isfile(): assert paths.work.join(file_path).read() == source_file assert str(paths.work.join(source_file)) in linked @@ -268,7 +269,7 @@ def test_local_override(runner, yadm_y, paths, for file_path in TEST_PATHS: source_file = file_path + '##or-class.or-os.or-hostname.or-user' assert paths.work.join(file_path).islink() - target = py.path.local(paths.work.join(file_path).readlink()) + target = py.path.local(os.path.realpath(paths.work.join(file_path))) if target.isfile(): assert paths.work.join(file_path).read() == source_file assert str(paths.work.join(source_file)) in linked @@ -308,7 +309,7 @@ def test_class_case(runner, yadm_y, paths, tst_sys, suffix): for file_path in TEST_PATHS: source_file = file_path + f'##{suffix}' assert paths.work.join(file_path).islink() - target = py.path.local(paths.work.join(file_path).readlink()) + target = py.path.local(os.path.realpath(paths.work.join(file_path))) if target.isfile(): assert paths.work.join(file_path).read() == source_file assert str(paths.work.join(source_file)) in linked @@ -346,7 +347,8 @@ def test_auto_alt(runner, yadm_y, paths, autoalt): assert not paths.work.join(file_path).exists() else: assert paths.work.join(file_path).islink() - target = py.path.local(paths.work.join(file_path).readlink()) + target = py.path.local( + os.path.realpath(paths.work.join(file_path))) if target.isfile(): assert paths.work.join(file_path).read() == source_file # no linking output when run via auto-alt @@ -383,7 +385,8 @@ def test_delimiter(runner, yadm_y, paths, source_file = file_path + suffix if delimiter == '.': assert paths.work.join(file_path).islink() - target = py.path.local(paths.work.join(file_path).readlink()) + target = py.path.local( + os.path.realpath(paths.work.join(file_path))) if target.isfile(): assert paths.work.join(file_path).read() == source_file assert str(paths.work.join(source_file)) in linked @@ -423,7 +426,7 @@ def test_invalid_links_removed(runner, yadm_y, paths): for file_path in TEST_PATHS: source_file = file_path + '##' + tst_class assert paths.work.join(file_path).islink() - target = py.path.local(paths.work.join(file_path).readlink()) + target = py.path.local(os.path.realpath(paths.work.join(file_path))) if target.isfile(): assert paths.work.join(file_path).read() == source_file assert str(paths.work.join(source_file)) in linked