# Path: zarr/util.py
# def flatten(arg: Iterable) -> Iterable:
# def json_dumps(o: Any) -> bytes:
# def json_loads(s: str) -> Dict[str, Any]:
# def normalize_shape(shape) -> Tuple[int]:
# def guess_chunks(shape: Tuple[int, ...], typesize: int) -> Tuple[int, ...]:
# def normalize_chunks(
#     chunks: Any, shape: Tuple[int, ...], typesize: int
# ) -> Tuple[int, ...]:
# def normalize_dtype(dtype: Union[str, np.dtype], object_codec) -> Tuple[np.dtype, Any]:
# def is_total_slice(item, shape: Tuple[int]) -> bool:
# def normalize_resize_args(old_shape, *args):
# def human_readable_size(size) -> str:
# def normalize_order(order: str) -> str:
# def normalize_dimension_separator(sep: Optional[str]) -> Optional[str]:
# def normalize_fill_value(fill_value, dtype: np.dtype):
# def normalize_storage_path(path: Union[str, bytes, None]) -> str:
# def buffer_size(v) -> int:
# def info_text_report(items: Dict[Any, Any]) -> str:
# def info_html_report(items) -> str:
#     def __init__(self, obj):
#     def __repr__(self):
#     def _repr_html_(self):
#     def __init__(self, obj, depth=0, level=None):
#     def get_children(self):
#     def get_text(self):
#     def get_type(self):
#     def get_children(self, node):
#     def get_root(self, tree):
#     def get_text(self, node):
# def tree_get_icon(stype: str) -> str:
# def tree_widget_sublist(node, root=False, expand=False):
# def tree_widget(group, expand, level):
#     def __init__(self, group, expand=False, level=None):
#     def __bytes__(self):
#     def __unicode__(self):
#     def __repr__(self):
#     def _ipython_display_(self):
# def check_array_shape(param, array, shape):
# def is_valid_python_name(name):
#     def __enter__(self):
#     def __exit__(self, *args):
#     def __init__(self, store_key, chunk_store):
#     def prepare_chunk(self):
#     def read_part(self, start, nitems):
#     def read_full(self):
# def retry_call(callabl: Callable,
#                args=None,
#                kwargs=None,
#                exceptions: Tuple[Any, ...] = (),
#                retries: int = 10,
#                wait: float = 0.1) -> Any:
# def all_equal(value: Any, array: Any):
# CHUNK_BASE = 256*1024  # Multiplier by which chunks are adjusted
# CHUNK_MIN = 128*1024  # Soft lower limit (128k)
# CHUNK_MAX = 64*1024*1024  # Hard upper limit
# class InfoReporter:
# class TreeNode:
# class TreeTraversal(Traversal):
# class TreeViewer:
# class NoLock:
# class PartialReadBuffer:


import re
import numpy as np
import pytest
from unittest import mock
from zarr.util import (all_equal, flatten, guess_chunks, human_readable_size, info_html_report,
                       info_text_report, is_total_slice, normalize_chunks,
                       normalize_dimension_separator,
                       normalize_fill_value, normalize_order,
                       normalize_resize_args, normalize_shape, retry_call,
                       tree_array_icon, tree_group_icon, tree_get_icon,
                       tree_widget)
        (0, 10),
        (1, 2, 0, 4, 5),
    )
    for shape in shapes:
        chunks = guess_chunks(shape, 1)
        assert isinstance(chunks, tuple)
        assert len(chunks) == len(shape)
        # doesn't make any sense to allow chunks to have zero length dimension
        assert all(0 < c <= max(s, 1) for c, s in zip(chunks, shape))

    # ludicrous itemsize
    chunks = guess_chunks((1000000,), 40000000000)
    assert isinstance(chunks, tuple)
    assert (1,) == chunks


def test_info_text_report():
    items = [('foo', 'bar'), ('baz', 'qux')]
    expect = "foo : bar\nbaz : qux\n"
    assert expect == info_text_report(items)


def test_info_html_report():
    items = [('foo', 'bar'), ('baz', 'qux')]
    actual = info_html_report(items)
    assert '<table' == actual[:6]
    assert '</table>' == actual[-8:]


def test_tree_get_icon():

