tests/dirbrowser: move parse out of DirLayout

This commit is contained in:
Daniel Schadt 2016-03-29 12:43:50 +02:00
parent 2db5b95552
commit f085eb6eca

View File

@ -33,9 +33,6 @@ class DirLayout:
"""Provide a fake directory layout to test dirbrowser.""" """Provide a fake directory layout to test dirbrowser."""
Parsed = collections.namedtuple('Parsed', 'path, parent, folders, files')
Item = collections.namedtuple('Item', 'path, link, text')
LAYOUT = [ LAYOUT = [
'folder0/file00', 'folder0/file00',
'folder0/file01', 'folder0/file01',
@ -99,7 +96,12 @@ class DirLayout:
"""Return the path of the base temporary folder.""" """Return the path of the base temporary folder."""
return os.path.normpath(str(self.base)) return os.path.normpath(str(self.base))
def parse(self, quteproc):
Parsed = collections.namedtuple('Parsed', 'path, parent, folders, files')
Item = collections.namedtuple('Item', 'path, link, text')
def parse(quteproc):
"""Parse the dirbrowser content from the given quteproc. """Parse the dirbrowser content from the given quteproc.
Args: Args:
@ -130,10 +132,10 @@ class DirLayout:
for li in container('ul', class_=css_class)[0]('li'): for li in container('ul', class_=css_class)[0]('li'):
item_path = QUrl(li.a['href']).toLocalFile() item_path = QUrl(li.a['href']).toLocalFile()
item_path = os.path.normpath(item_path) item_path = os.path.normpath(item_path)
list_.append(self.Item(path=item_path, link=li.a['href'], list_.append(Item(path=item_path, link=li.a['href'],
text=str(li.a.string))) text=str(li.a.string)))
return self.Parsed(path=path, parent=parent, folders=folders, return Parsed(path=path, parent=parent, folders=folders,
files=files) files=files)
@ -144,14 +146,14 @@ def dir_layout(tmpdir_factory):
def test_parent_folder(dir_layout, quteproc): def test_parent_folder(dir_layout, quteproc):
quteproc.open_url(dir_layout.file_url()) quteproc.open_url(dir_layout.file_url())
page = dir_layout.parse(quteproc) page = parse(quteproc)
assert page.parent == dir_layout.base_path() assert page.parent == dir_layout.base_path()
def test_parent_with_slash(dir_layout, quteproc): def test_parent_with_slash(dir_layout, quteproc):
"""Test the parent link with an URL that has a trailing slash.""" """Test the parent link with an URL that has a trailing slash."""
quteproc.open_url(dir_layout.file_url() + '/') quteproc.open_url(dir_layout.file_url() + '/')
page = dir_layout.parse(quteproc) page = parse(quteproc)
assert page.parent == dir_layout.base_path() assert page.parent == dir_layout.base_path()
@ -160,7 +162,7 @@ def test_parent_in_root_dir(dir_layout, quteproc):
root_path = os.path.realpath('/') root_path = os.path.realpath('/')
urlstr = QUrl.fromLocalFile(root_path).toString(QUrl.FullyEncoded) urlstr = QUrl.fromLocalFile(root_path).toString(QUrl.FullyEncoded)
quteproc.open_url(urlstr) quteproc.open_url(urlstr)
page = dir_layout.parse(quteproc) page = parse(quteproc)
assert page.parent is None assert page.parent is None
@ -169,7 +171,7 @@ def test_enter_folder_smoke(dir_layout, quteproc):
quteproc.send_cmd(':hint all normal') quteproc.send_cmd(':hint all normal')
# a is the parent link, s is the first listed folder/file # a is the parent link, s is the first listed folder/file
quteproc.send_cmd(':follow-hint s') quteproc.send_cmd(':follow-hint s')
page = dir_layout.parse(quteproc) page = parse(quteproc)
assert page.path == dir_layout.path('folder0') assert page.path == dir_layout.path('folder0')
@ -183,7 +185,7 @@ def test_enter_folder(dir_layout, quteproc, folder):
'XPathResult.ANY_TYPE, null).iterateNext().click()' 'XPathResult.ANY_TYPE, null).iterateNext().click()'
.format(folder) .format(folder)
) )
page = dir_layout.parse(quteproc) page = parse(quteproc)
assert page.path == dir_layout.path(folder) assert page.path == dir_layout.path(folder)
assert page.parent == dir_layout.path() assert page.parent == dir_layout.path()
folders, files = DirLayout.get_folder_content(folder) folders, files = DirLayout.get_folder_content(folder)