Exemplo n.º 1
0
def test_query_object():
    nasa_exoplanet_archive = NasaExoplanetArchiveClass()

    def mock_run_query(object_name="K2-18 b",
                       table="pscomppars",
                       select="pl_name,disc_year,discoverymethod,ra,dec"):
        assert object_name == "K2-18 b"
        assert table == "pscomppars"
        assert select == "pl_name,disc_year,discoverymethod,ra,dec"
        result = PropertyMock()
        result = {
            'pl_name': 'K2-18 b',
            'disc_year': 2015,
            'discoverymethod': 'Transit',
            'ra': [172.560141] * u.deg,
            'dec': [7.5878315] * u.deg
        }

        return result

    nasa_exoplanet_archive.query_object = mock_run_query
    response = nasa_exoplanet_archive.query_object()
    assert response['pl_name'] == 'K2-18 b'
    assert response['disc_year'] == 2015
    assert 'Transit' in response['discoverymethod']
    assert response['ra'] == [172.560141] * u.deg
    assert response['dec'] == [7.5878315] * u.deg
Exemplo n.º 2
0
def test_get_query_payload():
    nasa_exoplanet_archive = NasaExoplanetArchiveClass()

    def mock_run_query(table="ps",
                       get_query_payload=True,
                       select="count(*)",
                       where="disc_facility like '%TESS%'"):
        assert table == "ps"
        assert get_query_payload
        assert select == "count(*)"
        assert where == "disc_facility like '%TESS%'"
        result = PropertyMock()
        result = {
            'table': 'ps',
            'select': 'count(*)',
            'where': "disc_facility like '%TESS%'",
            'format': 'ipac'
        }
        return result

    nasa_exoplanet_archive.query_criteria = mock_run_query
    response = nasa_exoplanet_archive.query_criteria()
    assert 'ps' in response['table']
    assert 'count(*)' in response['select']
    assert "disc_facility like '%TESS%'" in response['where']
Exemplo n.º 3
0
def test_query_aliases_planet(query_aliases_request):
    nasa_exoplanet_archive = NasaExoplanetArchiveClass()
    result = nasa_exoplanet_archive.query_aliases('bet Pic b')
    assert len(result) > 10
    assert 'GJ 219 b' in result
    assert 'bet Pic b' in result
    assert '2MASS J05471708-5103594 b' in result
Exemplo n.º 4
0
def test_query_aliases(query_aliases_request):
    nasa_exoplanet_archive = NasaExoplanetArchiveClass()
    result = nasa_exoplanet_archive.query_aliases(object_name='bet Pic')
    assert len(result) > 10
    assert 'GJ 219' in result
    assert 'bet Pic' in result
    assert '2MASS J05471708-5103594' in result
Exemplo n.º 5
0
def test_api_tables(patch_get, table, query):
    NasaExoplanetArchiveMock = NasaExoplanetArchiveClass()

    NasaExoplanetArchiveMock._tap_tables = ['list']
    data = NasaExoplanetArchiveMock.query_criteria(table, select="*", **query)
    assert len(data) > 0

    # Check that the units were fixed properly
    for col in data.columns:
        assert isinstance(data[col], SkyCoord) or not isinstance(data[col].unit, u.UnrecognizedUnit)
Exemplo n.º 6
0
def test_get_tap_tables():
    nasa_exoplanet_archive = NasaExoplanetArchiveClass()

    def mock_run_query(url=conf.url_tap):
        assert url == conf.url_tap
        result = PropertyMock()
        result = ['transitspec', 'emissionspec', 'ps', 'pscomppars', 'keplernames', 'k2names']
        return result
    nasa_exoplanet_archive.get_tap_tables = mock_run_query
    result = nasa_exoplanet_archive.get_tap_tables()
    assert 'ps' in result
    assert 'pscomppars' in result
Exemplo n.º 7
0
def test_query_region():
    nasa_exoplanet_archive = NasaExoplanetArchiveClass()

    def mock_run_query(table="ps", select='pl_name,ra,dec', coordinates=SkyCoord(ra=172.56 * u.deg, dec=7.59 * u.deg), radius=1.0 * u.deg):
        assert table == "ps"
        assert select == 'pl_name,ra,dec'
        assert radius == 1.0 * u.deg
        result = PropertyMock()
        result = {'pl_name': 'K2-18 b'}
        return result
    nasa_exoplanet_archive.query_region = mock_run_query
    response = nasa_exoplanet_archive.query_region()
    assert 'K2-18 b' in response['pl_name']
