[lang-ref] ( normalize_path ) ( python )
def test_normalize_path():
# os.path.normpath()
assert os.path.normpath('/path//to/file1.txt') == '/path/to/file1.txt'
assert os.path.normpath('/path/to//file1.txt') == '/path/to/file1.txt'
assert os.path.normpath('/path/to/./file1.txt') == '/path/to/file1.txt'
assert os.path.normpath('/path/to/../file1.txt') == '/path/file1.txt'
def test_normalize_path_alternative():
# pathlib.Path (+ resolve for "..")
assert Path('/path//to/file1.txt').as_posix() == '/path/to/file1.txt'
assert Path('/path/to//file1.txt').as_posix() == '/path/to/file1.txt'
assert Path('/path/to/./file1.txt').as_posix() == '/path/to/file1.txt'
# resolve(strict=False) collapses ".." (and makes it absolute)
assert Path('/path/to/../file1.txt').resolve(strict=False).as_posix() == '/path/file1.txt'