From aeb702d813304b54cc313ce55833a044c45d4745 Mon Sep 17 00:00:00 2001
From: Federico Felici <federico.felici@epfl.ch>
Date: Wed, 3 Jul 2019 19:39:33 +0200
Subject: [PATCH] Rework test suite

* Add 'Slow' tag to mark slow tests
* Separation slow/fast tests done in logical place: get_all_gdat_requests.m
* Added 'TCV' and 'AUG' test options
---
 matlab/run_gdat_tests.m              | 27 +++++++++-----
 matlab/tests/get_all_gdat_requests.m | 23 +++++++++++-
 matlab/tests/test_requestnames.m     | 55 ++++++++++++++++------------
 matlab/tests/test_requestnames_AUG.m |  5 +--
 matlab/tests/test_requestnames_TCV.m |  4 +-
 5 files changed, 75 insertions(+), 39 deletions(-)

diff --git a/matlab/run_gdat_tests.m b/matlab/run_gdat_tests.m
index facc81f4..e17c73af 100644
--- a/matlab/run_gdat_tests.m
+++ b/matlab/run_gdat_tests.m
@@ -7,6 +7,11 @@ if nargin==0 || isempty(test_case)
   test_case = 'basic'; % default
 end
 
+%% Import some classes we need
+import matlab.unittest.selectors.HasTag;
+import matlab.unittest.constraints.ContainsSubstring;
+import matlab.unittest.selectors.HasName;
+
 %% populate suite
 % add path with tests
 addpath(genpath(fullfile(fileparts(mfilename('fullpath')),'tests')));
@@ -20,17 +25,19 @@ switch test_case
   case 'all'
     suite = suite_all; % run all
   case 'basic'
-    import matlab.unittest.selectors.HasParameter;
-    import matlab.unittest.selectors.HasName;
-    import matlab.unittest.selectors.HasTag;
-    import matlab.unittest.constraints.ContainsSubstring;
-    
-    s1 = HasName(ContainsSubstring('TCV')) & ...
-      (HasParameter('Value','ip') | HasParameter('Value','q_rho'));    
-    suite = suite_all.selectIf(s1);
+    s = ~HasTag('Slow');
+    suite = suite_all.selectIf(s);
   case 'IMAS'
-    s2 = HasTag('IMAS');
-    suite = suite_all.selectIf(s2);
+    s = HasTag('IMAS');
+    suite = suite_all.selectIf(s);
+  case 'TCV'
+
+    s = HasName(ContainsSubstring('TCV'));
+    suite = suite_all.selectIf(s);
+  case 'AUG'
+    s = HasName(ContainsSubstring('AUG'));
+    suite = suite_all.selectIf(s);
+    
   otherwise
     error('not yet implemented')
 end
diff --git a/matlab/tests/get_all_gdat_requests.m b/matlab/tests/get_all_gdat_requests.m
index efc96b66..a6791ba5 100644
--- a/matlab/tests/get_all_gdat_requests.m
+++ b/matlab/tests/get_all_gdat_requests.m
@@ -1,4 +1,25 @@
-function requests = get_all_gdat_requests(machine)
+function requests = get_all_gdat_requests(machine,testcase)
   [gd0,~] = gdat('machine',machine);
   requests = gd0.gdat_request;
+  
+switch machine
+  % list of calls that take some time, to be skipped for fast tests
+  case 'TCV'
+      slowlist = {'rtc','mhd','mpx','sxr','psi'};
+  case 'AUG'
+      slowlist = {'sxr','cxrs','transp','te_rho','ne_rho','nete_rho',...
+        'ece_rho','eced_rho','cxrs_rho','eqdsk','equil'}; 
+end
+
+switch testcase
+  case 'fast'
+    requests = requests(~ismember(requests,slowlist));
+    % choose tests not on the slowlist
+  case 'slow'
+    requests = requests(ismember(requests,slowlist));
+    % choose only tests on the slowlist
+  otherwise
+    error('unknown test_case %s',testcase);
+end
+
 end