# Path: zarr/util.py
# def flatten(arg: Iterable) -> Iterable:
# def json_dumps(o: Any) -> bytes:
# def json_loads(s: str) -> Dict[str, Any]:
# def normalize_shape(shape) -> Tuple[int]:
# def guess_chunks(shape: Tuple[int, ...], typesize: int) -> Tuple[int, ...]:
# def normalize_chunks(
#     chunks: Any, shape: Tuple[int, ...], typesize: int
# ) -> Tuple[int, ...]:
# def normalize_dtype(dtype: Union[str, np.dtype], object_codec) -> Tuple[np.dtype, Any]:
# def is_total_slice(item, shape: Tuple[int]) -> bool:
# def normalize_resize_args(old_shape, *args):
# def human_readable_size(size) -> str:
# def normalize_order(order: str) -> str:
# def normalize_dimension_separator(sep: Optional[str]) -> Optional[str]:
# def normalize_fill_value(fill_value, dtype: np.dtype):
# def normalize_storage_path(path: Union[str, bytes, None]) -> str:
# def buffer_size(v) -> int:
# def info_text_report(items: Dict[Any, Any]) -> str:
# def info_html_report(items) -> str:
#     def __init__(self, obj):
#     def __repr__(self):
#     def _repr_html_(self):
#     def __init__(self, obj, depth=0, level=None):
#     def get_children(self):
#     def get_text(self):
#     def get_type(self):
#     def get_children(self, node):
#     def get_root(self, tree):
#     def get_text(self, node):
# def tree_get_icon(stype: str) -> str:
# def tree_widget_sublist(node, root=False, expand=False):
# def tree_widget(group, expand, level):
#     def __init__(self, group, expand=False, level=None):
#     def __bytes__(self):
#     def __unicode__(self):
#     def __repr__(self):
#     def _ipython_display_(self):
# def check_array_shape(param, array, shape):
# def is_valid_python_name(name):
#     def __enter__(self):
#     def __exit__(self, *args):
#     def __init__(self, store_key, chunk_store):
#     def prepare_chunk(self):
#     def read_part(self, start, nitems):
#     def read_full(self):
# def retry_call(callabl: Callable,
#                args=None,
#                kwargs=None,
#                exceptions: Tuple[Any, ...] = (),
#                retries: int = 10,
#                wait: float = 0.1) -> Any:
# def all_equal(value: Any, array: Any):
# CHUNK_BASE = 256*1024  # Multiplier by which chunks are adjusted
# CHUNK_MIN = 128*1024  # Soft lower limit (128k)
# CHUNK_MAX = 64*1024*1024  # Hard upper limit
# class InfoReporter:
# class TreeNode:
# class TreeTraversal(Traversal):
# class TreeViewer:
# class NoLock:
# class PartialReadBuffer:


# Path: zarr/tests/test_util.py
import re
import numpy as np
import pytest
from unittest import mock
from zarr.util import (all_equal, flatten, guess_chunks, human_readable_size, info_html_report,
                       info_text_report, is_total_slice, normalize_chunks,
                       normalize_dimension_separator,
                       normalize_fill_value, normalize_order,
                       normalize_resize_args, normalize_shape, retry_call,
                       tree_array_icon, tree_group_icon, tree_get_icon,
                       tree_widget)

        (0, 10),
        (1, 2, 0, 4, 5),
    )
    for shape in shapes:
        chunks = guess_chunks(shape, 1)
        assert isinstance(chunks, tuple)
        assert len(chunks) == len(shape)
        # doesn't make any sense to allow chunks to have zero length dimension
        assert all(0 < c <= max(s, 1) for c, s in zip(chunks, shape))

    # ludicrous itemsize
    chunks = guess_chunks((1000000,), 40000000000)
    assert isinstance(chunks, tuple)
    assert (1,) == chunks


def test_info_text_report():
    items = [('foo', 'bar'), ('baz', 'qux')]
    expect = "foo : bar\nbaz : qux\n"
    assert expect == info_text_report(items)


def test_info_html_report():
    items = [('foo', 'bar'), ('baz', 'qux')]
    actual = info_html_report(items)
    assert '<table' == actual[:6]
    assert '</table>' == actual[-8:]


def test_tree_get_icon():

    assert tree_get_icon("Array") == tree_array_icon