From 44db5d24d89b7e623a9901298988cccaf1ca69c7 Mon Sep 17 00:00:00 2001
From: Federico Felici <federico.felici@epfl.ch>
Date: Tue, 2 Jul 2019 22:53:49 +0200
Subject: [PATCH] Add ids tests and cleanup requestnames classes

---
 matlab/TCV_IMAS/test_tcv_get_ids.m   | 33 +++++++++++++------------
 matlab/run_gdat_tests.m              | 37 ++++++++--------------------
 matlab/tests/test_requestnames.m     | 18 ++++++++------
 matlab/tests/test_requestnames_AUG.m |  5 +++-
 matlab/tests/test_requestnames_TCV.m |  5 +++-
 5 files changed, 46 insertions(+), 52 deletions(-)

diff --git a/matlab/TCV_IMAS/test_tcv_get_ids.m b/matlab/TCV_IMAS/test_tcv_get_ids.m
index 78cec894..2ae96cfd 100644
--- a/matlab/TCV_IMAS/test_tcv_get_ids.m
+++ b/matlab/TCV_IMAS/test_tcv_get_ids.m
@@ -1,16 +1,17 @@
-function passed = test_tcv_get_ids
-
-thispath = fileparts(mfilename('fullpath'));
-run(fullfile(thispath,'..','gdatpaths'));
-
-% simple test to check functionality
-
-shotlist = [-1,40000];
-
-for ishot=1:numel(shotlist)
-  shot = shotlist(ishot);
-  pf_active = tcv2ids(shot,'ids_names',{'pf_active','wall'});
-end
-
-passed = true;
-end
+classdef (SharedTestFixtures={...
+        check_mds,setup_gdatpaths})...
+        test_tcv_get_ids < matlab.unittest.TestCase
+  
+  properties(TestParameter)
+    shot = {'-1','40000','61400'};
+    ids_name = {'pf_active','wall'};
+  end
+  
+  methods(Test,TestTags = {'IMAS'})
+    function test_tcv2ids(testCase,shot,ids_name)
+      ids = tcv2ids(shot,ids_name);
+      testCase.assertTrue(~isempty(ids))
+    end
+  end
+  
+end
\ No newline at end of file
diff --git a/matlab/run_gdat_tests.m b/matlab/run_gdat_tests.m
index d9bbf28e..4420a65e 100644
--- a/matlab/run_gdat_tests.m
+++ b/matlab/run_gdat_tests.m
@@ -10,9 +10,11 @@ end
 %% populate suite
 % add path with tests
 addpath(genpath(fullfile(fileparts(mfilename('fullpath')),'tests')));
+addpath(genpath(fullfile(fileparts(mfilename('fullpath')),'TCV_IMAS')));
 
 suite_all = [matlab.unittest.TestSuite.fromClass(?test_requestnames_TCV),...
-  matlab.unittest.TestSuite.fromClass(?test_requestnames_AUG)];
+  matlab.unittest.TestSuite.fromClass(?test_requestnames_AUG),...
+  matlab.unittest.TestSuite.fromClass(?test_tcv_get_ids)];
 
 switch test_case
   case 'all'
@@ -20,10 +22,15 @@ switch test_case
   case 'basic'
     import matlab.unittest.selectors.HasParameter;
     import matlab.unittest.selectors.HasName;
+    import matlab.unittest.selectors.HasTag;
+
     import matlab.unittest.constraints.ContainsSubstring;
     
-    suite = suite_all.selectIf(HasParameter('Value','TCV') & ...
-      (HasParameter('Value','ip') | HasParameter('Value','q_rho')));
+    s1 = HasName(ContainsSubstring('TCV')) & ...
+      (HasParameter('Value','ip') | HasParameter('Value','q_rho'));
+    s2 = HasTag('IMAS');
+    
+    suite = suite_all.selectIf(s1 | s2);
   case 'TCV'
     suite = suite_all.selectIf(HasParameter('machine',IsEqualTo('TCV')));
   case 'AUG'
@@ -56,27 +63,3 @@ else
 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/test_requestnames.m b/matlab/tests/test_requestnames.m
index ec9a92ae..b793dcd0 100644
--- a/matlab/tests/test_requestnames.m
+++ b/matlab/tests/test_requestnames.m
@@ -1,19 +1,23 @@
 classdef (SharedTestFixtures={...
-        check_mds,setup_gdatpaths}) ...
-        test_requestnames < matlab.unittest.TestCase
+    check_mds,setup_gdatpaths}) ...
+    test_requestnames < matlab.unittest.TestCase
   
-properties(TestParameter,Abstract)
-    % parameters that will vary during tests
+  properties (Abstract)
     machine;
+  end
+  
+  properties(TestParameter,Abstract)
+    % parameters that will vary during tests
     shot;
     request; % placeholders
   end
-      
+  
   methods(Test)
-    function test_gdat_call(testCase,machine,shot,request)
+    function test_gdat_call(testCase,shot,request)
       testCase.assertTrue(isnumeric(str2double(shot)));
       testCase.assertTrue(ischar(request));
-
+      
+      machine = testCase.machine;
       % gdat call
       gdat_call = sprintf(['gdat_' lower(machine) '(%s,''%s'')'],shot,request);
       
diff --git a/matlab/tests/test_requestnames_AUG.m b/matlab/tests/test_requestnames_AUG.m
index f510dd66..4ed042cd 100644
--- a/matlab/tests/test_requestnames_AUG.m
+++ b/matlab/tests/test_requestnames_AUG.m
@@ -1,9 +1,12 @@
 classdef test_requestnames_AUG < test_requestnames
   % everything implemented in superclass
   
+  properties
+    machine = 'AUG';
+  end
+  
   properties(TestParameter)
     % parameters that will vary during tests
-    machine = {'AUG'};
     shot  = {'30594'};
     request = get_all_gdat_requests('AUG');
   end
diff --git a/matlab/tests/test_requestnames_TCV.m b/matlab/tests/test_requestnames_TCV.m
index 871cd50e..4eabc234 100644
--- a/matlab/tests/test_requestnames_TCV.m
+++ b/matlab/tests/test_requestnames_TCV.m
@@ -1,9 +1,12 @@
 classdef test_requestnames_TCV < test_requestnames
   % everything is implemented in superclass!
   
+  properties
+        machine = 'TCV';
+  end
+  
   properties(TestParameter)
     % parameters that will vary during tests
-    machine = {'TCV'};
     shot  = {'48836'};
     request = get_all_gdat_requests('TCV');
   end
-- 
GitLab