How to use arxiv - 10 common examples

To help you get started, we’ve selected a few arxiv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github arXiv / arxiv-browse / browse / controllers / tb_page / tests.py View on Github external
'foo': 'bar'
        })
        with self.assertRaises(BadRequest):
            tb_page.get_recent_tb_page(form_data)

        form_data = MultiDict({
            'views': 'baz'
        })
        with self.assertRaises(BadRequest):
            tb_page.get_recent_tb_page(form_data)

        form_data = MultiDict({
            'views': '25'
        })
        response_data, code, headers = tb_page.get_recent_tb_page(form_data)
        self.assertEqual(code, status.HTTP_200_OK, 'Response should be OK.')
        self.assertIn('max_trackbacks', response_data,
                      "Response data should include 'max_trackbacks'")
        self.assertEqual(response_data['max_trackbacks'], 25,
                         "'max_trackbacks' should equal value from form")
        self.assertIn('recent_trackback_pings', response_data,
                      "Response data should include 'recent_trackback_pings'")
        self.assertIn('article_map', response_data,
                      "Response data should include 'article_map'")
github arXiv / arxiv-search / search / controllers / advanced / tests.py View on Github external
def test_invalid_data(self, mock_index):
        """Form data are invalid."""
        request_data = MultiDict({
            'advanced': True,
            'date-past_12': True,
            'date-specific_year': True,
            'date-year': '2012'
        })
        response_data, code, headers = advanced.search(request_data)
        self.assertEqual(code, status.HTTP_200_OK, "Response should be OK.")

        self.assertIn('form', response_data, "Response should include form.")

        self.assertEqual(mock_index.search.call_count, 0,
                         "No search should be attempted")
github arXiv / arxiv-browse / tests / test_exceptions.py View on Github external
response = self.client.get(path)
            self.assertEqual(response.status_code,
                             status.HTTP_404_NOT_FOUND,
                             f'should get 404 for {path}')
            self.assertIn('text/html', response.content_type)

        response = self.client.get('/abs/1307.0001v999')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
                         f'should get 404 for known paper ID with '
                         'nonexistent version')
        response = self.client.get('/abs/alg-geom/07059999')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
                         f'should get 404 for valid old paper ID '
                         'with nonexistent paper number affix')
        response = self.client.get('/abs/astro-ph/0110242')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
                         f'should get 404 for known deleted paper')
        response = self.client.get('/abs/foo-bar/11223344')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
                         f'should get 404 for bad paper ID')
github arXiv / arxiv-search / tests / stubs / docmeta.py View on Github external
"""Stub for the docmeta service."""
import os
import json
from flask import Flask
from flask.json import jsonify
from werkzeug.exceptions import NotFound, InternalServerError

from arxiv.base import Base
from arxiv.base.converter import ArXivConverter
from arxiv.base import logging

logger = logging.getLogger(__name__)

METADATA_DIR = os.environ.get("METADATA_DIR")


app = Flask("metadata")
Base(app)

app.url_map.converters["arxiv"] = ArXivConverter


@app.route("/docmeta/", methods=["GET"])
def docmeta(document_id):
    """Retrieve document metadata."""
    logger.debug(f"Get metadata for {document_id}")
    logger.debug(f"Metadata base is {METADATA_DIR}")
    if not METADATA_DIR:
github arXiv / arxiv-browse / tests / test_browse.py View on Github external
def test_home(self):
        """Test the home page."""
        rv = self.app.get('/')
        self.assertEqual(rv.status_code, 200)
        html = BeautifulSoup(rv.data.decode('utf-8'), 'html.parser')

        for group_key, group_value in taxonomy.definitions.GROUPS.items():
            if group_key == 'grp_test':
                continue
            auths_elmt = html.find('h2', text=group_value['name'])
            self.assertTrue(auths_elmt, f"{group_value['name']} in h2 element")
        self.assertFalse(html.find('h2', text='Test'),
                         "'Test' group should not be shown on homepage")
github arXiv / arxiv-browse / tests / test_filters.py View on Github external
def test_arxiv_urlize(self):
        h = 'sosmooth.org'
        app.config['SERVER_NAME'] = h
        with app.app_context():
            self.assertEqual(
                urlize('http://example.com/'),
                '<a href="http://example.com/">this http URL</a>',
                'urlize (URL linking) 1/6')
            self.assertEqual(
                urlize('https://example.com/'),
                '<a href="https://example.com/">this https URL</a>',
                'urlize (URL linking) 2/6')
            self.assertEqual(
                urlize('ftp://example.com/'),
                '<a href="ftp://example.com/">this ftp URL</a>',
                'urlize (URL linking) 3/6')
            self.assertEqual(
                urlize('http://example.com/.hep-th/9901001'),
                '<a href="http://example.com/.hep-th/9901001">this http URL</a>',
                'urlize (URL linking) 4/6')
            self.assertEqual(
                urlize(
                    'http://projecteuclid.org/euclid.bj/1151525136'
                ),
                '<a href="http://projecteuclid.org/euclid.bj/1151525136">this http URL</a>',
                'urlize (URL linking) 6/6')
            self.assertEqual(
                urlize('  Correction to Bernoulli (2006), 12, 551--570 http://projecteuclid.org/euclid.bj/1151525136'),
                Markup('  Correction to Bernoulli (2006), 12, 551--570 <a href="http://projecteuclid.org/euclid.bj/1151525136">this http URL</a>'),
                'urlize (URL linking) 6/6')
