<commit_before># Licensed under a 3-clause BSD style license - see LICENSE.rst
import pytest
import shutil
import tempfile

from astropy.coordinates import SkyCoord
import astropy.units as u
from astropy.table import Table
from astroquery.utils.testing_tools import MockResponse
from astroquery.simbad import Simbad
# Maybe we need to expose SimbadVOTableResult to be in the public API?
from astroquery.simbad.core import SimbadVOTableResult


# M42 coordinates
ICRS_COORDS_M42 = SkyCoord("05h35m17.3s -05h23m28s", frame='icrs')
ICRS_COORDS_SgrB2 = SkyCoord(266.835*u.deg, -28.38528*u.deg, frame='icrs')
multicoords = SkyCoord([ICRS_COORDS_M42, ICRS_COORDS_SgrB2])


@pytest.mark.remote_data
class TestSimbad:

    @classmethod
    def setup_class(cls):
        Simbad.ROW_LIMIT = 5

    @pytest.fixture()
    def temp_dir(self, request):
        my_temp_dir = tempfile.mkdtemp()

        def fin():
            shutil.rmtree(my_temp_dir)
        request.addfinalizer(fin)
        return my_temp_dir

    def test_query_criteria1(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        result = simbad.query_criteria(
            "region(box, GAL, 49.89 -0.3, 0.5d 0.5d)", otype='HII')
        assert isinstance(result, Table)

    def test_query_criteria2(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        result = simbad.query_criteria(otype='SNR')
        assert isinstance(result, Table)

    def test_query_bibcode_async(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        response = simbad.query_bibcode_async(
            '2006ApJ*', wildcard=True)
        assert response is not None
        response.raise_for_status()
        # make sure requests has *NOT* been monkeypatched
        assert hasattr(response, 'connection')
        assert hasattr(response, 'close')
        assert hasattr(response, 'status_code')
        assert hasattr(response, 'request')
        assert not isinstance(response, MockResponse)
        assert not issubclass(response.__class__, MockResponse)

    def test_query_bibcode(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        result = simbad.query_bibcode('2006ApJ*', wildcard=True)
        assert isinstance(result, Table)

    def test_query_bibobj_async(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        response = simbad.query_bibobj_async('2005A&A.430.165F')
        assert response is not None

    def test_query_bibobj(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        result = simbad.query_bibobj('2005A&A.430.165F')
        assert isinstance(result, Table)

    def test_query_catalog_async(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        response = simbad.query_catalog_async('m')
        assert response is not None

    def test_query_catalog(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        result = simbad.query_catalog('m')
        assert isinstance(result, Table)

    def test_query_region_async(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        response = simbad.query_region_async(
            ICRS_COORDS_M42, radius=5 * u.deg, equinox=2000.0, epoch='J2000')

        assert response is not None

    def test_query_region_async_vector(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        response1 = simbad.query_region_async(multicoords,
                                                          radius=0.5*u.arcsec)
        assert response1.request.body == 'script=votable+%7Bmain_id%2Ccoordinates%7D%0Avotable+open%0Aquery+coo+5%3A35%3A17.3+-80%3A52%3A00+radius%3D0.5s+frame%3DICRS+equi%3D2000.0%0Aquery+coo+17%3A47%3A20.4+-28%3A23%3A07.008+radius%3D0.5s+frame%3DICRS+equi%3D2000.0%0Avotable+close'   # noqa

    def test_query_region(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        result = simbad.query_region(ICRS_COORDS_M42, radius=5 * u.deg,
                                     equinox=2000.0, epoch='J2000')
        assert isinstance(result, Table)

    def test_query_regions(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        result = simbad.query_region(multicoords, radius=1 * u.arcmin,
                                     equinox=2000.0, epoch='J2000')
        assert isinstance(result, Table)

    def test_query_object_async(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        response = simbad.query_object_async("m [0-9]", wildcard=True)
        assert response is not None
<commit_msg>Fix more timeout related test failures<commit_after># Licensed under a 3-clause BSD style license - see LICENSE.rst
import pytest
import shutil
import tempfile

from astropy.coordinates import SkyCoord
import astropy.units as u
from astropy.table import Table
from astroquery.utils.testing_tools import MockResponse
from astroquery.simbad import Simbad
# Maybe we need to expose SimbadVOTableResult to be in the public API?
from astroquery.simbad.core import SimbadVOTableResult


# M42 coordinates
ICRS_COORDS_M42 = SkyCoord("05h35m17.3s -05h23m28s", frame='icrs')
ICRS_COORDS_SgrB2 = SkyCoord(266.835*u.deg, -28.38528*u.deg, frame='icrs')
multicoords = SkyCoord([ICRS_COORDS_M42, ICRS_COORDS_SgrB2])


@pytest.mark.remote_data
class TestSimbad:

    @pytest.fixture()
    def temp_dir(self, request):
        my_temp_dir = tempfile.mkdtemp()

        def fin():
            shutil.rmtree(my_temp_dir)
        request.addfinalizer(fin)
        return my_temp_dir

    def test_query_criteria1(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        result = simbad.query_criteria(
            "region(box, GAL, 49.89 -0.3, 0.5d 0.5d)", otype='HII')
        assert isinstance(result, Table)

    def test_query_criteria2(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        result = simbad.query_criteria(otype='SNR')
        assert isinstance(result, Table)

    def test_query_bibcode_async(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        response = simbad.query_bibcode_async(
            '2006ApJ*', wildcard=True)
        assert response is not None
        response.raise_for_status()
        # make sure requests has *NOT* been monkeypatched
        assert hasattr(response, 'connection')
        assert hasattr(response, 'close')
        assert hasattr(response, 'status_code')
        assert hasattr(response, 'request')
        assert not isinstance(response, MockResponse)
        assert not issubclass(response.__class__, MockResponse)

    def test_query_bibcode(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        result = simbad.query_bibcode('2006ApJ*', wildcard=True)
        assert isinstance(result, Table)

    def test_query_bibobj_async(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        response = simbad.query_bibobj_async('2006AJ....131.1163S')
        assert response is not None

    def test_query_bibobj(self, temp_dir):
        simbad = Simbad()
        simbad.ROW_LIMIT = 5
        simbad.cache_location = temp_dir
        result = simbad.query_bibobj('2005A&A.430.165F')
        assert isinstance(result, Table)
        assert len(result) == 5

    def test_query_catalog_async(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        response = simbad.query_catalog_async('m')
        assert response is not None

    def test_query_catalog(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        result = simbad.query_catalog('m')
        assert isinstance(result, Table)

    def test_query_region_async(self, temp_dir):
        simbad = Simbad()
        # TODO: rewise once ROW_LIMIT is working
        simbad.TIMEOUT = 100
        simbad.cache_location = temp_dir
        response = simbad.query_region_async(
            ICRS_COORDS_M42, radius=2 * u.deg, equinox=2000.0, epoch='J2000')

        assert response is not None

    def test_query_region_async_vector(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        response1 = simbad.query_region_async(multicoords, radius=0.5*u.arcsec)
        assert response1.request.body == 'script=votable+%7Bmain_id%2Ccoordinates%7D%0Avotable+open%0Aquery+coo+5%3A35%3A17.3+-80%3A52%3A00+radius%3D0.5s+frame%3DICRS+equi%3D2000.0%0Aquery+coo+17%3A47%3A20.4+-28%3A23%3A07.008+radius%3D0.5s+frame%3DICRS+equi%3D2000.0%0Avotable+close'   # noqa

    def test_query_region(self, temp_dir):
        simbad = Simbad()
        # TODO: rewise once ROW_LIMIT is working
        simbad.TIMEOUT = 100
        simbad.cache_location = temp_dir
        result = simbad.query_region(ICRS_COORDS_M42, radius=2 * u.deg,
                                     equinox=2000.0, epoch='J2000')
        assert isinstance(result, Table)

    def test_query_regions(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        result = simbad.query_region(multicoords, radius=1 * u.arcmin,
                                     equinox=2000.0, epoch='J2000')
        assert isinstance(result, Table)

    def test_query_object_async(self, temp_dir):
        simbad = Simbad()
        simbad.cache_location = temp_dir
        response = simbad.query_object_async("m [0-9]", wildcard=True)
        assert response is not None

{'fraction_non_alphanumeric': 0.09261164848734307, 'fraction_numerical': 0.03766207038485285, 'mean_word_length': 2.933225414811817, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2226067', 'n_tokens_mistral': 3384, 'n_tokens_neox': 3164, 'n_words': 633}