From d334044f6ea1eed1147eb83cdc316ec3cfe4a1f5 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Sat, 5 Feb 2022 23:03:47 +0100 Subject: [PATCH] Added a couple of parametrized test, will now apply only the basedir of the path given --- src/bootstraparse/modules/pathresolver.py | 2 +- tests/modules/test_pathresolver.py | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/bootstraparse/modules/pathresolver.py b/src/bootstraparse/modules/pathresolver.py index c09bf83..95777a5 100644 --- a/src/bootstraparse/modules/pathresolver.py +++ b/src/bootstraparse/modules/pathresolver.py @@ -9,7 +9,7 @@ class PathResolver: """ def __init__(self, base_path): - self.base_path = os.path.normpath(base_path) + self.base_path = os.path.normpath(os.path.dirname(base_path)) def __call__(self, relative_path='.'): return self.give_absolute(relative_path) diff --git a/tests/modules/test_pathresolver.py b/tests/modules/test_pathresolver.py index 2de1beb..d007544 100644 --- a/tests/modules/test_pathresolver.py +++ b/tests/modules/test_pathresolver.py @@ -1,6 +1,9 @@ +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' @@ -8,7 +11,7 @@ test_path_win = test_path.replace('/', '\\') def test_PathResolver(): - path = path_r.PathResolver(test_path) + path = path_r.PathResolver(test_path+"/") assert path() == os.path.normpath(test_path) assert path().replace('/', '\\') == test_path_win assert path().replace('\\', '/') == test_path @@ -20,3 +23,16 @@ def test_BoostraPath(): def test_b_path(): assert re.match(path_like_regexp, path_r.b_path()) is not None + + +@pytest.mark.parametrize('init,path,result', [ + ('/a/b/c/', '..', "/a/b"), + ('/a/b/c/', '../..', "/a"), + ('/a/b/c/', '../../..', "/"), + ('/a/b/c/test.py', '.', '/a/b/c/'), + ('/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'), +]) +def test_path_call(init, path, result): + assert pathlib.Path(path_r.PathResolver(init)(path)) == pathlib.Path(result) \ No newline at end of file