File: test_compatibility.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 (36 lines) | stat: -rw-r--r-- 937 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
from __future__ import annotations

import random
from collections import Counter

import pytest

from distributed.compatibility import randbytes


def test_randbytes():
    with pytest.warns(
        DeprecationWarning,
        match=r"randbytes is deprecated and will be removed in a future release; "
        r"use random\.randbytes instead\.",
    ):
        x = randbytes(256_000)
    assert isinstance(x, bytes)
    assert len(x) == 256_000
    c = Counter(x)
    for i in range(256):
        assert 800 < c[i] < 1200, (i, c[i])


def test_randbytes_seed():
    state = random.getstate()
    try:
        random.seed(0)
        with pytest.warns(
            DeprecationWarning,
            match=r"randbytes is deprecated and will be removed in a future release; "
            r"use random\.randbytes instead\.",
        ):
            assert randbytes(8) == b"\xcd\x07,\xd8\xbeo\x9fb"
    finally:
        random.setstate(state)