-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Forward slicing in DataIO * Fix #144 by adding copy/deepcopy to DataIO * Add testing for DataIO
- Loading branch information
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import unittest2 as unittest | ||
|
||
from hdmf.data_utils import DataIO | ||
import numpy as np | ||
from copy import copy, deepcopy | ||
|
||
|
||
class DataIOTests(unittest.TestCase): | ||
|
||
def setUp(self): | ||
pass | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test_copy(self): | ||
obj = DataIO(data=[1., 2., 3.]) | ||
obj_copy = copy(obj) | ||
self.assertNotEqual(id(obj), id(obj_copy)) | ||
self.assertEqual(id(obj.data), id(obj_copy.data)) | ||
|
||
def test_deepcopy(self): | ||
obj = DataIO(data=[1., 2., 3.]) | ||
obj_copy = deepcopy(obj) | ||
self.assertNotEqual(id(obj), id(obj_copy)) | ||
self.assertNotEqual(id(obj.data), id(obj_copy.data)) | ||
|
||
def test_dataio_slice_delegation(self): | ||
indata = np.arange(30) | ||
dset = DataIO(indata) | ||
self.assertTrue(np.all(dset[2:15] == indata[2:15])) | ||
|
||
indata = np.arange(50).reshape(5, 10) | ||
dset = DataIO(indata) | ||
self.assertTrue(np.all(dset[1:3, 5:8] == indata[1:3, 5:8])) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |