File: test_1525.py

package info (click to toggle)
python-asdf 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 7,032 kB
  • sloc: python: 24,068; makefile: 123
file content (30 lines) | stat: -rw-r--r-- 810 bytes parent folder | download | duplicates (3)
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
import numpy as np
import pytest

import asdf


@pytest.mark.parametrize("memmap", [True, False])
def test_external_blocks_always_lazy_loaded_and_memmapped(tmp_path, memmap):
    """
    External blocks are always lazy loaded and memmapped

    https://github.com/asdf-format/asdf/issues/1525
    """

    fn = tmp_path / "test.asdf"
    arr = np.arange(10)
    af = asdf.AsdfFile({"arr": arr})
    af.set_array_storage(arr, "external")
    af.write_to(fn)

    with asdf.open(fn, memmap=memmap) as af:
        # check that block is external
        source = af["arr"]._source
        assert isinstance(source, str)

        # check if block is memmapped
        if not memmap:
            assert not isinstance(af["arr"].base, np.memmap)
        else:
            assert isinstance(af["arr"].base, np.memmap)