Skip to content

Commit

Permalink
remove dupe test
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed May 31, 2021
1 parent 4b5ae00 commit c7fd7cd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 138 deletions.
5 changes: 2 additions & 3 deletions +gemini3d/+tests/TestDataIO.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

function setup_env(tc)

import gemini3d.fileio.download_and_extract

cwd = fileparts(mfilename('fullpath'));
tc.TestData.cwd = cwd;

Expand All @@ -19,7 +17,8 @@ function setup_env(tc)
% setup so that hdf5nc is present
run(fullfile(cwd, "../../setup.m"))

download_and_extract(tc.TestData.name, fullfile(cwd, "data"))
% don't import so it sets up first
gemini3d.fileio.download_and_extract(tc.TestData.name, fullfile(cwd, "data"))

% temporary working directory
tc.TestData.outdir = tc.applyFixture(matlab.unittest.fixtures.TemporaryFolderFixture()).Folder;
Expand Down
5 changes: 3 additions & 2 deletions +gemini3d/+tests/TestDryrun.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@

function setup_sim(tc)

import gemini3d.fileio.download_and_extract
cwd = fileparts(mfilename('fullpath'));
run(fullfile(cwd, '../../setup.m'))

name = "2dew_eq";

cwd = fileparts(mfilename('fullpath'));
tc.TestData.datapath = fullfile(cwd, "data", name);

% get files if needed
download_and_extract(name, fullfile(cwd, "data"))
gemini3d.fileio.download_and_extract(name, fullfile(cwd, "data"))

% temporary working directory
tc.TestData.outdir = tc.applyFixture(matlab.unittest.fixtures.TemporaryFolderFixture('PreservingOnFailure', true)).Folder;
Expand Down
4 changes: 4 additions & 0 deletions +gemini3d/+tests/TestProject.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

methods(TestMethodSetup)
function setup_env(tc)

cwd = fileparts(mfilename('fullpath'));

run(fullfile(cwd, '../../setup.m'))

tc.TestData.cwd = cwd;
tc.TestData.ref_dir = fullfile(cwd, "data");

Expand Down
138 changes: 5 additions & 133 deletions +gemini3d/+tests/TestUnit.m
Original file line number Diff line number Diff line change
@@ -1,146 +1,18 @@
classdef TestUnit < matlab.unittest.TestCase

methods (Test)

function test_expanduser(tc)

import stdlib.fileio.expanduser

tc.verifyFalse(startsWith(expanduser('~/foo'), "~"))
tc.verifyFalse(any(startsWith(expanduser(["~/abc", "~/123"]), "~")))

tc.verifyTrue(endsWith(expanduser('~/foo'), "foo"))
tc.verifyTrue(all(endsWith(expanduser(["~/abc", "~/123"]), ["abc", "123"])))

tc.verifyEmpty(expanduser(string.empty))
tc.verifyEqual(expanduser(""), "")
end

function test_posix(tc)
import stdlib.fileio.posix

if ispc
tc.verifyFalse(contains(posix("c:\foo"), "\"))
tc.verifyFalse(any(contains(posix(["x:\123", "d:\abc"]), "\")))
end

tc.verifyEmpty(posix(string.empty))
end

function test_is_absolute_path(tc)

import stdlib.fileio.is_absolute_path

% path need not exist
tc.verifyTrue(is_absolute_path('~/foo'))
if ispc
tc.verifyTrue(is_absolute_path('x:/foo'))
tc.verifyEqual(is_absolute_path(["x:/abc", "x:/123", "", "c"]), [true, true, false, false])
tc.verifyTrue(all(is_absolute_path(["x:/abc"; "x:/123"])))
tc.verifyFalse(is_absolute_path('/foo'))
else
tc.verifyTrue(is_absolute_path('/foo'))
end

tc.verifyEmpty(is_absolute_path(string.empty))
tc.verifyFalse(is_absolute_path(""))
tc.verifyFalse(is_absolute_path("c"))
end

function test_absolute_path(tc)

import stdlib.fileio.absolute_path

pabs = absolute_path('2foo');
pabs2 = absolute_path('4foo');
tc.verifyFalse(startsWith(pabs, "2"))
tc.verifyTrue(strncmp(pabs, pabs2, 2))

par1 = absolute_path("../2foo");
par2 = absolute_path("../4foo");
tc.verifyFalse(startsWith(par1, ".."))
tc.verifyTrue(strncmp(par2, pabs2, 2))

pt1 = absolute_path("bar/../2foo");
tc.verifyFalse(contains(pt1, ".."))
methods(TestMethodSetup)

va = absolute_path(["2foo", "4foo"]);
tc.verifyFalse(any(startsWith(va, "2")))
vs = extractBefore(va, 2);
tc.verifyEqual(vs(1), vs(2))
function setup_stdlib(tc) %#ok<MANU>

tc.verifyEmpty(absolute_path(string.empty))
tc.verifyEqual(absolute_path(""), string(pwd))
end

function test_makedir(tc)

import stdlib.fileio.makedir
d = tempname;
makedir(d)
tc.assertTrue(isfolder(d))
end

function test_which(tc)

import stdlib.fileio.which
cwd = fileparts(mfilename('fullpath'));
run(fullfile(cwd, '../../setup.m'))

tc.verifyEmpty(which(string.empty))

n = "matlab";
% assumes Matlab in environment variable PATH
tc.assumeNotEmpty(which(n))

p = fullfile(matlabroot, "bin", n);

% full absolute path
exe = which(p);

if ispc
tc.verifyTrue(endsWith(exe, ".exe"))
else
tc.verifyFalse(endsWith(exe, ".exe"))
end
tc.assertTrue(isfile(exe))

end

function test_with_suffix(tc)

import stdlib.fileio.with_suffix

tc.verifyEqual(with_suffix("foo.h5", ".nc"), "foo.nc")
if ~verLessThan("matlab", "9.9")
% fileparts vectorized in R2020b
tc.verifyEqual(with_suffix(["foo.h5", "bar.dat"], ".nc"), ["foo.nc", "bar.nc"])

tc.verifyEmpty(with_suffix(string.empty, ".nc"))
tc.verifyEqual(with_suffix("", ""), "")
tc.verifyEqual(with_suffix("c", ""), "c")
tc.verifyEqual(with_suffix("c.nc", ""), "c")
tc.verifyEqual(with_suffix("", ".nc"), ".nc")
end
end

function test_path_tail(tc)

import stdlib.fileio.path_tail

tc.verifyEqual(path_tail("a/b/c.h5"), "c.h5")
tc.verifyEqual(path_tail("c.h5"), "c.h5")
tc.verifyEqual(path_tail("a/b/c/"), "c")

if ~verLessThan("matlab", "9.9")
% fileparts vectorized in R2020b
tc.verifyEqual(path_tail(["c.h5", "a/b/c/"]), ["c.h5", "c"])

tc.verifyEmpty(path_tail(string.empty))
tc.verifyEqual(strlength(path_tail("")), 0)
methods (Test)

tc.verifyEqual(path_tail(["", "a/b"]), ["", "b"])
tc.verifyEqual(path_tail("c"), "c")
end
end

function test_nml_gemini_simroot(tc)

Expand Down

0 comments on commit c7fd7cd

Please sign in to comment.