1import numpy as np
2from numpy.testing import assert_allclose
3
4import pytest
5from pytest import raises
6
7from astropy import units as u
8
9from astropy.wcs import WCS
10from astropy.tests.helper import assert_quantity_allclose
11from astropy.wcs.wcsapi.utils import deserialize_class, wcs_info_str
12
13
14def test_construct():
15
16    result = deserialize_class(('astropy.units.Quantity', (10,), {'unit': 'deg'}))
17    assert_quantity_allclose(result, 10 * u.deg)
18
19
20def test_noconstruct():
21
22    result = deserialize_class(('astropy.units.Quantity', (), {'unit': 'deg'}), construct=False)
23    assert result == (u.Quantity, (), {'unit': 'deg'})
24
25
26def test_invalid():
27
28    with raises(ValueError) as exc:
29        deserialize_class(('astropy.units.Quantity', (), {'unit': 'deg'}, ()))
30    assert exc.value.args[0] == 'Expected a tuple of three values'
31
32
33DEFAULT_1D_STR = """
34WCS Transformation
35
36This transformation has 1 pixel and 1 world dimensions
37
38Array shape (Numpy order): None
39
40Pixel Dim  Axis Name  Data size  Bounds
41        0  None            None  None
42
43World Dim  Axis Name  Physical Type  Units
44        0  None       None           unknown
45
46Correlation between pixel and world axes:
47
48           Pixel Dim
49World Dim    0
50        0  yes
51"""
52
53
54def test_wcs_info_str():
55
56    # The tests in test_sliced_low_level_wcs.py exercise wcs_info_str
57    # extensively. This test is to ensure that the function exists and the
58    # API of the function works as expected.
59
60    wcs_empty = WCS(naxis=1)
61
62    assert wcs_info_str(wcs_empty).strip() == DEFAULT_1D_STR.strip()
63