File: test_tree.py

package info (click to toggle)
zarr 3.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,068 kB
  • sloc: python: 31,589; makefile: 10
file content (62 lines) | stat: -rw-r--r-- 1,695 bytes parent folder | download | duplicates (2)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import textwrap
from typing import Any

import pytest

import zarr

pytest.importorskip("rich")


@pytest.mark.parametrize("root_name", [None, "root"])
def test_tree(root_name: Any) -> None:
    os.environ["OVERRIDE_COLOR_SYSTEM"] = "truecolor"

    g = zarr.group(path=root_name)
    A = g.create_group("A")
    B = g.create_group("B")
    C = B.create_group("C")
    D = C.create_group("C")

    A.create_array(name="x", shape=(2), dtype="float64")
    A.create_array(name="y", shape=(0,), dtype="int8")
    B.create_array(name="x", shape=(0,), dtype="float64")
    C.create_array(name="x", shape=(0,), dtype="float64")
    D.create_array(name="x", shape=(0,), dtype="float64")

    result = repr(g.tree())
    root = root_name or ""

    BOPEN = "\x1b[1m"
    BCLOSE = "\x1b[0m"

    expected = textwrap.dedent(f"""\
        {BOPEN}/{root}{BCLOSE}
        ├── {BOPEN}A{BCLOSE}
        │   ├── {BOPEN}x{BCLOSE} (2,) float64
        │   └── {BOPEN}y{BCLOSE} (0,) int8
        └── {BOPEN}B{BCLOSE}
            ├── {BOPEN}C{BCLOSE}
            │   ├── {BOPEN}C{BCLOSE}
            │   │   └── {BOPEN}x{BCLOSE} (0,) float64
            │   └── {BOPEN}x{BCLOSE} (0,) float64
            └── {BOPEN}x{BCLOSE} (0,) float64
        """)

    assert result == expected

    result = repr(g.tree(level=0))
    expected = textwrap.dedent(f"""\
        {BOPEN}/{root}{BCLOSE}
        ├── {BOPEN}A{BCLOSE}
        └── {BOPEN}B{BCLOSE}
        """)

    assert result == expected


def test_expand_not_implemented() -> None:
    g = zarr.group()
    with pytest.raises(NotImplementedError):
        g.tree(expand=True)