File: test_utils.py

package info (click to toggle)
dask.distributed 2024.12.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 12,588 kB
  • sloc: python: 96,954; javascript: 1,549; sh: 390; makefile: 220
file content (27 lines) | stat: -rw-r--r-- 643 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
from __future__ import annotations

import pytest

from distributed.protocol.utils import host_array, host_array_from_buffers


def test_host_array():
    a = host_array(5)
    a[:3] = b"abc"
    a[3:] = b"de"
    assert bytes(a) == b"abcde"


def test_host_array_from_buffers():
    a = host_array_from_buffers([b"abc", b"de"])
    a[:1] = b"f"
    assert bytes(a) == b"fbcde"


def test_host_array_from_buffers_numpy():
    """Test for word sizes larger than 1 byte"""
    np = pytest.importorskip("numpy")
    a = host_array_from_buffers(
        [np.array([1, 2], dtype="u1"), np.array([3, 4], dtype="u8")]
    )
    assert a.nbytes == 18