[lang-ref] ( relative_path_to_absolute_path ) ( python )

def test_relative_path_to_absolute_path():
    # os.path.abspath()
    cwd = os.getcwd()

    assert os.path.abspath('/path/to/file1.txt') == '/path/to/file1.txt'
    assert os.path.abspath('path/to/file1.txt')  == f'{cwd}/path/to/file1.txt'
    assert os.path.abspath('../file1.txt')       == os.path.normpath(f'{cwd}/../file1.txt')
def test_relative_path_to_absolute_path_alternative():
    # pathlib.Path.absolute()
    cwd = os.getcwd()

    assert Path('/path/to/file1.txt').absolute().as_posix() == '/path/to/file1.txt'
    assert Path('path/to/file1.txt').absolute().as_posix()  == f'{cwd}/path/to/file1.txt'
    assert Path('../file1.txt').absolute().as_posix()       == f'{cwd}/../file1.txt' # not normalized