# Licensed under a 3-clause BSD style license - see LICENSE.rst import functools import numpy as np import pytest from astropy import units as u from astropy.utils import iers from astropy.time import Time from astropy.table import Table from astropy.utils.compat.optional_deps import HAS_H5PY allclose_sec = functools.partial(np.allclose, rtol=2. ** -52, atol=2. ** -52 * 24 * 3600) # 20 ps atol is_masked = np.ma.is_masked def test_simple(): t = Time([1, 2, 3], format='cxcsec') assert t.masked is False assert np.all(t.mask == [False, False, False]) # Before masking, format output is not a masked array (it is an ndarray # like always) assert not isinstance(t.value, np.ma.MaskedArray) assert not isinstance(t.unix, np.ma.MaskedArray) t[2] = np.ma.masked assert t.masked is True assert np.all(t.mask == [False, False, True]) assert allclose_sec(t.value[:2], [1, 2]) assert is_masked(t.value[2]) assert is_masked(t[2].value) # After masking format output is a masked array assert isinstance(t.value, np.ma.MaskedArray) assert isinstance(t.unix, np.ma.MaskedArray) # Todo : test all formats def test_scalar_init(): t = Time('2000:001') assert t.masked is False assert t.mask == np.array(False) def test_mask_not_writeable(): t = Time('2000:001') with pytest.raises(AttributeError) as err: t.mask = True assert "can't set attribute" in str(err.value) t = Time(['2000:001']) with pytest.raises(ValueError) as err: t.mask[0] = True assert "assignment destination is read-only" in str(err.value) def test_str(): t = Time(['2000:001', '2000:002']) t[1] = np.ma.masked assert str(t) == "['2000:001:00:00:00.000' --]" assert repr(t) == "