skip tests using mocpy/pyvo when those lib are not installed
# -*- coding: utf-8 -*
# Licensed under a 3-clause BSD style license - see LICENSE.rst
+import sys
import pytest
import os
import json
@@ -11,6 +12,17 @@ from ..core import cds
from astropy import coordinates
+try:
+ import pyvo as vo
+except ImportError:
+ pass
+
+try:
+ from mocpy import MOC
+except ImportError:
+ pass
+
+
DATA_FILES = {
'CONE_SEARCH': 'cone_search.json',
'POLYGON_SEARCH': 'polygon_search.json',
@@ -174,10 +186,11 @@ def test_max_rec_param(max_rec):
Tests requiring mocpy
"""
-try:
- from mocpy import MOC
+
# test of moc_order payload
+@pytest.mark.skipif('mocpy' not in sys.modules,
+ reason="requires the mocpy library")
@pytest.mark.parametrize('moc_order', [5, 10])
def test_moc_order_param(moc_order):
result = cds.query_region(region_type=cds.RegionType.MOC,
@@ -190,6 +203,8 @@ try:
assert isinstance(result, MOC)
+@pytest.mark.skipif('mocpy' not in sys.modules,
+ reason="requires the mocpy library")
def test_from_mocpy_obj():
moc = MOC()
moc.add_pix(order=5, i_pix=3, nest=True)
@@ -203,15 +218,16 @@ try:
from ast import literal_eval
assert literal_eval(result['moc']) == {"5": [3],
"9": [34, 35, 36]}
-except ImportError:
- pass
"""
Tests requiring pyvo
"""
-try:
+
+
+@pytest.mark.skipif('pyvo' not in sys.modules,
+ reason="requires the pyvo library")
# test of field_l when retrieving dataset records
@pytest.mark.parametrize('field_l', [['ID'],
['ID', 'moc_sky_fraction'],
@@ -226,7 +242,6 @@ try:
output_format=cds.ReturnFormat.record,
meta_var=field_l,
get_query_payload=False)
-
assert isinstance(datasets, dict)
for id, dataset in datasets.items():
at_least_one_field = False
@@ -237,6 +252,8 @@ try:
assert at_least_one_field
+@pytest.mark.skipif('pyvo' not in sys.modules,
+ reason="requires the pyvo library")
@pytest.mark.parametrize('get_attr, get_attr_str', [(cds.ReturnFormat.id, 'id'),
(cds.ReturnFormat.record, 'record'),
(cds.ReturnFormat.number, 'number'),
@@ -254,5 +271,3 @@ try:
assert result['get'] == get_attr_str
-except ImportError:
- pass
