2017-12-14 11:50:25 +00:00
|
|
|
import os
|
2018-01-12 17:52:20 +00:00
|
|
|
import pytest
|
|
|
|
from pydu.platform import WINDOWS
|
|
|
|
from pydu.path import cd, is_super_path
|
2017-12-14 11:50:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_cd(tmpdir):
|
|
|
|
path = str(tmpdir)
|
|
|
|
cwd = os.getcwd()
|
|
|
|
with cd(path):
|
|
|
|
assert os.getcwd() == path
|
|
|
|
assert os.getcwd() == cwd
|
2018-01-12 17:52:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestIsSupoerPath:
|
|
|
|
def test_is_super_path_general(self):
|
|
|
|
assert is_super_path('/aa/bb/cc', '/aa/bb/cc')
|
|
|
|
assert is_super_path('/aa/bb', '/aa/bb/cc')
|
|
|
|
assert is_super_path('/aa', '/aa/bb/cc')
|
|
|
|
assert is_super_path('/', '/aa/bb/cc')
|
|
|
|
assert is_super_path('/', '/')
|
|
|
|
assert not is_super_path('/a', '/aa/bb/cc')
|
|
|
|
|
|
|
|
@pytest.mark.skipif(not WINDOWS, reason='Not support on none-windows')
|
|
|
|
def test_is_super_path_win(self):
|
|
|
|
assert is_super_path('c:/aa/bb', 'c:/aa/bb\\cc')
|
|
|
|
assert is_super_path('c:/aa/bb', 'c:/aa\\bb/cc')
|
|
|
|
assert is_super_path('c:/aa\\bb', 'c:\\aa/bb/cc')
|
|
|
|
assert is_super_path('c:/', 'c:\\')
|