dirbrowser: move parent dir logic to own function
This commit is contained in:
parent
7fe4c7e06d
commit
5e73a2ea37
@ -68,6 +68,18 @@ def is_root(directory):
|
||||
return os.path.dirname(directory) == directory
|
||||
|
||||
|
||||
def parent_dir(directory):
|
||||
"""Return the parent directory for the given directory.
|
||||
|
||||
Args:
|
||||
directory: The path to the directory.
|
||||
|
||||
Return:
|
||||
The path to the parent directory.
|
||||
"""
|
||||
return os.path.normpath(os.path.join(directory, os.pardir))
|
||||
|
||||
|
||||
def dirbrowser_html(path):
|
||||
"""Get the directory browser web page.
|
||||
|
||||
@ -82,7 +94,7 @@ def dirbrowser_html(path):
|
||||
if is_root(path):
|
||||
parent = None
|
||||
else:
|
||||
parent = os.path.normpath(os.path.join(path, '..'))
|
||||
parent = parent_dir(path)
|
||||
|
||||
try:
|
||||
all_files = os.listdir(path)
|
||||
|
@ -77,6 +77,29 @@ class TestIsRoot:
|
||||
assert filescheme.is_root(directory) == is_root
|
||||
|
||||
|
||||
class TestParentDir:
|
||||
|
||||
@pytest.mark.windows
|
||||
@pytest.mark.parametrize('directory, parent', [
|
||||
('C:\\foo\\bar', 'C:\\foo'),
|
||||
('C:\\foo', 'C:\\'),
|
||||
('C:\\foo\\', 'C:\\'),
|
||||
('C:\\', 'C:\\'),
|
||||
])
|
||||
def test_windows(self, directory, parent):
|
||||
assert filescheme.parent_dir(directory) == parent
|
||||
|
||||
@pytest.mark.posix
|
||||
@pytest.mark.parametrize('directory, parent', [
|
||||
('/home/foo', '/home'),
|
||||
('/home', '/'),
|
||||
('/home/', '/'),
|
||||
('/', '/'),
|
||||
])
|
||||
def test_posix(self, directory, parent):
|
||||
assert filescheme.parent_dir(directory) == parent
|
||||
|
||||
|
||||
def _file_url(path):
|
||||
"""Return a file:// url (as string) for the given LocalPath.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user