File: test_to_yaml.py

package info (click to toggle)
python-asdf 2.14.3-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,280 kB
  • sloc: python: 16,612; makefile: 124
file content (38 lines) | stat: -rw-r--r-- 872 bytes parent folder | download
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
import os

import numpy as np

import asdf

from ... import AsdfFile
from ...tests.helpers import assert_tree_match, get_file_sizes
from .. import main


def test_to_yaml(tmpdir):
    x = np.arange(0, 10, dtype=float)

    tree = {
        "science_data": x,
        "subset": x[3:-3],
        "skipping": x[::2],
        "not_shared": np.arange(10, 0, -1, dtype=np.uint8),
    }

    path = os.path.join(str(tmpdir), "original.asdf")
    ff = AsdfFile(tree)
    ff.write_to(path)
    assert len(ff.blocks) == 2

    result = main.main_from_args(["to_yaml", path])

    assert result == 0

    files = get_file_sizes(str(tmpdir))

    assert "original.asdf" in files
    assert "original.yaml" in files

    with asdf.open(os.path.join(str(tmpdir), "original.yaml")) as ff:
        assert_tree_match(ff.tree, tree)
        assert len(list(ff.blocks.internal_blocks)) == 0