Simplify usage of tabhistory.TabHistoryItem.

This commit is contained in:
Florian Bruhin 2015-08-23 18:16:19 +02:00
parent ece2786d40
commit 6d8854bc07
2 changed files with 15 additions and 15 deletions

View File

@ -35,14 +35,19 @@ class TabHistoryItem:
Attributes:
url: The QUrl of this item.
original_url: The QUrl of this item which was originally requested.
title: The title as string of this item.
active: Whether this item is the item currently navigated to.
user_data: The user data for this item.
"""
def __init__(self, url, original_url, title, active=False, user_data=None):
def __init__(self, url, title, *, original_url=None, active=False,
user_data=None):
self.url = url
self.original_url = original_url
if original_url is None:
self.original_url = url
else:
self.original_url = original_url
self.title = title
self.active = active
self.user_data = user_data

View File

@ -30,23 +30,18 @@ from qutebrowser.utils import qtutils
ITEMS = [
Item(QUrl('https://www.heise.de/'), QUrl('http://www.heise.de/'), 'heise'),
Item(QUrl('http://example.com/%E2%80%A6'),
QUrl('http://example.com/%E2%80%A6'), 'percent', active=True),
Item(QUrl('http://example.com/?foo=bar'),
QUrl('http://original.url.example.com/'), 'arg',
Item(QUrl('https://www.heise.de/'), 'heise'),
Item(QUrl('http://example.com/%E2%80%A6'), 'percent', active=True),
Item(QUrl('http://example.com/?foo=bar'), 'arg',
original_url=QUrl('http://original.url.example.com/'),
user_data={'foo': 23, 'bar': 42}),
# From https://github.com/OtterBrowser/otter-browser/issues/709#issuecomment-74749471
Item(QUrl('http://github.com/OtterBrowser/24/134/2344/otter-browser/'
'issues/709/'),
QUrl('http://github.com/OtterBrowser/24/134/2344/otter-browser/'
'issues/709/'),
'Page not found | github',
user_data={'zoom': 149, 'scroll-pos': QPoint(0, 0)}),
Item(QUrl('https://mail.google.com/mail/u/0/#label/some+label/'
'234lkjsd0932lkjf884jqwerdf4'),
QUrl('https://mail.google.com/mail/u/0/#label/some+label/'
'234lkjsd0932lkjf884jqwerdf4'),
'"some label" - email@gmail.com - Gmail"',
user_data={'zoom': 120, 'scroll-pos': QPoint(0, 0)}),
]
@ -119,16 +114,16 @@ def test_titles(objects, i, item):
def test_no_active_item():
"""Check tabhistory.serialize with no active item."""
items = [Item(QUrl(), QUrl(), '')]
items = [Item(QUrl(), '')]
with pytest.raises(ValueError):
tabhistory.serialize(items)
def test_two_active_items():
"""Check tabhistory.serialize with two active items."""
items = [Item(QUrl(), QUrl(), '', active=True),
Item(QUrl(), QUrl(), ''),
Item(QUrl(), QUrl(), '', active=True)]
items = [Item(QUrl(), '', active=True),
Item(QUrl(), ''),
Item(QUrl(), '', active=True)]
with pytest.raises(ValueError):
tabhistory.serialize(items)