diff --git a/.travis.yml b/.travis.yml index f10b731..16e69a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,4 +39,8 @@ install: - export PUBS_TESTS_MODE=ONLINE # command to run tests -script: python setup.py test +script: + - export PUBS_TESTS_MODE=ONLINE + - python setup.py test + - export PUBS_TESTS_MODE=MOCK + - python setup.py test diff --git a/readme.md b/readme.md index 4b03dcd..5b43e56 100644 --- a/readme.md +++ b/readme.md @@ -56,6 +56,10 @@ or an ISBN (dashes are ignored): pubs add -I 978-0822324669 -d article.pdf +or an arXiv id (automatically downloading arXiv article is in the works): + + pubs add -X math/9501234 -d article.pdf + ## References always up-to-date diff --git a/tests/mock_requests.py b/tests/mock_requests.py index a9ff9ab..3eb72ca 100644 --- a/tests/mock_requests.py +++ b/tests/mock_requests.py @@ -8,11 +8,11 @@ $ export PUBS_TESTS_MODE=COLLECT $ export PUBS_TESTS_MODE=ONLINE The MOCK mode is the default one, active even if PUBS_TESTS_MODE has not been -set. It use prefetched data to run pubs units tests relying on the `requests.get` +set. It uses saved data to run pubs units tests relying on the `requests.get` function without the need of an internet connection (it is also much faster). The prefected data is save in the `test_apis_data.pickle` file. -The COLLECT mode does real GET requests, and update the `test_apis_data.pickle` +The COLLECT mode does real GET requests, and updates the `test_apis_data.pickle` file. It is needed if you add or modify the test relying on `requests.get`. The ONLINE mode bypasses all this and use the original `requests.get` without @@ -22,17 +22,14 @@ running tests on Travis for instance. import os -try: - import cPickle as pickle -except ImportError: - import pickle +import json import requests _orgininal_requests_get = requests.get _collected_responses = [] -_data_filepath = os.path.join(os.path.dirname(__file__), 'test_apis_data.pickle') +_data_filepath = os.path.join(os.path.dirname(__file__), 'test_apis_data.json') class MockingResponse: def __init__(self, text, status_code=200, error_msg=None): @@ -50,12 +47,12 @@ mode = os.environ.get('PUBS_TESTS_MODE', 'MOCK') if mode == 'MOCK': - with open(os.path.join(_data_filepath), 'rb') as fd: - _collected_responses.extend(pickle.load(fd)) + with open(os.path.join(_data_filepath), 'r') as fd: + _collected_responses = json.load(fd) def mock_requests_get(*args, **kwargs): for args2, kwargs2, text, status_code, error_msg in _collected_responses: - if args == args2 and kwargs == kwargs2: + if list(args) == list(args2) and kwargs == kwargs2: return MockingResponse(text, status_code, error_msg) raise KeyError(('No stub data found for requests.get({}, {}).\n You may' ' need to update the mock data. Look at the ' @@ -71,7 +68,6 @@ elif mode == 'COLLECT': r.raise_for_status() except requests.exceptions.RequestException as e: error_msg = str(e) - key = (sorted(args), sorted((k, v) for k, v in kwargs.items())) _collected_responses.append((args, kwargs, text, status_code, error_msg)) _save_collected_responses() # yes, we save everytime, because it's not @@ -81,8 +77,8 @@ elif mode == 'COLLECT': return MockingResponse(text, status_code, error_msg) def _save_collected_responses(): - with open(os.path.join(_data_filepath), 'wb') as fd: - pickle.dump(_collected_responses, fd, protocol=2) + with open(os.path.join(_data_filepath), 'w') as fd: + json.dump(_collected_responses, fd) elif mode == 'ONLINE': def mock_requests_get(*args, **kwargs): diff --git a/tests/test_apis.py b/tests/test_apis.py index e3651e4..67a76b5 100644 --- a/tests/test_apis.py +++ b/tests/test_apis.py @@ -2,7 +2,6 @@ from __future__ import unicode_literals import unittest -import socket import mock @@ -18,26 +17,9 @@ from pubs import apis import mock_requests -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) - s.close() - return True - except socket.error: - pass - return False - - class APITests(unittest.TestCase): def setUp(self): - # if not _is_connected(): - # self.skipTest('no connection detected, skiping test') self.endecoder = EnDecoder() diff --git a/tests/test_apis_data.json b/tests/test_apis_data.json new file mode 100644 index 0000000..42daa8c --- /dev/null +++ b/tests/test_apis_data.json @@ -0,0 +1 @@ +[[["https://export.arxiv.org/api/query?id_list=astro-ph/9812133"], {}, "\n\n \n ArXiv Query: search_query=&id_list=astro-ph/9812133&start=0&max_results=10\n http://arxiv.org/api/SfKekabpSjI/htnxCLpK3q9AsUs\n 2018-08-09T00:00:00-04:00\n 1\n 0\n 10\n \n http://arxiv.org/abs/astro-ph/9812133v1\n 1998-12-08T03:27:34Z\n 1998-12-08T03:27:34Z\n Measurements of Omega and Lambda from 42 High-Redshift Supernovae\n We report measurements of the mass density, Omega_M, and\ncosmological-constant energy density, Omega_Lambda, of the universe based on\nthe analysis of 42 Type Ia supernovae discovered by the Supernova Cosmology\nProject. The magnitude-redshift data for these SNe, at redshifts between 0.18\nand 0.83, are fit jointly with a set of SNe from the Calan/Tololo Supernova\nSurvey, at redshifts below 0.1, to yield values for the cosmological\nparameters. All SN peak magnitudes are standardized using a SN Ia lightcurve\nwidth-luminosity relation. The measurement yields a joint probability\ndistribution of the cosmological parameters that is approximated by the\nrelation 0.8 Omega_M - 0.6 Omega_Lambda ~= -0.2 +/- 0.1 in the region of\ninterest (Omega_M <~ 1.5). For a flat (Omega_M + Omega_Lambda = 1) cosmology we\nfind Omega_M = 0.28{+0.09,-0.08} (1 sigma statistical) {+0.05,-0.04}\n(identified systematics). The data are strongly inconsistent with a Lambda = 0\nflat cosmology, the simplest inflationary universe model. An open, Lambda = 0\ncosmology also does not fit the data well: the data indicate that the\ncosmological constant is non-zero and positive, with a confidence of P(Lambda >\n0) = 99%, including the identified systematic uncertainties. The best-fit age\nof the universe relative to the Hubble time is t_0 = 14.9{+1.4,-1.1} (0.63/h)\nGyr for a flat cosmology. The size of our sample allows us to perform a variety\nof statistical tests to check for possible systematic errors and biases. We\nfind no significant differences in either the host reddening distribution or\nMalmquist bias between the low-redshift Calan/Tololo sample and our\nhigh-redshift sample. The conclusions are robust whether or not a\nwidth-luminosity relation is used to standardize the SN peak magnitudes.\n\n \n S. Perlmutter\n The Supernova Cosmology Project\n \n \n G. Aldering\n The Supernova Cosmology Project\n \n \n G. Goldhaber\n The Supernova Cosmology Project\n \n \n R. A. Knop\n The Supernova Cosmology Project\n \n \n P. Nugent\n The Supernova Cosmology Project\n \n \n P. G. Castro\n The Supernova Cosmology Project\n \n \n S. Deustua\n The Supernova Cosmology Project\n \n \n S. Fabbro\n The Supernova Cosmology Project\n \n \n A. Goobar\n The Supernova Cosmology Project\n \n \n D. E. Groom\n The Supernova Cosmology Project\n \n \n I. M. Hook\n The Supernova Cosmology Project\n \n \n A. G. Kim\n The Supernova Cosmology Project\n \n \n M. Y. Kim\n The Supernova Cosmology Project\n \n \n J. C. Lee\n The Supernova Cosmology Project\n \n \n N. J. Nunes\n The Supernova Cosmology Project\n \n \n R. Pain\n The Supernova Cosmology Project\n \n \n C. R. Pennypacker\n The Supernova Cosmology Project\n \n \n R. Quimby\n The Supernova Cosmology Project\n \n \n C. Lidman\n The Supernova Cosmology Project\n \n \n R. S. Ellis\n The Supernova Cosmology Project\n \n \n M. Irwin\n The Supernova Cosmology Project\n \n \n R. G. McMahon\n The Supernova Cosmology Project\n \n \n P. Ruiz-Lapuente\n The Supernova Cosmology Project\n \n \n N. Walton\n The Supernova Cosmology Project\n \n \n B. Schaefer\n The Supernova Cosmology Project\n \n \n B. J. Boyle\n The Supernova Cosmology Project\n \n \n A. V. Filippenko\n The Supernova Cosmology Project\n \n \n T. Matheson\n The Supernova Cosmology Project\n \n \n A. S. Fruchter\n The Supernova Cosmology Project\n \n \n N. Panagia\n The Supernova Cosmology Project\n \n \n H. J. M. Newberg\n The Supernova Cosmology Project\n \n \n W. J. Couch\n The Supernova Cosmology Project\n \n 10.1086/307221\n \n 21 pages and 10 figures. Accepted for publication in the\n Astrophysical Journal. Individual color figures, supplementary tables, and\n preprint also available at http://www-supernova.lbl.gov/\n Astrophys.J.517:565-586,1999\n \n \n \n \n \n \n \n\n", 200, null], [["http://dx.doi.org/10.1086/307221"], {"headers": {"accept": "application/x-bibtex"}}, "@article{Perlmutter_1999,\n\tdoi = {10.1086/307221},\n\turl = {https://doi.org/10.1086%2F307221},\n\tyear = 1999,\n\tmonth = {jun},\n\tpublisher = {{IOP} Publishing},\n\tvolume = {517},\n\tnumber = {2},\n\tpages = {565--586},\n\tauthor = {S. Perlmutter and G. Aldering and G. Goldhaber and R. A. Knop and P. Nugent and P. G. Castro and S. Deustua and S. Fabbro and A. Goobar and D. E. Groom and I. M. Hook and A. G. Kim and M. Y. Kim and J. C. Lee and N. J. Nunes and R. Pain and C. R. Pennypacker and R. Quimby and C. Lidman and R. S. Ellis and M. Irwin and R. G. McMahon and P. Ruiz-Lapuente and N. Walton and B. Schaefer and B. J. Boyle and A. V. Filippenko and T. Matheson and A. S. Fruchter and N. Panagia and H. J. M. Newberg and W. J. Couch and The Supernova Cosmology Project},\n\ttitle = {Measurements of $\\{upOmega}$ and $\\{upLambda}$ from 42 High-Redshift Supernovae},\n\tjournal = {The Astrophysical Journal}\n}", 200, null], [["https://export.arxiv.org/api/query?id_list=astro-ph/9812133"], {}, "\n\n \n ArXiv Query: search_query=&id_list=astro-ph/9812133&start=0&max_results=10\n http://arxiv.org/api/SfKekabpSjI/htnxCLpK3q9AsUs\n 2018-08-09T00:00:00-04:00\n 1\n 0\n 10\n \n http://arxiv.org/abs/astro-ph/9812133v1\n 1998-12-08T03:27:34Z\n 1998-12-08T03:27:34Z\n Measurements of Omega and Lambda from 42 High-Redshift Supernovae\n We report measurements of the mass density, Omega_M, and\ncosmological-constant energy density, Omega_Lambda, of the universe based on\nthe analysis of 42 Type Ia supernovae discovered by the Supernova Cosmology\nProject. The magnitude-redshift data for these SNe, at redshifts between 0.18\nand 0.83, are fit jointly with a set of SNe from the Calan/Tololo Supernova\nSurvey, at redshifts below 0.1, to yield values for the cosmological\nparameters. All SN peak magnitudes are standardized using a SN Ia lightcurve\nwidth-luminosity relation. The measurement yields a joint probability\ndistribution of the cosmological parameters that is approximated by the\nrelation 0.8 Omega_M - 0.6 Omega_Lambda ~= -0.2 +/- 0.1 in the region of\ninterest (Omega_M <~ 1.5). For a flat (Omega_M + Omega_Lambda = 1) cosmology we\nfind Omega_M = 0.28{+0.09,-0.08} (1 sigma statistical) {+0.05,-0.04}\n(identified systematics). The data are strongly inconsistent with a Lambda = 0\nflat cosmology, the simplest inflationary universe model. An open, Lambda = 0\ncosmology also does not fit the data well: the data indicate that the\ncosmological constant is non-zero and positive, with a confidence of P(Lambda >\n0) = 99%, including the identified systematic uncertainties. The best-fit age\nof the universe relative to the Hubble time is t_0 = 14.9{+1.4,-1.1} (0.63/h)\nGyr for a flat cosmology. The size of our sample allows us to perform a variety\nof statistical tests to check for possible systematic errors and biases. We\nfind no significant differences in either the host reddening distribution or\nMalmquist bias between the low-redshift Calan/Tololo sample and our\nhigh-redshift sample. The conclusions are robust whether or not a\nwidth-luminosity relation is used to standardize the SN peak magnitudes.\n\n \n S. Perlmutter\n The Supernova Cosmology Project\n \n \n G. Aldering\n The Supernova Cosmology Project\n \n \n G. Goldhaber\n The Supernova Cosmology Project\n \n \n R. A. Knop\n The Supernova Cosmology Project\n \n \n P. Nugent\n The Supernova Cosmology Project\n \n \n P. G. Castro\n The Supernova Cosmology Project\n \n \n S. Deustua\n The Supernova Cosmology Project\n \n \n S. Fabbro\n The Supernova Cosmology Project\n \n \n A. Goobar\n The Supernova Cosmology Project\n \n \n D. E. Groom\n The Supernova Cosmology Project\n \n \n I. M. Hook\n The Supernova Cosmology Project\n \n \n A. G. Kim\n The Supernova Cosmology Project\n \n \n M. Y. Kim\n The Supernova Cosmology Project\n \n \n J. C. Lee\n The Supernova Cosmology Project\n \n \n N. J. Nunes\n The Supernova Cosmology Project\n \n \n R. Pain\n The Supernova Cosmology Project\n \n \n C. R. Pennypacker\n The Supernova Cosmology Project\n \n \n R. Quimby\n The Supernova Cosmology Project\n \n \n C. Lidman\n The Supernova Cosmology Project\n \n \n R. S. Ellis\n The Supernova Cosmology Project\n \n \n M. Irwin\n The Supernova Cosmology Project\n \n \n R. G. McMahon\n The Supernova Cosmology Project\n \n \n P. Ruiz-Lapuente\n The Supernova Cosmology Project\n \n \n N. Walton\n The Supernova Cosmology Project\n \n \n B. Schaefer\n The Supernova Cosmology Project\n \n \n B. J. Boyle\n The Supernova Cosmology Project\n \n \n A. V. Filippenko\n The Supernova Cosmology Project\n \n \n T. Matheson\n The Supernova Cosmology Project\n \n \n A. S. Fruchter\n The Supernova Cosmology Project\n \n \n N. Panagia\n The Supernova Cosmology Project\n \n \n H. J. M. Newberg\n The Supernova Cosmology Project\n \n \n W. J. Couch\n The Supernova Cosmology Project\n \n 10.1086/307221\n \n 21 pages and 10 figures. Accepted for publication in the\n Astrophysical Journal. Individual color figures, supplementary tables, and\n preprint also available at http://www-supernova.lbl.gov/\n Astrophys.J.517:565-586,1999\n \n \n \n \n \n \n \n\n", 200, null], [["http://dx.doi.org/10.1086/307221"], {"headers": {"accept": "application/x-bibtex"}}, "@article{Perlmutter_1999,\n\tdoi = {10.1086/307221},\n\turl = {https://doi.org/10.1086%2F307221},\n\tyear = 1999,\n\tmonth = {jun},\n\tpublisher = {{IOP} Publishing},\n\tvolume = {517},\n\tnumber = {2},\n\tpages = {565--586},\n\tauthor = {S. Perlmutter and G. Aldering and G. Goldhaber and R. A. Knop and P. Nugent and P. G. Castro and S. Deustua and S. Fabbro and A. Goobar and D. E. Groom and I. M. Hook and A. G. Kim and M. Y. Kim and J. C. Lee and N. J. Nunes and R. Pain and C. R. Pennypacker and R. Quimby and C. Lidman and R. S. Ellis and M. Irwin and R. G. McMahon and P. Ruiz-Lapuente and N. Walton and B. Schaefer and B. J. Boyle and A. V. Filippenko and T. Matheson and A. S. Fruchter and N. Panagia and H. J. M. Newberg and W. J. Couch and The Supernova Cosmology Project},\n\ttitle = {Measurements of $\\{upOmega}$ and $\\{upLambda}$ from 42 High-Redshift Supernovae},\n\tjournal = {The Astrophysical Journal}\n}", 200, null], [["https://export.arxiv.org/api/query?id_list=math/0211159"], {}, "\n\n \n ArXiv Query: search_query=&id_list=math/0211159&start=0&max_results=10\n http://arxiv.org/api/4nVRTcAL5Np4oaGFQnqVPG0+c5k\n 2018-08-09T00:00:00-04:00\n 1\n 0\n 10\n \n http://arxiv.org/abs/math/0211159v1\n 2002-11-11T16:11:49Z\n 2002-11-11T16:11:49Z\n The entropy formula for the Ricci flow and its geometric applications\n We present a monotonic expression for the Ricci flow, valid in all dimensions\nand without curvature assumptions. It is interpreted as an entropy for a\ncertain canonical ensemble. Several geometric applications are given. In\nparticular, (1) Ricci flow, considered on the space of riemannian metrics\nmodulo diffeomorphism and scaling, has no nontrivial periodic orbits (that is,\nother than fixed points); (2) In a region, where singularity is forming in\nfinite time, the injectivity radius is controlled by the curvature; (3) Ricci\nflow can not quickly turn an almost euclidean region into a very curved one, no\nmatter what happens far away. We also verify several assertions related to\nRichard Hamilton's program for the proof of Thurston geometrization conjecture\nfor closed three-manifolds, and give a sketch of an eclectic proof of this\nconjecture, making use of earlier results on collapsing with local lower\ncurvature bound.\n\n \n Grisha Perelman\n \n 39 pages\n \n \n \n \n \n \n\n", 200, null], [["http://dx.doi.org/10.1007/BF01700692"], {"headers": {"accept": "application/x-bibtex"}}, "@article{G_del_1931,\n\tdoi = {10.1007/bf01700692},\n\turl = {https://doi.org/10.1007%2Fbf01700692},\n\tyear = 1931,\n\tmonth = {dec},\n\tpublisher = {Springer Nature},\n\tvolume = {38-38},\n\tnumber = {1},\n\tpages = {173--198},\n\tauthor = {Kurt G\u00f6del},\n\ttitle = {\u00dcber formal unentscheidbare S\u00e4tze der Principia Mathematica und verwandter Systeme I},\n\tjournal = {Monatshefte f\u00fcr Mathematik und Physik}\n}", 200, null], [["http://dx.doi.org/999999"], {"headers": {"accept": "application/x-bibtex"}}, "\n\n\nError: DOI Not Found\n\n\n\n\n \n\n\n\n\n\n\n
\n\"Logo\"\n
\n\n
\n
\n
\n\n\n\n\n\n \n \n \n \n
\"\"\n HOME  | HANDBOOK  | FACTSHEETS  | FAQs  |  RESOURCES  | USERS  | NEWS  | MEMBERS AREA\n
\n\n\n
\n
\n\n\n\n \n\n\n\n\n\n\n\n\n\n\n
\n\"\"\n
\n\n