\ No newline at end of file
diff --git a/matlab/tests/test_requestnames.m b/matlab/tests/test_requestnames.m
index 825e9059..83daa117 100644
--- a/matlab/tests/test_requestnames.m
+++ b/matlab/tests/test_requestnames.m
@@ -4,36 +4,45 @@ classdef (SharedTestFixtures={...
   
   properties (Abstract)
     Machine;
-    Skiplist; % tests to skip
   end
   
   properties(TestParameter,Abstract)
     % parameters that will vary during tests
     shot;
-    request; % placeholders
+    requests_fast; % placeholders
+    requests_slow;
   end
   
-  methods(Test)
-    function test_gdat_call(testCase,shot,request)
-      testCase.assertTrue(isnumeric(str2double(shot)));
-      testCase.assertTrue(ischar(request));
-      
-      testCase.assumeFalse(ismember(testCase.Skiplist,request),...
-        sprintf('Skipped request %s since it is on the skiplist for %s',request,testCase.Machine));
-      
-      % gdat call
-      gdat_call = sprintf(['gdat_' lower(testCase.Machine) '(%s,''%s'')'],shot,request);
-      
-      % logging
-      fprintf('Testing gdat call: %s\n',gdat_call);
-      
-      gdat_out = eval(gdat_call); %#ok<NASGU>
-      
-      % in some future: check for warnings
-      %gdat_out = verifyWarningFree(testCase,eval(gdat_call),...
-      %  'Warning issued from gdat call:\n   %s\n',gdat_call);
-      
-      % (add optional sanity checks of gdat_out here)
+  methods(Test,TestTags = {'Fast'})
+    function test_gdat_call_fast(testCase,shot,requests_fast)
+      test_gdat_call(testCase,shot,requests_fast);
     end
   end
+  
+  methods(Test,TestTags = {'Slow'})
+    function test_gdat_call_slow(testCase,shot,requests_slow)
+      test_gdat_call(testCase,shot,requests_slow);
+    end
+  end
+  
+end
+
+function test_gdat_call(testCase,shot,request)
+% actual function to test gdat call
+testCase.assertTrue(isnumeric(str2double(shot)));
+testCase.assertTrue(ischar(request));
+
+% gdat call
+gdat_call = sprintf(['gdat_' lower(testCase.Machine) '(%s,''%s'')'],shot,request);
+
+% logging
+fprintf('Testing gdat call: %s\n',gdat_call);
+
+gdat_out = eval(gdat_call); %#ok<NASGU>
+
+% in some future: check for warnings
+%gdat_out = verifyWarningFree(testCase,eval(gdat_call),...
+%  'Warning issued from gdat call:\n   %s\n',gdat_call);
+
+% (add optional sanity checks of gdat_out here)
 end
\ No newline at end of file
diff --git a/matlab/tests/test_requestnames_AUG.m b/matlab/tests/test_requestnames_AUG.m
index 7760847a..f5326628 100644
--- a/matlab/tests/test_requestnames_AUG.m
+++ b/matlab/tests/test_requestnames_AUG.m
@@ -3,14 +3,13 @@ classdef test_requestnames_AUG < test_requestnames
   
   properties
     Machine = 'AUG';
-    Skiplist = {'cxrs','transp','te_rho','ne_rho','nete_rho','ece_rho','eced_rho','cxrs_rho','eqdsk','equil'}; 
-    % skip these equest names
   end
   
   properties(TestParameter)
     % parameters that will vary during tests
     shot  = {'30594'};
-    request = get_all_gdat_requests('AUG');
+    requests_fast = get_all_gdat_requests('AUG','fast');
+    requests_slow = get_all_gdat_requests('AUG','slow');  
   end
   
 end
\ No newline at end of file
diff --git a/matlab/tests/test_requestnames_TCV.m b/matlab/tests/test_requestnames_TCV.m
index b1aaebfa..6b605206 100644
--- a/matlab/tests/test_requestnames_TCV.m
+++ b/matlab/tests/test_requestnames_TCV.m
@@ -3,13 +3,13 @@ classdef test_requestnames_TCV < test_requestnames
   
   properties
     Machine = 'TCV';
-    Skiplist = {''}; % skip these calls
   end
   
   properties(TestParameter)
     % parameters that will vary during tests
     shot  = {'48836'};
-    request = get_all_gdat_requests('TCV');
+    requests_fast = get_all_gdat_requests('TCV','fast');
+    requests_slow = get_all_gdat_requests('TCV','slow');
   end
   
 end
\ No newline at end of file
-- 
GitLab