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
This commit is contained in:
parent
814ce1bde2
commit
938a53b8f5
@ -36,8 +36,6 @@ matrix:
|
|||||||
# command to install dependencies
|
# command to install dependencies
|
||||||
install:
|
install:
|
||||||
- python --version
|
- python --version
|
||||||
- pip install -r tests/requirements.txt
|
|
||||||
- python setup.py install
|
|
||||||
|
|
||||||
# command to run tests
|
# command to run tests
|
||||||
script: python -m unittest discover
|
script: python setup.py test
|
||||||
|
@ -13,7 +13,7 @@ class ReferenceNotFoundError(Exception):
|
|||||||
pass
|
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.
|
"""Return a bibtex string from various ID methods.
|
||||||
|
|
||||||
This is a wrapper around functions that will return a bibtex string given
|
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_str: A string with the ID.
|
||||||
id_type: Name of the ID type. Must be one of `doi`, `isbn`, or `arxiv`.
|
id_type: Name of the ID type. Must be one of `doi`, `isbn`, or `arxiv`.
|
||||||
rp: A `Repository` object.
|
rp: A `Repository` object.
|
||||||
|
ui: A UI object.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A bibtex string.
|
A bibtex string.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ValueError: if `id_type` is not one of `doi`, `isbn`, or `arxiv`.
|
ValueError: if `id_type` is not one of `doi`, `isbn`, or `arxiv`.
|
||||||
|
apis.ReferenceNotFoundException: if no valid reference could be found.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
id_fns = {
|
id_fns = {
|
||||||
@ -69,7 +71,7 @@ def _get_request(url, headers=None):
|
|||||||
|
|
||||||
## DOI support
|
## DOI support
|
||||||
|
|
||||||
def doi2bibtex(doi):
|
def doi2bibtex(doi, **kwargs):
|
||||||
"""Return a bibtex string of metadata from a DOI"""
|
"""Return a bibtex string of metadata from a DOI"""
|
||||||
|
|
||||||
url = 'http://dx.doi.org/{}'.format(doi)
|
url = 'http://dx.doi.org/{}'.format(doi)
|
||||||
@ -83,7 +85,8 @@ def doi2bibtex(doi):
|
|||||||
|
|
||||||
## ISBN support
|
## ISBN support
|
||||||
|
|
||||||
def isbn2bibtex(isbn):
|
|
||||||
|
def isbn2bibtex(isbn, **kwargs):
|
||||||
"""Return a bibtex string of metadata from an ISBN"""
|
"""Return a bibtex string of metadata from an ISBN"""
|
||||||
|
|
||||||
url = 'http://www.ottobib.com/isbn/{}/bibtex'.format(isbn)
|
url = 'http://www.ottobib.com/isbn/{}/bibtex'.format(isbn)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
-e .
|
||||||
pyyaml
|
pyyaml
|
||||||
bibtexparser>=1.0
|
bibtexparser>=1.0
|
||||||
python-dateutil
|
python-dateutil
|
||||||
@ -5,3 +6,10 @@ requests
|
|||||||
configobj
|
configobj
|
||||||
beautifulsoup4
|
beautifulsoup4
|
||||||
feedparser
|
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
|
||||||
|
12
setup.py
12
setup.py
@ -1,10 +1,16 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
import unittest
|
||||||
|
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
with open('pubs/version.py') as f:
|
with open('pubs/version.py') as f:
|
||||||
exec(f.read()) # defines __version__
|
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(
|
setup(
|
||||||
name='pubs',
|
name='pubs',
|
||||||
version=__version__,
|
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'],
|
'requests', 'configobj', 'beautifulsoup4', 'feedparser'],
|
||||||
tests_require=['pyfakefs>=2.7', 'mock'],
|
|
||||||
extras_require={'autocompletion': ['argcomplete'],
|
extras_require={'autocompletion': ['argcomplete'],
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -41,6 +46,9 @@ setup(
|
|||||||
'Intended Audience :: Science/Research',
|
'Intended Audience :: Science/Research',
|
||||||
],
|
],
|
||||||
|
|
||||||
|
test_suite= 'tests',
|
||||||
|
tests_require=['pyfakefs>=3.4', 'mock', 'ddt'],
|
||||||
|
|
||||||
# in order to avoid 'zipimport.ZipImportError: bad local file header'
|
# in order to avoid 'zipimport.ZipImportError: bad local file header'
|
||||||
zip_safe=False,
|
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
|
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):
|
def setUp(self):
|
||||||
|
if not _is_connected():
|
||||||
|
self.skipTest('no connection detected, skiping test')
|
||||||
self.endecoder = EnDecoder()
|
self.endecoder = EnDecoder()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class TestDOI2Bibtex(APITests):
|
||||||
|
|
||||||
def test_unicode(self):
|
def test_unicode(self):
|
||||||
bib = doi2bibtex('10.1007/BF01700692')
|
bib = doi2bibtex('10.1007/BF01700692')
|
||||||
self.assertIsInstance(bib, ustr)
|
self.assertIsInstance(bib, ustr)
|
||||||
@ -37,10 +55,7 @@ class TestDOI2Bibtex(unittest.TestCase):
|
|||||||
doi2bibtex('999999')
|
doi2bibtex('999999')
|
||||||
|
|
||||||
|
|
||||||
class TestISBN2Bibtex(unittest.TestCase):
|
class TestISBN2Bibtex(APITests):
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.endecoder = EnDecoder()
|
|
||||||
|
|
||||||
def test_unicode(self):
|
def test_unicode(self):
|
||||||
bib = isbn2bibtex('9782081336742')
|
bib = isbn2bibtex('9782081336742')
|
||||||
@ -61,10 +76,7 @@ class TestISBN2Bibtex(unittest.TestCase):
|
|||||||
self.endecoder.decode_bibdata(bib)
|
self.endecoder.decode_bibdata(bib)
|
||||||
|
|
||||||
|
|
||||||
class TestArxiv2Bibtex(unittest.TestCase):
|
class TestArxiv2Bibtex(APITests):
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.endecoder = EnDecoder()
|
|
||||||
|
|
||||||
def test_parses_to_bibtex_with_doi(self):
|
def test_parses_to_bibtex_with_doi(self):
|
||||||
bib = arxiv2bibtex('astro-ph/9812133')
|
bib = arxiv2bibtex('astro-ph/9812133')
|
||||||
@ -85,6 +97,9 @@ class TestArxiv2Bibtex(unittest.TestCase):
|
|||||||
entry['title'],
|
entry['title'],
|
||||||
'The entropy formula for the Ricci flow and its geometric applications')
|
'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):
|
def test_oldstyle_pattern(self):
|
||||||
"""Test that we can accurately differentiate between old and new style arXiv ids."""
|
"""Test that we can accurately differentiate between old and new style arXiv ids."""
|
||||||
# old-style arXiv ids
|
# old-style arXiv ids
|
||||||
|
Loading…
x
Reference in New Issue
Block a user