DOI Not Found

\n\n
 
\n\n\n\n

10/999999

\n\n
 
\n\n\n\n\n

This DOI cannot be found in the DOI System. Possible reasons are:

\n\n\n
    \n\n
  • The DOI is incorrect in your source. Search for the item by name, title, or other metadata using a search engine.
  • \n\n
  • The DOI was copied incorrectly. Check to see that the string includes all the characters before and after the slash and no sentence punctuation marks.
  • \n\n
  • The DOI has not been activated yet. Please try again later, and report the problem if the error continues.
  • \n\n
\n\n\n\n
 
\n\n

You may report this error to the responsible DOI Registration Agency using the form below. Include your email address to receive confirmation and feedback.

\n\n
\n\n
\n\n\n\n\n\n\n\n\n\n\n\n\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Your Email Address:
Additional Information About the Error:
\n\n

\n\n
\n
\n\n\n\n\n
\"\"
\n\n
 
\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n
\nDOI System Proxy Server Documentation\n
\n\"DOI_disc_logo\"\n\n®, DOI®, DOI.ORG®, and shortDOI® are trademarks of the International DOI Foundation.\n
\n\n\n", 404, "404 Client Error: for url: http://dx.doi.org/999999"], [["http://dx.doi.org/10.1007/BF01700692"], {"headers": {"accept": "application/x-bibtex"}}, "@article{G_del_1931,\n\tdoi = {10.1007/bf01700692},\n\turl = {https://doi.org/10.1007%2Fbf01700692},\n\tyear = 1931,\n\tmonth = {dec},\n\tpublisher = {Springer Nature},\n\tvolume = {38-38},\n\tnumber = {1},\n\tpages = {173--198},\n\tauthor = {Kurt G\u00f6del},\n\ttitle = {\u00dcber formal unentscheidbare S\u00e4tze der Principia Mathematica und verwandter Systeme I},\n\tjournal = {Monatshefte f\u00fcr Mathematik und Physik}\n}", 200, null], [["http://www.ottobib.com/isbn/9782081336742/bibtex"], {"headers": null}, "\n\n\n\n \n \n \n \n \n \n \n \n\n \n\n Bibliography and Works Cited Generator for MLA, APA, Wikipedia and Bibtex - OttoBib.com \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n
\n \n
\n
\n