Exemplo n.º 8
0
def test_select():
    nasa_exoplanet_archive = NasaExoplanetArchiveClass()

    def mock_run_query(table="ps", select=["hostname", "pl_name"], where="hostname='Kepler-11'", get_query_payload=True):
        assert table == "ps"
        assert select == ["hostname", "pl_name"]
        assert where == "hostname='Kepler-11'"
        assert get_query_payload
        payload = PropertyMock()
        payload = {'table': 'ps', 'select': 'hostname,pl_name', 'where': "hostname='Kepler-11'", 'format': 'ipac'}
        return payload
    nasa_exoplanet_archive.query_criteria = mock_run_query
    payload = nasa_exoplanet_archive.query_criteria()
    assert payload["select"] == "hostname,pl_name"
Exemplo n.º 9
0
def test_query_criteria():
    nasa_exoplanet_archive = NasaExoplanetArchiveClass()

    def mock_run_query(table="ps", select='pl_name,discoverymethod,dec', where="discoverymethod like 'Microlensing' and dec > 0"):
        assert table == "ps"
        assert select == "pl_name,discoverymethod,dec"
        assert where == "discoverymethod like 'Microlensing' and dec > 0"
        result = PropertyMock()
        result = {'pl_name': 'TCP J05074264+2447555 b', 'discoverymethod': 'Microlensing', 'dec': [24.7987499] * u.deg}
        return result
    nasa_exoplanet_archive.query_criteria = mock_run_query
    response = nasa_exoplanet_archive.query_criteria()
    assert 'TCP J05074264+2447555 b' in response['pl_name']
    assert 'Microlensing' in response['discoverymethod']
    assert response['dec'] == [24.7987499] * u.deg
Exemplo n.º 10
0
def test_regularize_object_name(patch_get):
    NasaExoplanetArchiveMock = NasaExoplanetArchiveClass()

    NasaExoplanetArchiveMock._tap_tables = ['list']
    assert NasaExoplanetArchiveMock._regularize_object_name(
        "kepler 2") == "HAT-P-7"
    assert NasaExoplanetArchiveMock._regularize_object_name(
        "kepler 1 b") == "TrES-2 b"

    with pytest.warns(NoResultsWarning) as warning:
        NasaExoplanetArchiveMock._regularize_object_name("not a planet")
    assert "No aliases found for name: 'not a planet'" == str(
        warning[0].message)
Exemplo n.º 11
0
def test_backwards_compat(patch_get):
    """
    These are the tests from the previous version of this interface.
    They query old tables by default and should return InvalidTableError.
    """
    NasaExoplanetArchiveMock = NasaExoplanetArchiveClass()

    NasaExoplanetArchiveMock._tap_tables = ['list']

    # test_hd209458b_exoplanets_archive
    with pytest.warns(AstropyDeprecationWarning):
        with pytest.raises(InvalidTableError) as error:
            NasaExoplanetArchiveMock.query_planet("HD 209458 b ")
        assert "replaced" in str(error)

    # test_hd209458b_exoplanet_archive_coords
    with pytest.warns(AstropyDeprecationWarning):
        with pytest.raises(InvalidTableError) as error:
            NasaExoplanetArchiveMock.query_planet("HD 209458 b ")
        assert "replaced" in str(error)

    # test_hd209458_stellar_exoplanet
    with pytest.warns(AstropyDeprecationWarning):
        with pytest.raises(InvalidTableError) as error:
            NasaExoplanetArchiveMock.query_star("HD 209458")
        assert "replaced" in str(error)

    # test_hd136352_stellar_exoplanet_archive
    with pytest.warns(AstropyDeprecationWarning):
        with pytest.raises(InvalidTableError) as error:
            NasaExoplanetArchiveMock.query_star("HD 136352")
        assert "replaced" in str(error)

    # test_exoplanet_archive_query_all_columns
    with pytest.warns(AstropyDeprecationWarning):
        with pytest.raises(InvalidTableError) as error:
            NasaExoplanetArchiveMock.query_planet("HD 209458 b ",
                                                  all_columns=True)
        assert "replaced" in str(error)