From 6c5b69a23d0300fef19d807bad862f2cda56755a Mon Sep 17 00:00:00 2001 From: "Phyks (Lucas Verney)" Date: Sat, 30 Jan 2016 16:51:30 +0100 Subject: [PATCH] Unittests for fetcher --- libbmc/fetcher.py | 2 +- libbmc/papers/__init__.py | 5 ++--- libbmc/tests/test_fetcher.py | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 libbmc/tests/test_fetcher.py diff --git a/libbmc/fetcher.py b/libbmc/fetcher.py index e6ff516..f7473e4 100644 --- a/libbmc/fetcher.py +++ b/libbmc/fetcher.py @@ -26,7 +26,7 @@ def download(url, proxies=[None]): associated content-type. Returns ``(None, None)`` if it was \ unable to download the document. - # TODO: Unittests + >>> download("http://arxiv.org/pdf/1312.4006.pdf") # doctest: +SKIP """ # Loop over all available connections for proxy in proxies: diff --git a/libbmc/papers/__init__.py b/libbmc/papers/__init__.py index 7ba1b1f..047cc01 100644 --- a/libbmc/papers/__init__.py +++ b/libbmc/papers/__init__.py @@ -1,7 +1,6 @@ from . import identifiers -# TODO: Include tearpages - __all__ = [ - "identifiers" + "identifiers", + "tearpages" ] diff --git a/libbmc/tests/test_fetcher.py b/libbmc/tests/test_fetcher.py new file mode 100644 index 0000000..746d03a --- /dev/null +++ b/libbmc/tests/test_fetcher.py @@ -0,0 +1,15 @@ +import unittest +from libbmc.fetcher import * + + +class TestFetcher(unittest.TestCase): + def test_download(self): + dl, contenttype = download('http://arxiv.org/pdf/1312.4006.pdf') + self.assertIn(contenttype, ['pdf', 'djvu']) + self.assertNotEqual(dl, '') + + def test_download_invalid_type(self): + self.assertEqual(download('http://phyks.me/'), (None, None)) + + def test_download_invalid_url(self): + self.assertEqual(download('a'), (None, None))