forked from yadm-dev/yadm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This function will create a path relative to another, without the use of an external program like dirname.
- Loading branch information
1 parent
f8d6d2b
commit 98392b9
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""Unit tests: relative_path""" | ||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'base,full_path,expected', | ||
[ | ||
("/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"), | ||
("/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"), | ||
], | ||
) | ||
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}" | ||
""" | ||
|
||
run = runner(command=['bash'], inp=script) | ||
assert run.success | ||
assert run.err == '' | ||
assert run.out.strip() == expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters