Skip to content

Commit

Permalink
test(test_memh5): add test for memh5 copying and equality
Browse files Browse the repository at this point in the history
  • Loading branch information
ljgray committed Mar 14, 2023
1 parent ba6d1fc commit ce597f2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
29 changes: 29 additions & 0 deletions caput/tests/test_memh5.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import pytest
from pytest_lazyfixture import lazy_fixture
import zarr
import copy

from caput import memh5, fileformats

Expand All @@ -28,6 +29,34 @@ def test_ro_dict():
a["b"] = 6


# Unit test for MemDataset


def test_dataset_copy():
# Check for string types
x = memh5.MemDatasetCommon(shape=(4, 5), dtype=np.float32)
x[:] = 0

# Check a deepcopy using .copy
y = x.copy()
assert x == y
y[:] = 1
# Check this this is in fact a deep copy
assert x != y

# This is a shallow copy
y = x.copy(shallow=True)
assert x == y
y[:] = 1
assert x == y

# Check a deepcopy using copy.deepcopy
y = copy.deepcopy(x)
assert x == y
y[:] = 2
assert x != y


# Unit tests for MemGroup.


Expand Down
29 changes: 29 additions & 0 deletions caput/tests/test_memh5_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np
import h5py
import zarr
import copy

from caput import fileformats, memh5, mpiarray, mpiutil

Expand Down Expand Up @@ -228,3 +229,31 @@ def test_redistribute():
assert g["data"].distributed_axis == 0
g.redistribute(1)
assert g["data"].distributed_axis == 1


# Unit test for MemDataset


def test_dataset_copy():
# Check for string types
x = memh5.MemDatasetDistributed(shape=(4, 5), dtype=np.float32)
x[:] = 0

# Check a deepcopy using .copy
y = x.copy()
assert x == y
y[:] = 1
# Check this this is in fact a deep copy
assert x != y

# This is a shallow copy
y = x.copy(shallow=True)
assert x == y
y[:] = 1
assert x == y

# Check a deepcopy using copy.deepcopy
y = copy.deepcopy(x)
assert x == y
y[:] = 2
assert x != y

0 comments on commit ce597f2

Please sign in to comment.