1####################################################################### 2# Copyright (C) 2019-present, Blosc Development team <blosc@blosc.org> 3# All rights reserved. 4# 5# This source code is licensed under a BSD-style license (found in the 6# LICENSE file in the root directory of this source tree) 7####################################################################### 8 9import caterva as cat 10import pytest 11import numpy as np 12import os 13from msgpack import packb 14 15 16@pytest.mark.parametrize("sequencial", 17 [ 18 True, 19 False, 20 ]) 21@pytest.mark.parametrize("shape, chunks, blocks, urlpath, dtype", 22 [ 23 ([556], [221], [33], "testmeta00.cat", np.float64), 24 ([20, 134, 13], [12, 66, 8], [3, 13, 5], "testmeta01.cat", np.int32), 25 ([12, 13, 14, 15, 16], [8, 9, 4, 12, 9], [2, 6, 4, 5, 4], "testmeta02.cat", np.float32) 26 ]) 27def test_metalayers(shape, chunks, blocks, urlpath, sequencial, dtype): 28 if os.path.exists(urlpath): 29 cat.remove(urlpath) 30 31 numpy_meta = packb({b"dtype": str(np.dtype(dtype))}) 32 test_meta = packb({b"lorem": 1234}) 33 34 # Create an empty caterva array (on disk) 35 itemsize = np.dtype(dtype).itemsize 36 a = cat.empty(shape, itemsize, chunks=chunks, blocks=blocks, 37 urlpath=urlpath, sequencial=sequencial, 38 meta={"numpy": numpy_meta, 39 "test": test_meta}) 40 41 assert ("numpy" in a.meta) 42 assert ("error" not in a.meta) 43 assert (a.meta["numpy"] == numpy_meta) 44 assert ("test" in a.meta) 45 assert (a.meta["test"] == test_meta) 46 47 test_meta = packb({b"lorem": 4231}) 48 a.meta["test"] = test_meta 49 assert (a.meta["test"] == test_meta) 50 51 # Remove file on disk 52 cat.remove(urlpath) 53