diff --git a/src/bootstraparse/modules/pathresolver.py b/src/bootstraparse/modules/pathresolver.py index 4d763fa..67af985 100644 --- a/src/bootstraparse/modules/pathresolver.py +++ b/src/bootstraparse/modules/pathresolver.py @@ -1,5 +1,6 @@ # Module for resolving relative path problems +# import pathlib import os @@ -10,7 +11,7 @@ class PathResolver: """ def __init__(self, base_path): - self.base_path = os.path.normpath(os.path.dirname(base_path)) + self.base_path = os.path.normpath(os.path.join(os.getcwd(), os.path.dirname(base_path))) def __call__(self, relative_path='.'): """ diff --git a/tests/modules/test_pathresolver.py b/tests/modules/test_pathresolver.py index 85f7810..b7d8523 100644 --- a/tests/modules/test_pathresolver.py +++ b/tests/modules/test_pathresolver.py @@ -1,20 +1,12 @@ import pathlib import bootstraparse.modules.pathresolver as path_r -import os import re import pytest path_like_regexp = r'^([A-z]\:\\|/).+[/\\]src[/\\]bootstraparse[/\\]?$' -test_path = '/a/b/c/test' -test_path_win = test_path.replace('/', '\\') - - -def test_PathResolver(): - path = path_r.PathResolver(test_path+"/") - assert path() == os.path.normpath(test_path) - assert path().replace('/', '\\') == test_path_win - assert path().replace('\\', '/') == test_path +# test_path = '/a/b/c/test' +# test_path_win = test_path.replace('/', '\\') def test_BoostraPath(): @@ -33,6 +25,8 @@ def test_b_path(): ('/a/b/c/test.py', './', '/a/b/c/'), ('/a/b/c/test.py', './test2.py', '/a/b/c/test2.py'), ('/a/b/c/test.py', '../test2.py', '/a/b/test2.py'), + ('/a/b/c/test.py', '/d/test2.py', '/d/test2.py'), + ('/a/b/c/test.py', '../d/test2.py', '/a/b/d/test2.py'), ]) def test_path_call(init, path, result): - assert pathlib.Path(path_r.PathResolver(init)(path)) == pathlib.Path(result) + assert pathlib.Path(path_r.PathResolver(init)(path)).parts[1:] == pathlib.Path(result).parts[1:]