File: test_1523.py

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

import asdf


def test_update_corrupts_stream_data(tmp_path):
    """
    update corrupts stream data
    https://github.com/asdf-format/asdf/issues/1523
    """
    fn = tmp_path / "stream.asdf"

    s = asdf.Stream([3], np.uint8)
    asdf.AsdfFile({"s": s}).write_to(fn)

    with open(fn, "rb+") as f:
        f.seek(0, 2)
        f.write(b"\x01\x02\x03")

    with asdf.open(fn) as af:
        np.testing.assert_array_equal(af["s"], [[1, 2, 3]])

    with asdf.open(fn, mode="rw") as af:
        af["a"] = np.arange(1000)
        af.update()
        np.testing.assert_array_equal(af["s"], [[1, 2, 3]])

    with asdf.open(fn) as af:
        np.testing.assert_array_equal(af["s"], [[1, 2, 3]])