2019-11-17 13:58:49 -05:00
|
|
|
"""Unit tests: relative_path"""
|
2024-11-11 16:30:41 -05:00
|
|
|
|
2019-11-17 13:58:49 -05:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
2023-07-10 15:43:17 -04:00
|
|
|
"base,full_path,expected",
|
2019-11-17 13:58:49 -05:00
|
|
|
[
|
|
|
|
("/A/B/C", "/A", "../.."),
|
|
|
|
("/A/B/C", "/A/B", ".."),
|
|
|
|
("/A/B/C", "/A/B/C", ""),
|
|
|
|
("/A/B/C", "/A/B/C/D", "D"),
|
|
|
|
("/A/B/C", "/A/B/C/D/E", "D/E"),
|
2024-12-03 16:52:58 -05:00
|
|
|
("/A/B/C", "/A/B/CD", "../CD"),
|
|
|
|
("/A/B/C", "/A/BB/C", "../../BB/C"),
|
2019-11-17 13:58:49 -05:00
|
|
|
("/A/B/C", "/A/B/D", "../D"),
|
|
|
|
("/A/B/C", "/A/B/D/E", "../D/E"),
|
|
|
|
("/A/B/C", "/A/D", "../../D"),
|
|
|
|
("/A/B/C", "/A/D/E", "../../D/E"),
|
|
|
|
("/A/B/C", "/D/E/F", "../../../D/E/F"),
|
2024-12-03 16:52:58 -05:00
|
|
|
("/", "/A/B/C", "A/B/C"),
|
|
|
|
("/A/B/C", "/", "../../.."),
|
|
|
|
("/A/B B/C", "/A/C C/D", "../../C C/D"),
|
2019-11-17 13:58:49 -05:00
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_relative_path(runner, paths, base, full_path, expected):
|
|
|
|
"""Test translate_to_relative"""
|
|
|
|
|
|
|
|
script = f"""
|
|
|
|
YADM_TEST=1 source {paths.pgm}
|
|
|
|
relative_path "{base}" "{full_path}"
|
|
|
|
"""
|
|
|
|
|
2023-07-10 15:43:17 -04:00
|
|
|
run = runner(command=["bash"], inp=script)
|
2019-11-17 13:58:49 -05:00
|
|
|
assert run.success
|
2023-07-10 15:43:17 -04:00
|
|
|
assert run.err == ""
|
2019-11-17 13:58:49 -05:00
|
|
|
assert run.out.strip() == expected
|