File: test_pickle.py

package info (click to toggle)
python-astropy 1.3-8~bpo8%2B2
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 44,292 kB
  • sloc: ansic: 160,360; python: 137,322; sh: 11,493; lex: 7,638; yacc: 4,956; xml: 1,796; makefile: 474; cpp: 364
file content (71 lines) | stat: -rw-r--r-- 1,835 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from ...extern.six.moves import zip, cPickle as pickle
from ...coordinates import Longitude
from ... import coordinates as coord
from ...tests.helper import pytest, pickle_protocol, check_pickling_recovery
import numpy as np

#Can't test distances without scipy due to cosmology deps
try:
    import scipy  # pylint: disable=W0611
    HAS_SCIPY = True
except ImportError:
    HAS_SCIPY = False

def test_basic():
    lon1 = Longitude(1.23, "radian", wrap_angle='180d')
    s = pickle.dumps(lon1)
    lon2 = pickle.loads(s)

def test_pickle_longitude_wrap_angle():
    a = Longitude(1.23, "radian", wrap_angle='180d')
    s = pickle.dumps(a)
    b = pickle.loads(s)

    assert a.rad == b.rad
    assert a.wrap_angle == b.wrap_angle


_names = [coord.Angle,
          coord.Distance,
          coord.DynamicMatrixTransform,
          coord.ICRS,
          coord.Latitude,
          coord.Longitude,
          coord.StaticMatrixTransform,
          ]

_xfail = [False,
          not HAS_SCIPY,
          True,
          True,
          False,
          True,
          False]

_args = [[0.0],
         [],
         [lambda *args: np.identity(3), coord.ICRS, coord.ICRS],
         [0, 0],
         [0],
         [0],
         [np.identity(3), coord.ICRS, coord.ICRS],
         ]

_kwargs = [{'unit':'radian'},
           {'z':0.23},
           {},
           {'unit':['radian', 'radian']},
           {'unit':'radian'},
           {'unit':'radian'},
           {},
           ]


@pytest.mark.parametrize(("name","args","kwargs","xfail"),
                         zip(_names, _args, _kwargs, _xfail))
def test_simple_object(pickle_protocol, name, args, kwargs, xfail):
    # Tests easily instantiated objects
    if xfail:
        pytest.xfail()
    original = name(*args, **kwargs)
    check_pickling_recovery(original, pickle_protocol)