diff --git a/matlab/run_gdat_tests.m b/matlab/run_gdat_tests.m index f1feadad69639458a55a38d700597b58dd2c7a5f..93a84e970ad42c3729dd29a843d60640eded6c1a 100644 --- a/matlab/run_gdat_tests.m +++ b/matlab/run_gdat_tests.m @@ -1,16 +1,33 @@ function [passed,results] = run_gdat_tests(test_case) -% test runner for gdat +% test runner for gdat % F. Felici, EPFL federico.felici@epfl.ch if nargin==0 - test_case = 'all'; % deafult + test_case = 'all'; % default end %% populate suite +% add path with tests +addpath(genpath(fullfile(fileparts(mfilename('fullpath')),'tests'))); + +suite_all = [matlab.unittest.TestSuite.fromClass(?test_requestnames_TCV),... + matlab.unittest.TestSuite.fromClass(?test_requestnames_AUG)]; + switch test_case case 'all' - suite = matlab.unittest.TestSuite.fromClass(?test_requestnames); + suite = suite_all; % run all + case 'basic' + import matlab.unittest.selectors.HasParameter; + import matlab.unittest.selectors.HasName; + import matlab.unittest.constraints.ContainsSubstring; + + suite = suite_all.selectIf(HasName(ContainsSubstring('TCV')) & ... + (HasParameter('Value','ip') | HasParameter('Value','q_rho'))); + case 'TCV' + suite = suite_all.selectIf(HasParameter('machine',IsEqualTo('TCV'))); + case 'AUG' + suite = suite_all.selectIf(HasParameter('machine',IsEqualTo('AUG'))); otherwise error('not yet implemented') end @@ -21,7 +38,6 @@ results = run(suite); disp(table(results)); fprintf('\nTotal test duration: %5.2fs\n',sum(table(results).Duration)) - %% display results if all([results.Passed]) fprintf('\nPassed all tests\n') @@ -42,3 +58,25 @@ end end +function [shots,request_list] = get_gdat_test_params(machine) + +% get requests for this machine +[gd0,~] = gdat('machine',machine); +request_list = gd0.gdat_request; + +% get test shot list for this machine +shots = get_shots(machine); +end + + +function shots = get_shots(machine) +switch machine + case 'AUG' + shots = {num2str(30594)}; % use strings for display purposes + case 'TCV' + shots = {num2str(48836)}; + otherwise + error('no shot defined for this machine') +end +end + diff --git a/matlab/tests/check_mds.m b/matlab/tests/check_mds.m new file mode 100644 index 0000000000000000000000000000000000000000..51ff6d391f0f2d4a4ef37924eebe41859df58836 --- /dev/null +++ b/matlab/tests/check_mds.m @@ -0,0 +1,8 @@ +classdef check_mds < matlab.unittest.fixtures.Fixture + methods + function setup(fixture) + fixture.assumeFalse(~exist('mdsdata','file'),'mdsdata not found - is mds on path?'); + % other environment checks here + end + end +end \ No newline at end of file diff --git a/matlab/tests/get_all_gdat_requests.m b/matlab/tests/get_all_gdat_requests.m new file mode 100644 index 0000000000000000000000000000000000000000..efc96b66d03a4a99e32bf3567b1ebb17c3624c65 --- /dev/null +++ b/matlab/tests/get_all_gdat_requests.m @@ -0,0 +1,4 @@ +function requests = get_all_gdat_requests(machine) + [gd0,~] = gdat('machine',machine); + requests = gd0.gdat_request; +end \ No newline at end of file diff --git a/matlab/tests/setup_gdatpaths.m b/matlab/tests/setup_gdatpaths.m new file mode 100644 index 0000000000000000000000000000000000000000..67baae309fba74724e9b565e3276effd9ce44953 --- /dev/null +++ b/matlab/tests/setup_gdatpaths.m @@ -0,0 +1,9 @@ +classdef setup_gdatpaths < matlab.unittest.fixtures.Fixture + methods + function setup(fixture) + p = path; % get current matlab path (pre-testing) + fixture.addTeardown(@path,p); % teardown function to restore path + gdatpaths; % script to set up paths + end + end +end \ No newline at end of file diff --git a/matlab/test_requestnames.m b/matlab/tests/test_requestnames.m similarity index 68% rename from matlab/test_requestnames.m rename to matlab/tests/test_requestnames.m index e51ba862f9a289348c691e6a45c7e4d552eb7d20..73e64be52ae2509f8686abe8b140a7dafc9fe52b 100644 --- a/matlab/test_requestnames.m +++ b/matlab/tests/test_requestnames.m @@ -1,27 +1,30 @@ -classdef test_requestnames < matlab.unittest.TestCase +classdef (SharedTestFixtures={... + check_mds,setup_gdatpaths}) ... + test_requestnames < matlab.unittest.TestCase - properties(TestParameter) - gdat_test_params = get_gdat_test_params(); +properties(TestParameter,Abstract) + % parameters that will vary during tests + shot; + request; % placeholders end - - methods(TestClassSetup) - function testMDS(testCase) - testCase.assumeFalse(~exist('mdsdata','file'),'mdsdata not found - is mds on path?'); - % other environment checks here - end - end - + methods(Test) - function test_gdat_call(testCase,gdat_test_params) - machine = gdat_test_params{1}; - shot = gdat_test_params{2}; - gdat_request = gdat_test_params{3}; + function test_gdat_call(testCase,shot,request) + testCase.assertTrue(isnumeric(num2str(shot))); + testCase.assertTrue(ischar(request)); + + % gdat call + gdat_call = sprintf(['gdat_' lower(testCase.machine) '(%s,''%s'')'],shot,request); + + % logging + testCase.log(sprintf('gdat_call: %s\n',gdat_call)); + + gdat_out = eval(gdat_call); - gdat_call = sprintf(['gdat_' lower(machine) '(%d,''%s'')'],shot,gdat_request); + % in some future: check for warnings - testCase.log(sprintf('gdat_call: %s\n',gdat_call)); - gdat_out = verifyWarningFree(testCase,eval(gdat_call),... - 'Warning issued from gdat call:\n %s\n',gdat_call); + %gdat_out = verifyWarningFree(testCase,eval(gdat_call),... + % 'Warning issued from gdat call:\n %s\n',gdat_call); % add content checks of gdat_out here end @@ -29,42 +32,8 @@ classdef test_requestnames < matlab.unittest.TestCase end -function test_params = get_gdat_test_params() - -machines = {'AUG','TCV'}; - -test_params = cell(0,1); % init -for im = 1:numel(machines) - % get requests for this machine - machine = machines{im}; - [gd0,~] = gdat('machine',machine); - request_list = gd0.gdat_request; - % get test shot list for this machine - shots = get_shots(machine); - for ishot = 1:numel(shots) - shot = shots(ishot); - for ireq = 1:numel(request_list) - % populate cell of test parameters - test_params = [test_params;{{machine,shot,request_list{ireq}}}]; %#ok<AGROW> - end - end -end -end - - -function shot = get_shots(machine) -switch machine - case 'AUG' - shot = 30594; - case 'TCV' - shot = 48836; - otherwise - error('no shot defined for this machine') -end -end -% % methods(TestClassSetup) % function getShot(testCase,machine) % switch machine diff --git a/matlab/tests/test_requestnames_AUG.m b/matlab/tests/test_requestnames_AUG.m new file mode 100644 index 0000000000000000000000000000000000000000..18b5da42d93588d8aaed070155c3eda92a8217eb --- /dev/null +++ b/matlab/tests/test_requestnames_AUG.m @@ -0,0 +1,10 @@ +classdef test_requestnames_AUG < test_requestnames + % everything implemented in superclass + + properties(TestParameter) + % parameters that will vary during tests + shot = {'30594'}; + request = get_all_gdat_requests('AUG'); + end + +end \ No newline at end of file diff --git a/matlab/tests/test_requestnames_TCV.m b/matlab/tests/test_requestnames_TCV.m new file mode 100644 index 0000000000000000000000000000000000000000..8f84cfecef5c1e917d72b13e87a853cea36d61ef --- /dev/null +++ b/matlab/tests/test_requestnames_TCV.m @@ -0,0 +1,11 @@ +classdef test_requestnames_TCV < test_requestnames + % everything is implemented in superclass! + + properties(TestParameter) + % parameters that will vary during tests + shot = {'48836'}; + request = get_all_gdat_requests('TCV'); + end + + +end \ No newline at end of file