github arXiv / arxiv-browse / tests / test_filters.py View on Github external
f'<a href="https://arxiv.org/abs/hep-th/9901002">hep-th/9901002</a>.',
                'followed by period')
            self.assertEqual(
                urlize('0702.0003.'),
                f'<a href="https://arxiv.org/abs/0702.0003">0702.0003</a>.',
                'followed by period')
            self.assertEqual(
                urlize('hep-th/9901001,hep-th/9901002'),
                f'<a href="https://arxiv.org/abs/hep-th/9901001">hep-th/9901001</a>,<a href="https://arxiv.org/abs/hep-th/9901002">hep-th/9901002</a>',
                'filter_urls_ids_escape (ID linking) 3/7')
            self.assertEqual(
                urlize('0702.0003, something'),
                f'<a href="https://arxiv.org/abs/0702.0003">0702.0003</a>, something',
                'followed by comma')
            self.assertEqual(
                urlize('(0702.0003) something'),
                f'(<a href="https://arxiv.org/abs/0702.0003">0702.0003</a>) something',
                'in parens')
github arXiv / arxiv-browse / tests / test_filters.py View on Github external
'<a href="http://projecteuclid.org/euclid.bj/1151525136">this http URL</a>',
                'urlize (URL linking) 6/6')
            self.assertEqual(
                urlize('  Correction to Bernoulli (2006), 12, 551--570 http://projecteuclid.org/euclid.bj/1151525136'),
                Markup('  Correction to Bernoulli (2006), 12, 551--570 <a href="http://projecteuclid.org/euclid.bj/1151525136">this http URL</a>'),
                'urlize (URL linking) 6/6')
            # shouldn't match
            self.assertEqual(
                urlize('2448446.4710(5)'), '2448446.4710(5)',
                'urlize (should not match) 1/9')
            self.assertEqual(
                urlize('HJD=2450274.4156+/-0.0009'),
                'HJD=2450274.4156+/-0.0009',
                'urlize (should not match) 2/9')
            self.assertEqual(
                urlize('T_min[HJD]=49238.83662(14)+0.146352739(11)E.'),
                'T_min[HJD]=49238.83662(14)+0.146352739(11)E.',
                'urlize (should not match) 3/9')
            self.assertEqual(
                urlize('Pspin=1008.3408s'), 'Pspin=1008.3408s',
                'urlize (should not match) 4/9')
            self.assertEqual(
                urlize('2453527.87455^{+0.00085}_{-0.00091}'),
                '2453527.87455^{+0.00085}_{-0.00091}',
                'urlize (should not match) 5/9')
            self.assertEqual(
                urlize('2451435.4353'), '2451435.4353',
                'urlize (should not match) 6/9')
            self.assertEqual(
                urlize('cond-mat/97063007'),
                '<a href="https://arxiv.org/abs/cond-mat/9706300">cond-mat/9706300</a>7',
                'urlize (should match) 7/9')
github arXiv / arxiv-browse / tests / test_filters.py View on Github external
self.assertEqual(
                urlize('ftp://example.com/'),
                '<a href="ftp://example.com/">this ftp URL</a>',
                'urlize (URL linking) 3/6')
            self.assertEqual(
                urlize('http://example.com/.hep-th/9901001'),
                '<a href="http://example.com/.hep-th/9901001">this http URL</a>',
                'urlize (URL linking) 4/6')
            self.assertEqual(
                urlize(
                    'http://projecteuclid.org/euclid.bj/1151525136'
                ),
                '<a href="http://projecteuclid.org/euclid.bj/1151525136">this http URL</a>',
                'urlize (URL linking) 6/6')
            self.assertEqual(
                urlize('  Correction to Bernoulli (2006), 12, 551--570 http://projecteuclid.org/euclid.bj/1151525136'),
                Markup('  Correction to Bernoulli (2006), 12, 551--570 <a href="http://projecteuclid.org/euclid.bj/1151525136">this http URL</a>'),
                'urlize (URL linking) 6/6')
            # shouldn't match
            self.assertEqual(
                urlize('2448446.4710(5)'), '2448446.4710(5)',
                'urlize (should not match) 1/9')
            self.assertEqual(
                urlize('HJD=2450274.4156+/-0.0009'),
                'HJD=2450274.4156+/-0.0009',
                'urlize (should not match) 2/9')
            self.assertEqual(
                urlize('T_min[HJD]=49238.83662(14)+0.146352739(11)E.'),
                'T_min[HJD]=49238.83662(14)+0.146352739(11)E.',
                'urlize (should not match) 3/9')
            self.assertEqual(
                urlize('Pspin=1008.3408s'), 'Pspin=1008.3408s',
github arXiv / arxiv-browse / tests / test_filters.py View on Github external
def test_arxiv_id_urls_basic(self):
        h = 'arxiv.org'  # Totally bogus setup for testing, at least url_for returns something
        app.config['SERVER_NAME'] = h

        with app.app_context():
            self.assertEqual(urlize('', ['arxiv_id']), '')
            s = 'some text 134#%$$%&amp;^^%*^&amp;(()*_)_&lt;&gt;?:;[}}'
            self.assertEqual(urlize(s), str(escape(s)),
                             'filters should return escaped text')
            self.assertEqual(
                urlize('hep-th/9901001'),
                f'<a href="https://arxiv.org/abs/hep-th/9901001">hep-th/9901001</a>',
            )
            self.assertEqual(
                urlize('hep-th/9901001 hep-th/9901002'),
                f'<a href="https://arxiv.org/abs/hep-th/9901001">hep-th/9901001</a> <a href="https://arxiv.org/abs/hep-th/9901002">hep-th/9901002</a>'
                )