Skip to content

Commit

Permalink
Expand test to cover incorrect file extension
Browse files Browse the repository at this point in the history
  • Loading branch information
btreeby committed Jun 4, 2023
1 parent c6651d4 commit d02991a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion +h5tools/private/mustBeH5File.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function mustBeH5File(filename)

[~, ~, ext] = fileparts(filename);
if ~strcmp(ext, '.h5')
eid = 'Filename:wrongExtension';
eid = 'h5tools:wrongExtension';
msg = 'Filename must have .h5 extension.';
throwAsCaller(MException(eid, msg));
end
15 changes: 13 additions & 2 deletions tests/test_copyGroup.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
properties
fromFile = 'testFrom.h5';
toFile = 'testTo.h5';
textFile = 'textFile.txt';
groupFile1 = 'testGroup1';
datasetFile1 = 'testDataset1'
Expand All @@ -24,7 +25,8 @@
methods (TestMethodSetup)
% Create two HDF5 files, both containing a group with a dataset.
% Create two HDF5 files, both containing a group with a dataset,
% and a text file.
function createH5Files(testCase)
testCase.dataFile1 = rand(testCase.dimsFile1);
testCase.dataFile2 = rand(testCase.dimsFile2);
Expand All @@ -34,6 +36,8 @@ function createH5Files(testCase)
h5create(testCase.toFile, ['/' testCase.groupFile2 '/' testCase.datasetFile2], testCase.dimsFile2);
h5write(testCase.toFile, ['/' testCase.groupFile2 '/' testCase.datasetFile2], testCase.dataFile2);
writelines("Hello world", testCase.textFile);
end
end
Expand All @@ -44,6 +48,7 @@ function createH5Files(testCase)
function deleteH5Files(testCase)
delete(testCase.fromFile);
delete(testCase.toFile);
delete(testCase.textFile);
end
end
Expand All @@ -54,10 +59,16 @@ function deleteH5Files(testCase)
% dataset is correct.
function testValidInput(testCase)
h5tools.copyGroup(testCase.fromFile, testCase.toFile, testCase.groupFile1);
dataOut = h5read(testCase.toFile, ['/' testCase.groupFile1 '/' testCase.datasetFile1]);
testCase.verifyEqual(dataOut, testCase.dataFile1);
end
% Copy a dataset with the wrong extension.
function testInvalidInput(testCase)
testCase.verifyError( ...
@() h5tools.copyGroup(testCase.fromFile, testCase.textFile, testCase.groupFile1), ...
'h5tools:wrongExtension');
end

end

Expand Down

0 comments on commit d02991a

Please sign in to comment.