| 1 |
import asdf |
| 2 |
import pytest |
| 3 |
from astropy import units as u |
| 4 |
from astropy.time import Time, TimeDelta |
| 5 |
|
| 6 |
from asdf_astropy.testing.helpers import assert_time_delta_equal |
| 7 |
|
| 8 |
|
| 9 |
def create_time_deltas(): |
| 10 |
result = [TimeDelta([1, 2] * u.day)] |
| 11 |
result += [TimeDelta(Time.now() - Time.now(), format=format_) for format_ in TimeDelta.FORMATS] |
| 12 |
result += [TimeDelta(0.125 * u.day, scale=scale) for scale in [*list(TimeDelta.SCALES), None]] |
| 13 |
|
| 14 |
return result |
| 15 |
|
| 16 |
|
| 17 |
@pytest.mark.parametrize("time_delta", create_time_deltas()) |
| 18 |
def test_serialization(time_delta, tmp_path): |
| 19 |
file_path = tmp_path / "test.asdf" |
| 20 |
with asdf.AsdfFile() as af: |
| 21 |
af["time_delta"] = time_delta |
| 22 |
af.write_to(file_path) |
| 23 |
|
| 24 |
with asdf.open(file_path) as af: |
| 25 |
assert_time_delta_equal(af["time_delta"], time_delta) |