| 1 |
from hdmf.data_utils import append_data |
| 2 |
from hdmf.testing import TestCase |
| 3 |
|
| 4 |
import numpy as np |
| 5 |
from numpy.testing import assert_array_equal |
| 6 |
|
| 7 |
try: |
| 8 |
import zarr |
| 9 |
ZARR_INSTALLED = True |
| 10 |
except ImportError: |
| 11 |
ZARR_INSTALLED = False |
| 12 |
|
| 13 |
|
| 14 |
class MyIterable: |
| 15 |
def __init__(self, data): |
| 16 |
self.data = data |
| 17 |
|
| 18 |
|
| 19 |
class TestAppendData(TestCase): |
| 20 |
def test_append_exception(self): |
| 21 |
data = MyIterable([1, 2, 3, 4, 5]) |
| 22 |
with self.assertRaises(ValueError): |
| 23 |
append_data(data, 4) |
| 24 |
|
| 25 |
|
| 26 |
class TestZarrAppendData(TestCase): |
| 27 |
|
| 28 |
def setUp(self): |
| 29 |
if not ZARR_INSTALLED: |
| 30 |
self.skipTest("optional Zarr package is not installed") |
| 31 |
|
| 32 |
|
| 33 |
def test_append_data_zarr(self): |
| 34 |
zarr_array = zarr.array([1,2,3]) |
| 35 |
new = append_data(zarr_array, 4) |
| 36 |
|
| 37 |
assert_array_equal(new[:], np.array([1,2,3,4])) |