Fix docstrings

This commit is contained in:
Florian Bruhin 2016-05-07 22:15:27 +02:00
parent eb5bfc1659
commit 1a03388fb5

View File

@ -98,8 +98,9 @@ class FakeDownloadManager:
"""Mock browser.downloads.DownloadManager.""" """Mock browser.downloads.DownloadManager."""
def get(self, url, fileobj, **kwargs): def get(self, url, fileobj, **kwargs):
"""Return a FakeDownloadItem instance with a fileobj """Return a FakeDownloadItem instance with a fileobj.
whose content is copied from the file the given url links to.
The content is copied from the file the given url links to.
""" """
download_item = FakeDownloadItem(fileobj, name=url.path()) download_item = FakeDownloadItem(fileobj, name=url.path())
with open(url.path(), 'rb') as fake_url_file: with open(url.path(), 'rb') as fake_url_file:
@ -118,12 +119,12 @@ def download_stub(win_registry):
def create_zipfile(directory, files, zipname='test'): def create_zipfile(directory, files, zipname='test'):
"""Return a path to a newly created zip file """Return a path to a newly created zip file.
Args: Args:
- directory : path object where to create the zip file directory: path object where to create the zip file
- files : list of paths to each file to add in the zipfile files: list of paths to each file to add in the zipfile
- zipname : name to give to the zip file. zipname: name to give to the zip file.
""" """
zipfile_path = directory / zipname + '.zip' zipfile_path = directory / zipname + '.zip'
with zipfile.ZipFile(str(zipfile_path), 'w') as new_zipfile: with zipfile.ZipFile(str(zipfile_path), 'w') as new_zipfile:
@ -139,10 +140,10 @@ def create_blocklist(directory, blocked_hosts=BLOCKLIST_HOSTS,
"""Return a path to a blocklist file. """Return a path to a blocklist file.
Args: Args:
- directory : path object where to create the blocklist file directory: path object where to create the blocklist file
- blocked_hosts : an iterable of string hosts to add to the blocklist blocked_hosts: an iterable of string hosts to add to the blocklist
- name : name to give to the blocklist file name: name to give to the blocklist file
- line_format : 'etc_hosts' --> /etc/hosts format line_format: 'etc_hosts' --> /etc/hosts format
'one_per_line' --> one host per line format 'one_per_line' --> one host per line format
'not_correct' --> Not a correct hosts file format. 'not_correct' --> Not a correct hosts file format.
""" """
@ -166,9 +167,11 @@ def create_blocklist(directory, blocked_hosts=BLOCKLIST_HOSTS,
def assert_urls(host_blocker, blocked=BLOCKLIST_HOSTS, def assert_urls(host_blocker, blocked=BLOCKLIST_HOSTS,
whitelisted=WHITELISTED_HOSTS, urls_to_check=URLS_TO_CHECK): whitelisted=WHITELISTED_HOSTS, urls_to_check=URLS_TO_CHECK):
"""Test if Urls to check are blocked or not by HostBlocker """Test if Urls to check are blocked or not by HostBlocker.
Ensure Urls in blocked and not in whitelisted are blocked
All other Urls must not be blocked.""" Ensure URLs in 'blocked' and not in 'whitelisted' are blocked.
All other URLs must not be blocked.
"""
whitelisted = list(whitelisted) + list(host_blocker.WHITELISTED) whitelisted = list(whitelisted) + list(host_blocker.WHITELISTED)
for str_url in urls_to_check: for str_url in urls_to_check:
url = QUrl(str_url) url = QUrl(str_url)
@ -181,13 +184,15 @@ def assert_urls(host_blocker, blocked=BLOCKLIST_HOSTS,
def generic_blocklists(directory): def generic_blocklists(directory):
"""Return a generic list of files to be used in hosts-block-lists option. """Return a generic list of files to be used in hosts-block-lists option.
This list contains : This list contains :
- a remote zip file with 1 hosts file and 2 useless files - a remote zip file with 1 hosts file and 2 useless files
- a remote zip file with only useless files - a remote zip file with only useless files
(Should raise a FileNotFoundError) (Should raise a FileNotFoundError)
- a remote zip file with only one valid hosts file - a remote zip file with only one valid hosts file
- a local text file with valid hosts - a local text file with valid hosts
- a remote text file without valid hosts format.""" - a remote text file without valid hosts format.
"""
# remote zip file with 1 hosts file and 2 useless files # remote zip file with 1 hosts file and 2 useless files
file1 = create_blocklist(directory, blocked_hosts=CLEAN_HOSTS, file1 = create_blocklist(directory, blocked_hosts=CLEAN_HOSTS,
@ -233,7 +238,9 @@ def generic_blocklists(directory):
def test_without_datadir(config_stub, tmpdir, monkeypatch, win_registry): def test_without_datadir(config_stub, tmpdir, monkeypatch, win_registry):
"""No directory for data configured so no hosts file exists. """No directory for data configured so no hosts file exists.
Ensure CommandError is raised and no Url is blocked."""
Ensure CommandError is raised and no URL is blocked.
"""
config_stub.data = {'content': config_stub.data = {'content':
{'host-block-lists': generic_blocklists(tmpdir), {'host-block-lists': generic_blocklists(tmpdir),
'host-blocking-enabled': True}} 'host-blocking-enabled': True}}
@ -264,7 +271,7 @@ def test_disabled_blocking_update(basedir, config_stub, download_stub,
def test_no_blocklist_update(config_stub, download_stub, def test_no_blocklist_update(config_stub, download_stub,
data_tmpdir, basedir, tmpdir, win_registry): data_tmpdir, basedir, tmpdir, win_registry):
"""Ensure no Url is blocked when no block list exists.""" """Ensure no URL is blocked when no block list exists."""
config_stub.data = {'content': config_stub.data = {'content':
{'host-block-lists': None, {'host-block-lists': None,
'host-blocking-enabled': True}} 'host-blocking-enabled': True}}
@ -295,7 +302,9 @@ def test_successful_update(config_stub, basedir, download_stub,
def test_failed_dl_update(config_stub, basedir, download_stub, def test_failed_dl_update(config_stub, basedir, download_stub,
data_tmpdir, tmpdir, win_registry): data_tmpdir, tmpdir, win_registry):
"""One blocklist fails to download. """One blocklist fails to download.
Ensure hosts from this list are not blocked."""
Ensure hosts from this list are not blocked.
"""
dl_fail_blocklist = QUrl(create_blocklist(tmpdir, dl_fail_blocklist = QUrl(create_blocklist(tmpdir,
blocked_hosts=CLEAN_HOSTS, blocked_hosts=CLEAN_HOSTS,
name='download_will_fail', name='download_will_fail',