-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pegasko
committed
Jan 8, 2024
1 parent
b87e95e
commit fdccf5f
Showing
10 changed files
with
258 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
venv/* | ||
test/* | ||
*/__pycache__/* | ||
*.egg-info | ||
build/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pytest] | ||
testpaths = test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import xleb.pathutils | ||
|
||
from xleb.config import config | ||
|
||
|
||
def test_normalize_abs_posixpath(): | ||
"""Test pathutils webpath normalization""" | ||
|
||
assert xleb.pathutils.normalize_abs_posixpath('') == '/' | ||
assert xleb.pathutils.normalize_abs_posixpath('/') == '/' | ||
|
||
assert xleb.pathutils.normalize_abs_posixpath(' ') == '/' | ||
assert xleb.pathutils.normalize_abs_posixpath(' / ') == '/' | ||
assert xleb.pathutils.normalize_abs_posixpath(' //// ') == '/' | ||
assert xleb.pathutils.normalize_abs_posixpath('///////') == '/' | ||
assert xleb.pathutils.normalize_abs_posixpath('/ / / /') == '/' | ||
assert xleb.pathutils.normalize_abs_posixpath(' // / ') == '/' | ||
assert xleb.pathutils.normalize_abs_posixpath('///////foo') == '/foo' | ||
assert xleb.pathutils.normalize_abs_posixpath('/// ///foo') == '/foo' | ||
assert xleb.pathutils.normalize_abs_posixpath('///////foo/') == '/foo' | ||
assert xleb.pathutils.normalize_abs_posixpath('//// / foo/') == '/foo' | ||
assert xleb.pathutils.normalize_abs_posixpath(' foo/') == '/foo' | ||
assert xleb.pathutils.normalize_abs_posixpath(' foo ') == '/foo' | ||
assert xleb.pathutils.normalize_abs_posixpath('/foo/////') == '/foo' | ||
assert xleb.pathutils.normalize_abs_posixpath('///////foo////') == '/foo' | ||
|
||
assert xleb.pathutils.normalize_abs_posixpath('foo') == '/foo' | ||
assert xleb.pathutils.normalize_abs_posixpath('/foo') == '/foo' | ||
|
||
assert xleb.pathutils.normalize_abs_posixpath('foo/bar') == '/foo/bar' | ||
assert xleb.pathutils.normalize_abs_posixpath('/foo/bar') == '/foo/bar' | ||
|
||
assert xleb.pathutils.normalize_abs_posixpath('foo/../bar') == '/bar' | ||
assert xleb.pathutils.normalize_abs_posixpath('/foo/../bar') == '/bar' | ||
|
||
assert xleb.pathutils.normalize_abs_posixpath('..') == '/' | ||
assert xleb.pathutils.normalize_abs_posixpath('/..') == '/' | ||
|
||
assert xleb.pathutils.normalize_abs_posixpath('../foo') == '/foo' | ||
assert xleb.pathutils.normalize_abs_posixpath('/../foo') == '/foo' | ||
|
||
|
||
def test_posixpath_to_fspath(): | ||
"""Test pathutils webpath to fspath""" | ||
|
||
rootpath = '/foo/bar' | ||
|
||
assert xleb.pathutils.posixpath_to_fspath('', rootpath=rootpath) == '/foo/bar' | ||
assert xleb.pathutils.posixpath_to_fspath('/', rootpath=rootpath) == '/foo/bar' | ||
|
||
assert xleb.pathutils.posixpath_to_fspath('baz', rootpath=rootpath) == '/foo/bar/baz' | ||
assert xleb.pathutils.posixpath_to_fspath('/baz', rootpath=rootpath) == '/foo/bar/baz' | ||
|
||
assert xleb.pathutils.posixpath_to_fspath('baz/taz', rootpath=rootpath) == '/foo/bar/baz/taz' | ||
assert xleb.pathutils.posixpath_to_fspath('/baz/taz', rootpath=rootpath) == '/foo/bar/baz/taz' | ||
|
||
assert xleb.pathutils.posixpath_to_fspath('baz/../taz', rootpath=rootpath) == '/foo/bar/taz' | ||
assert xleb.pathutils.posixpath_to_fspath('/baz/../taz', rootpath=rootpath) == '/foo/bar/taz' | ||
|
||
assert xleb.pathutils.posixpath_to_fspath('..', rootpath=rootpath) == '/foo/bar' | ||
assert xleb.pathutils.posixpath_to_fspath('/..', rootpath=rootpath) == '/foo/bar' | ||
|
||
assert xleb.pathutils.posixpath_to_fspath('../taz', rootpath=rootpath) == '/foo/bar/taz' | ||
assert xleb.pathutils.posixpath_to_fspath('/../taz', rootpath=rootpath) == '/foo/bar/taz' | ||
|
||
rootpath = '/foo/bar/' | ||
|
||
assert xleb.pathutils.posixpath_to_fspath('', rootpath=rootpath) == '/foo/bar' | ||
assert xleb.pathutils.posixpath_to_fspath('/', rootpath=rootpath) == '/foo/bar' | ||
|
||
assert xleb.pathutils.posixpath_to_fspath('baz', rootpath=rootpath) == '/foo/bar/baz' | ||
assert xleb.pathutils.posixpath_to_fspath('/baz', rootpath=rootpath) == '/foo/bar/baz' | ||
|
||
assert xleb.pathutils.posixpath_to_fspath('baz/taz', rootpath=rootpath) == '/foo/bar/baz/taz' | ||
assert xleb.pathutils.posixpath_to_fspath('/baz/taz', rootpath=rootpath) == '/foo/bar/baz/taz' | ||
|
||
assert xleb.pathutils.posixpath_to_fspath('baz/../taz', rootpath=rootpath) == '/foo/bar/taz' | ||
assert xleb.pathutils.posixpath_to_fspath('/baz/../taz', rootpath=rootpath) == '/foo/bar/taz' | ||
|
||
assert xleb.pathutils.posixpath_to_fspath('..', rootpath=rootpath) == '/foo/bar' | ||
assert xleb.pathutils.posixpath_to_fspath('/..', rootpath=rootpath) == '/foo/bar' | ||
|
||
assert xleb.pathutils.posixpath_to_fspath('../taz', rootpath=rootpath) == '/foo/bar/taz' | ||
assert xleb.pathutils.posixpath_to_fspath('/../taz', rootpath=rootpath) == '/foo/bar/taz' | ||
|
||
|
||
def test_is_safe_path(): | ||
"""Test if given path is safe relative to the given rootdir""" | ||
|
||
rootpath = '/foo/bar' | ||
|
||
assert xleb.pathutils.is_safe_fspath('/foo/bar', rootpath=rootpath) == True | ||
assert xleb.pathutils.is_safe_fspath('/foo/bar/', rootpath=rootpath) == True | ||
|
||
assert xleb.pathutils.is_safe_fspath('/foo', rootpath=rootpath) == False | ||
assert xleb.pathutils.is_safe_fspath('/foo/', rootpath=rootpath) == False | ||
|
||
assert xleb.pathutils.is_safe_fspath('./foo', rootpath=rootpath) == False | ||
assert xleb.pathutils.is_safe_fspath('./foo/', rootpath=rootpath) == False | ||
|
||
assert xleb.pathutils.is_safe_fspath('../foo', rootpath=rootpath) == False | ||
assert xleb.pathutils.is_safe_fspath('../foo/', rootpath=rootpath) == False | ||
|
||
assert xleb.pathutils.is_safe_fspath('~/foo', rootpath=rootpath) == False | ||
assert xleb.pathutils.is_safe_fspath('~/foo/', rootpath=rootpath) == False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.