Skip to content

Commit

Permalink
Add unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mairanteodoro committed Sep 10, 2024
1 parent aa0cd8f commit 1cf55ef
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/test_tweakreg.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Test astrometric utility functions for alignment"""

import copy
from copy import deepcopy
from pathlib import Path

import asdf
import contextlib
import numpy as np
import pytest
from astropy.modeling.models import Shift
Expand All @@ -21,6 +23,7 @@
relative_align,
)
from stcal.tweakreg.utils import _wcsinfo_from_wcs_transform
import requests

# Define input GWCS specification to be used for these tests
WCS_NAME = "mosaic_long_i2d_gwcs.asdf" # Derived using B7.5 Level 3 product
Expand All @@ -38,6 +41,11 @@
N_EXAMPLE_SOURCES = 21


class MockConnectionError:
def __init__(self, *args, **kwargs):
raise requests.exceptions.ConnectionError


@pytest.fixture(scope="module")
def wcsobj():
path = Path(__file__).parent / DATADIR / WCS_NAME
Expand Down Expand Up @@ -310,3 +318,23 @@ def test_absolute_align(example_input, input_catalog):

abs_delta = abs(result[1].wcs(0, 0)[0] - result[0].wcs(0, 0)[0])
assert abs_delta < 1E-12

def test_get_catalog_timeout():
"""Test that get_catalog can raise an exception on timeout."""

with pytest.raises(Exception) as exec_info:
for dt in np.arange(1, 0, -0.01):
with contextlib.suppress(requests.exceptions.ConnectionError):
amutils.get_catalog(10, 10, search_radius=0.1, catalog="GAIADR3", timeout=dt)
assert exec_info.type == requests.exceptions.Timeout


def test_get_catalog_raises_connection_error(monkeypatch):
"""Test that get_catalog can raise an exception on connection error."""

monkeypatch.setattr("requests.get", MockConnectionError)

with pytest.raises(Exception) as exec_info:
amutils.get_catalog(10, 10, search_radius=0.1, catalog="GAIADR3")

assert exec_info.type == requests.exceptions.ConnectionError

0 comments on commit 1cf55ef

Please sign in to comment.