OttoBib

\n

bibtex Format

\n
\n
\n\n
\n
\n \n
\n
\n
\n\n
\n

\n NOTE!\n
\n

    \n
  1. Verify accuracy of the data (particularly authors)
  2. \n
  3. Remember to do a HANGING INDENT (something I cannot do with HTML here)
  4. \n
  5. I strive for accuracy of the citations but you should treat this tool as a starting point in your works cited, because you still need to look it over.
  6. \n
\n

\n
\n
\n\n
\n \n\n \n", 200, null], [["http://www.ottobib.com/isbn/9999999999999/bibtex"], {"headers": null}, "\n\n\n\n \n \n \n \n \n \n \n \n\n \n\n Bibliography and Works Cited Generator for MLA, APA, Wikipedia and Bibtex - OttoBib.com \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n
\n \n
\n\t

OttoBib

\n\t

Make a bibliography or works cited with just an ISBN. It's free, easy and FAST

\n\t

\n\t about ottobib and history\n\t \n\t

\n\t \n

\n\t
\n
\n\n
\n
\n\n
No Results for 9999999999999
\n
\n

\n Enter ISBN of book(s) - separate with commas (,)\n

\n \n read more about ISBN on Wikipedia\n \n
\n \n \n \n \n \n\n
\n \n
\n
\n\n
\n
\n\n

