Skip to content

Commit

Permalink
Test read_from_file with 1-D and 3-D datasets (#86)
Browse files Browse the repository at this point in the history
Add unit tests for `read_from_file` that test cases where the
dataset's rank != 2.
  • Loading branch information
gmgunter authored Sep 16, 2024
1 parent a5da2f7 commit cda19d7
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,25 @@ def test_0d(self):
with pytest.raises(ValueError, match=errmsg):
read_from_file(out_arr, file)

def test_1d(self):
in_arr = np.arange(999)
out_arr = np.empty_like(in_arr)
with tempfile.TemporaryFile() as file:
in_arr.tofile(file)
file.seek(0)
read_from_file(out_arr, file, batchsize=100)
np.testing.assert_array_equal(in_arr, out_arr)

def test_3d(self):
shape = (101, 20, 30)
in_arr = np.arange(np.prod(shape)).reshape(shape)
out_arr = np.empty_like(in_arr)
with tempfile.TemporaryFile() as file:
in_arr.tofile(file)
file.seek(0)
read_from_file(out_arr, file, batchsize=10)
np.testing.assert_array_equal(in_arr, out_arr)


class TestScratchDirectory:
def test_temp_directory(self):
Expand Down

0 comments on commit cda19d7

Please sign in to comment.