python setup.py test + no connection case

- Make `python setup.py test work`. remove test/requirements.txt.
  fix #154
- Detect if no connection is present, and skip tests if not.
  stop-gap measure for issue #147
main
Fabien C. Y. Benureau 7 years ago
parent 814ce1bde2
commit 938a53b8f5
No known key found for this signature in database
GPG Key ID: C3FB5E831A249A9A

@ -36,8 +36,6 @@ matrix:
# command to install dependencies
install:
- python --version
- pip install -r tests/requirements.txt
- python setup.py install
# command to run tests
script: python -m unittest discover
script: python setup.py test

@ -13,7 +13,7 @@ class ReferenceNotFoundError(Exception):
pass
def get_bibentry_from_api(id_str, id_type, rp):
def get_bibentry_from_api(id_str, id_type, rp, ui=None):
"""Return a bibtex string from various ID methods.
This is a wrapper around functions that will return a bibtex string given
@ -27,12 +27,14 @@ def get_bibentry_from_api(id_str, id_type, rp):
id_str: A string with the ID.
id_type: Name of the ID type. Must be one of `doi`, `isbn`, or `arxiv`.
rp: A `Repository` object.
ui: A UI object.
Returns:
A bibtex string.
Raises:
ValueError: if `id_type` is not one of `doi`, `isbn`, or `arxiv`.
apis.ReferenceNotFoundException: if no valid reference could be found.
"""
id_fns = {
@ -69,7 +71,7 @@ def _get_request(url, headers=None):
## DOI support
def doi2bibtex(doi):
def doi2bibtex(doi, **kwargs):
"""Return a bibtex string of metadata from a DOI"""
url = 'http://dx.doi.org/{}'.format(doi)
@ -83,7 +85,8 @@ def doi2bibtex(doi):
## ISBN support
def isbn2bibtex(isbn):
def isbn2bibtex(isbn, **kwargs):
"""Return a bibtex string of metadata from an ISBN"""
url = 'http://www.ottobib.com/isbn/{}/bibtex'.format(isbn)

@ -1,3 +1,4 @@
-e .
pyyaml
bibtexparser>=1.0
python-dateutil
@ -5,3 +6,10 @@ requests
configobj
beautifulsoup4
feedparser
six
# those are the additional packages required to run the tests
pyfakefs
ddt
mock
pytest # optional (python setup.py test works without it), but possible nonetheless

@ -1,10 +1,16 @@
#!/usr/bin/env python
import unittest
from setuptools import setup
with open('pubs/version.py') as f:
exec(f.read()) # defines __version__
def pubs_test_suite():
test_loader = unittest.TestLoader()
test_suite = test_loader.discover('tests', pattern='test_*.py')
return test_suite
setup(
name='pubs',
version=__version__,
@ -26,9 +32,8 @@ setup(
],
},
install_requires=['pyyaml', 'bibtexparser>=1.0', 'python-dateutil',
install_requires=['pyyaml', 'bibtexparser>=1.0', 'python-dateutil', 'six',
'requests', 'configobj', 'beautifulsoup4', 'feedparser'],
tests_require=['pyfakefs>=2.7', 'mock'],
extras_require={'autocompletion': ['argcomplete'],
},
@ -41,6 +46,9 @@ setup(
'Intended Audience :: Science/Research',
],
test_suite= 'tests',
tests_require=['pyfakefs>=3.4', 'mock', 'ddt'],
# in order to avoid 'zipimport.ZipImportError: bad local file header'
zip_safe=False,

@ -1,5 +0,0 @@
# those are the additional packages required to run the tests
six
pyfakefs
ddt
mock

@ -12,11 +12,29 @@ from pubs.apis import ReferenceNotFoundError, arxiv2bibtex, doi2bibtex, isbn2bib
from pubs import apis
class TestDOI2Bibtex(unittest.TestCase):
def _is_connected():
"""Return False if no internet connection is detected.
May not work if the local network redirects the connection.
"""
try:
host = socket.gethostbyname('www.google.com')
s = socket.create_connection((host, 80), 2)
return True
except:
return False
class APITests(unittest.TestCase):
def setUp(self):
if not _is_connected():
self.skipTest('no connection detected, skiping test')
self.endecoder = EnDecoder()
class TestDOI2Bibtex(APITests):
def test_unicode(self):
bib = doi2bibtex('10.1007/BF01700692')
self.assertIsInstance(bib, ustr)
@ -37,10 +55,7 @@ class TestDOI2Bibtex(unittest.TestCase):
doi2bibtex('999999')
class TestISBN2Bibtex(unittest.TestCase):
def setUp(self):
self.endecoder = EnDecoder()
class TestISBN2Bibtex(APITests):
def test_unicode(self):
bib = isbn2bibtex('9782081336742')
@ -61,10 +76,7 @@ class TestISBN2Bibtex(unittest.TestCase):
self.endecoder.decode_bibdata(bib)
class TestArxiv2Bibtex(unittest.TestCase):
def setUp(self):
self.endecoder = EnDecoder()
class TestArxiv2Bibtex(APITests):
def test_parses_to_bibtex_with_doi(self):
bib = arxiv2bibtex('astro-ph/9812133')
@ -85,6 +97,9 @@ class TestArxiv2Bibtex(unittest.TestCase):
entry['title'],
'The entropy formula for the Ricci flow and its geometric applications')
class TestArxiv2BibtexLocal(unittest.TestCase):
"""Test arXiv 2 Bibtex connection; those tests don't require a connection"""
def test_oldstyle_pattern(self):
"""Test that we can accurately differentiate between old and new style arXiv ids."""
# old-style arXiv ids

Loading…
Cancel
Save