Did OttoBib help you? Then help us and Like us on Facebook!

\n
\n
\n\n\n
\n\n\n\n\n
\n \n\n \n", 200, null], [["http://www.ottobib.com/isbn/9782081336742/bibtex"], {"headers": null}, "\n\n\n\n \n \n \n \n \n \n \n \n\n \n\n Bibliography and Works Cited Generator for MLA, APA, Wikipedia and Bibtex - OttoBib.com \n \n \n\n \n \n \n \n \n \n \n \n \n \n \n
\n \n
\n
\n

OttoBib

\n

bibtex Format

\n
\n
\n\n
\n
\n \n
\n
\n
\n\n
\n

\n NOTE!\n
\n

    \n
  1. Verify accuracy of the data (particularly authors)
  2. \n
  3. Remember to do a HANGING INDENT (something I cannot do with HTML here)
  4. \n
  5. I strive for accuracy of the citations but you should treat this tool as a starting point in your works cited, because you still need to look it over.
  6. \n
\n

\n
\n
\n\n
\n \n\n \n", 200, null]] \ No newline at end of file diff --git a/tests/test_apis_data.pickle b/tests/test_apis_data.pickle deleted file mode 100644 index 1d7a914..0000000 Binary files a/tests/test_apis_data.pickle and /dev/null differ