Added a couple of parametrized test, will now apply only the basedir of the path given
This commit is contained in:
parent
2b057796ba
commit
d334044f6e
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
Loading…
Reference in New Issue