Skip to content
Snippets Groups Projects
Commit 9239ee99 authored by Federico Felici's avatar Federico Felici Committed by Olivier Sauter
Browse files

Test suite improvements

* Added shared fixtures for setup/teardown
* Split into subclasses for each machine, this allows test
 parameters (shots, request) to vary depending on machine
* Put things into separate test folder
parent b31b09e2
No related branches found
No related tags found
1 merge request!4Feature/testsuite
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
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
function requests = get_all_gdat_requests(machine)
[gd0,~] = gdat('machine',machine);
requests = gd0.gdat_request;
end
\ No newline at end of file
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
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
......
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
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment