datatest.gms : Driver for datalib tests of all sorts

Description


Category : GAMS Data Utilities library


Main file : datatest.gms   includes :  datatest.gms

$TITLE 'Driver for datalib tests of all sorts'

$eolcom //
$version 1

$set SLASH     \
$if %system.filesys% == UNIX $set SLASH /
$if not set PREFIX $set PREFIX %system.buildcode%

$if not set FAIL $set ALL all_data.gms
$if     set FAIL $set ALL all_data.tmp
$if not set FAIL $set FAIL failures_data.gms

$set GAMSlo %GAMS.lo%
$if %GAMS.ide% == 1 $set GAMSlo 2

$set FLAGS lo=%GAMSlo%
$if %DEMOSIZE% == 1 $set FLAGS --DEMOSIZE=1 %FLAGS%

$hidden When adding models we need to update this file at a few
$hidden spots:
$hidden   1. Add the model name (in order) to the set m
$hidden   2. Consider if the model should be in ignore(m), i.e. not
$hidden      run as part of datatest
$hidden   3. Consider if the model should be in winOnly(m), i.e. not
$hidden      run if we are not on Windows
set m   'model names in alphabetic order' /
A
B
C
CheckListbox               'Multiple ask popups for entering values through listboxes or checklistboxes'
CHP                        'Optimize combined heat and power generation in Excel, using vba API (opt) and GDXXRW'
CHP2                       'Optimize combined heat and power generation in Excel, using vba API (opt and gdx)'
Combobox                   'Multiple ask popups for entering values through comboboxes'
CompTimeWriteTrnsportGDX   'Writes data to GDX file during compile time'
connect01                  'Complex Connect Example with Spreadsheets'
connect02                  'Complex Connect Example with CSV Files'
connect03                  'Simple Connect Example with CSV files'
connect04                  'Simple Connect Example for SQL'
connect05                  'Simple Connect Example for Excel'
csv2gdx1                   'Test gdxdump and csv2gdx'
csv2gdx2                   'CSV2GDX Example 2 - Reading CSV Files with CSV2GDX'
csv2gdx3                   'CSV2GDX Example 3 - Reading Semicolon separated Data'
csv2gdx4                   'CSV2GDX Example 4 - Dealing with missing Labels and Duplicates'
csv2gdx5                   'CSV2GDX Example 5 - Reading more than one Parameter from a single Input File'
csv2gdx6                   'CSV2GDX Example 6 - Reading economic Data from the World Bank Data Catalog'
csv2gdx7                   'CSV2GDX Example 7 - Reading special Values with CSV2GDX'
csv2gdx8                   'CSV2GDX Example 8 - Reading an compressed encrypted Input File'
csv2gdx9                   'CSV2GDX Example 9 - Reading Options from an external File'
csv2gdx10                  'CSV2GDX Example 10 - Reading Set Elements with explanatory Text'
D
dBASE                      'Reads a dBASE table from United Nations Statistics Division'
DBTimestamp1               'Retrieves Data from Database once each Day'
DBTimestamp2               'Retrieves Data from Database once each Day'
Distances1                 'MDB2GMS Example 1 - Reading a single valued Table'
Distances2                 'SQL2GMS Example 1 - Reading a single valued Table'
E
embeddedSort               'Sorting of numerical data using the embedded code facility'
embeddedSplit              'Splitting of labels using the embedded code facility'
Excel                      'Reads Data from Excel through ODBC'
ExecTimeReadTrnsportGDX    'Reads data from a GDX file during execution time'
F
Fileopenbox                'Ask popup for opening a file'
Filesavebox                'Ask popup for saving a file'
G
GDX2ACCESSExample1         'Dumping the Contents of trnsport.gdx'
GDX2ACCESSExample2         'Writing Explanatory Text to Database'
GDX2ACCESSExample3         'Dumping a large Table to Database'
GDX2ACCESSExample4         'Special Value Mapping'
GDX2ACCESSExample5         'Renaming Fields'
GDXCOPYExample19           'Copies a GDX file to a compressed format for version 6'
GDXDIFFExample16           'Compares two GDX files and writes the difference to a third GDX file'
GDXDUMPExample1            'GDXDUMP - Adding double Quotes to an user defined Header when writing to CSV'
GDXDUMPExample15           'Generates first a GDX file and then lists symbols in the GDX file'
GDXExecute_unloadExample4  'Writes data to GDX file during execution time'
GDXINExample1              'Illustrates use of demand data from an external source in compile phase'
GDXINExample2              'Illustrates use of demand and market data from an external source in compile phase'
GDXINExample3              'Lists all the symbols in Trnsport.gdx in the listing file in compile phase'
GDXMERGEExample17          'Merges a number of GDX files into one'
gdxmrw_ext01_init          'Extended use of GDXMRW'
gdxmrw_intro01_init        'Introduction to data transfer between Matlab and GAMS'
gdxmrw_intro02_init        'Introduction to calling GAMS from Matlab'
gdxmrw_irgdx01_init        'Reading data from a indexed GDX file with IRGDX'
gdxmrw_iwgdx01_init        'Writing data into a indexed GDX file with IWGDX'
gdxmrw_qp1                 'Portfolio Analysis with Matlab & GAMS'
gdxmrw_qp1_starter         'Portfolio Analysis with Matlab & GAMS (starter)'
gdxmrw_qp2                 'Portfolio Analysis with Matlab & GAMS'
gdxmrw_qp2_starter         'Portfolio Analysis with Matlab & GAMS (starter)'
gdxmrw_qp3                 'QP solver M-file using GAMS and GDXMRW'
gdxmrw_rgdx01_init         'Reading data from a GDX file into a structure with RGDX'
gdxmrw_tr1                 'Transport LP with non-indexed GDX data interface'
gdxmrw_tr2                 'Transport LP with indexed GDX data interface'
gdxmrw_tr3                 'LP with data from GDXMRW - canonical LP form'
gdxmrw_tr4                 'LP with sets and params from GDXMRW - no UELs'
gdxmrw_tr5                 'LP with sets and params from GDXMRW - nice UELs'
gdxmrw_wgdx01_init         'Writing structured data into a GDX file with WGDX'
GDXMRWPlotting01           'Packages GDXMRW data plotting examples'
GDXMRWShowJac1             'Visualize model Jacobian in Matlab'
GDXRANKExample18           'Sorts a parameter, creates a sorted version and verifies that the sort works correctly'
GDXViewerExample           'Illustrates conversion of GDX data into different formats'
GDXXRW_AUTOOPEN            'Tests that gdxxrw calls the auto_open macro facility'
GDXXRWExample10            'Reading Spreadsheet using the index Option'
GDXXRWExample11a           'Writing Sets and Parameter to Spreadsheet at Compile Time'
GDXXRWExample11b           'Writing Sets and Parameter to Spreadsheet at Execution Time'
GDXXRWExample12            'Writing to Spreadsheet using the merge and clear Option'
GDXXRWExample13            'Reads a Table from Spreadsheet, manipulates the Data and writes back to Spreadsheet'
GDXXRWExample14            'Reading Data from Spreadsheet and writing Data to Spreadsheet after Solve'
GDXXRWExample15            'Writing to Spreadsheet using a Filter'
GDXXRWExample16            'Writing to Spreadsheet adding Text and Hyperlinks'
GDXXRWExample5             'Reading Parameter from Spreadsheet'
GDXXRWExample6             'Reading Parameter from Spreadsheet with Duplication'
GDXXRWExample7             'Reading Multi-dimensional Parameter from Spreadsheet'
GDXXRWExample8             'Reading Special Values from Spreadsheet and writing to Spreadsheet'
GDXXRWExample9             'Reading Set Elements associated with Data or Text using the values Option'
GDXXRWExample17            'Reading several Scalars from Spreadsheet'
GDXXRWExample18            'Reading Sets from Spreadsheet'
GDXXRWExample19            'Writing Parameter to Spreadsheet including Zero Values'
GDXXRWExample20            'Reading empty Cells with colMerge and reading merged Excel Ranges with cMerge'
GDXXRWExample21            'Skipping empty Rows or Columns and Ignoring Rows or Columns'
GMSPythonCheck             'Consistency and vulnerability check for GMSPython'
GMSPythonLib               'GMSPYTHONLIB compatibility check'
gtmvn                      'Demonstrate the use of numpy.multivariate_normal on stock return data using Transfer'
H
I
IndexMapping1              'MDB2GMS Example 6 - Index Mapping done in GAMS'
IndexMapping2              'MDB2GMS Example 6 - Index mapping done in Database'
IndexMapping3              'SQL2GMS Example 6 - Index Mapping done in GAMS'
IndexMapping4              'SQL2GMS Example 6 - Index mapping done in Database'
invert1                    'Matrix inversion via R'
invert2                    'Matrix inversion via Matlab'
J
K
L
LeastSquares               'Demonstrate the use of numpy.linalg.lstsq on the Filip test problem using Embedded Code Python'
Loadpoint                  'Illustrates use of "execute_loadpoint" command'
M
MDB2GDX1                   'Creates a GDX File using MDB2GMS at execution Time and displays it in GDXVIEWER'
MDB2GDX2                   'Creates a GDX File using MDB2GMS at compile Time'
MDB2GMS                    'Runs MDB2GMS interactively'
mdbReadingSets             'MDB2GMS Example 3,4,5 - Reading Sets from Database using MDB2GMS'
MDBSr5                     'Sequence of GAMS Models using the save/restart Facility'
moo01                      'Solve scalable multi-objective knapsack model'
moo02                      'Solve multi-objective power generation model'
MultipleAsk                'Multiple ask popups for entering various data types'
N
O
P
pickstock                  'Stock selection problem with MIRO'
PopulateV                  'Creates MS Access database'
Portfolio                  'Determines an efficient frontier in Excel, using the GDX DLL (vba API) and the GAMS executable'
Q
R
RadioButton                'Multiple ask popups for entering values through radio buttons'
rank01                     'Rank a vector, and display the data in sorted order'
rank02                     'Generate percentiles for a random vector'
rank03                     'Use libinclude rank to report multisectoral Monte Carlo results'
rank04                     'Repeated computation of percentiles within a loop'
rank05                     'Percentile ranking of household expenditure data with heterogenous household size'
readdata                   'Read data from .inc, .xlsx, .accdb and .csv file'
ReadingSets                'SQL2GMS Example 3,4,5 - Reading Sets from Database using SQL2GMS'
ReadMultiDimPar            'Reads a multidimensional parameter'
ReadMultiRange             'Reads a multi-area range and does post processing to eliminate invalid entries'
ReadSet                    'Reads set data'
ReadTrnsportData1          'Reads set data and the table of the transportation model in several calls'
ReadTrnsportData2          'Reads set data and the table of the transportation model in one call'
S
SalesProfitDB1             'MDB2GMS Example 2 - Reading a multi valued Table using separate Queries and Parameters'
SalesProfitDB2c            'MDB2GMS Example 2 - Reading a multi valued Table using a Parameter with an extra Index Position'
SalesProfitDB2m            'MDB2GMS Example 2 - Reading a multi valued Table (mute Version)'
SalesProfitDB3             'MDB2GMS Example 7 - Multi-Query Batch Example (Output: Several include Files)'
SalesProfitDB4             'MDB2GMS Example 7 - Multi-Query Batch Example (Output: A single GDX File)'
SalesProfitDB5             'SQL2GMS Example 2 - Reading a multi valued Table'
SalesProfitDB6             'SQL2GMS Example 7 - Multi-Query Batch Example (Output: Several include Files)'
SalesProfitDB7             'SQL2GMS Example 7 - Multi-Query Batch Example (Output: A single GDX File)'
Samurai                    'Solve a Samurai Sudoku in Excel, using the GDX DLL (vba API) and the GAMS executable'
Savepoint                  'Saves solution to a log or GDX file'
SingleAsk                  'Single ask popup for entering an integer value'
SpawnGAMSAccess            'Spawn GAMS from Access'
SpawnGAMSExcel             'Spawn an arbitrary GAMS model from Excel'
SQL2GDX1                   'Creates a GDX File using SQL2GMS at execution Time and displays it in GDXVIEWER'
SQL2GDX2                   'Creates a GDX File using SQL2GMS at compile Time'
SQL2GMS                    'Runs SQL2GMS interactively'
SQLServer                  'Test timeouts against SQL Server'
SQLSr5                     'Sequence of GAMS Models using the save/restart Facility'
Sudoku                     'Solve a Sudoku in Excel, using the GDX DLL (vba API) and the GAMS executable'
T
Text                       'Reads Table from a Text File using the ODBC Text Driver'
tompivot                   'Little GAMS Program from Tom Rutherford that Illustrates Report Generation with Excel'
transxls                   'Solve classical transportation problem in Excel, using vba API (opt and gdx)'
transport                  'Classical transportation problem with MIRO'
triobal                    'Tommasino-Rao Input Output Balance Software'
TrnsxcllStarter            'Trnsxcll: Excel Spreadsheet in Charge of GAMS'
tsvngdx                    'Integrate gdxdiff with TortoiseSVN'
U
V
W
Wiring                     'Use of wiring Option to read multi-data Column Tables'
X
Y
Z
     /

letters(m) / a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z /

$if not set TEST $goto alltest
SET runtests(m) / %TEST% /;
$if errorfree $goto TEST_OK
$clearerror
$log The test model(s) specified (--TEST=%TEST%) are not all valid
$abort

$label alltest
SET runtests(m);
runtests(m)$(not letters(m)) = yes;
$label TEST_OK

Set ignore(m)  /
  CheckListbox     'model shows only the use of listbox and checklistbox'
  CHP              'model opens interactive spreadsheet in excel'
  CHP2             'model opens interactive spreadsheet in excel'
  Combobox         'model shows only the use of combobox'
  Fileopenbox      'model shows only the use of fileopenbox'
  Filesavebox      'model shows only the use of filesavebox'
  GDXViewerExample 'model shows only the use of the GDX viewer'
  gdxmrw_ext01_init     'example requires Matlab'
  gdxmrw_intro01_init   'example requires Matlab'
  gdxmrw_intro02_init   'example requires Matlab'
  gdxmrw_irgdx01_init   'example requires Matlab'
  gdxmrw_iwgdx01_init   'example requires Matlab'
  gdxmrw_qp1            'example requires Matlab'
  gdxmrw_qp1_starter    'example requires Matlab'
  gdxmrw_qp2            'example requires Matlab'
  gdxmrw_qp2_starter    'example requires Matlab'
  gdxmrw_qp3            'example requires Matlab'
  gdxmrw_rgdx01_init    'example requires Matlab'
  gdxmrw_tr1            'example requires Matlab'
  gdxmrw_tr2            'example requires Matlab'
  gdxmrw_tr3            'example requires Matlab'
  gdxmrw_tr4            'example requires Matlab'
  gdxmrw_tr5            'example requires Matlab'
  gdxmrw_wgdx01_init    'example requires Matlab'
  GDXMRWPlotting01 'model just a placeholder for GDXMRW examples, requires Matlab'
  GDXMRWShowJac1   'model requires Matlab'
  invert1          'example requires R'
  invert2          'example requires Matlab'
  MDB2GDX1         'model has a gdx viewer call'
  MDB2GMS          'model has an ask call'
  MultipleAsk      'model has several ask calls'
  PopulateV        'model has an Access call'
  Portfolio        'model opens interactive spreadsheet'
  RadioButton      'model has two ask calls'
  SalesProfitDB4   'model has a gdx viewer call'
  SalesProfitDB7   'model has a gdx viewer call'
  Samurai          'model opens interactive spreadsheet'
  SingleAsk        'model has an ask call'
  SpawnGAMSAccess  'model opens interactive spreadsheet'
  SpawnGAMSExcel   'model opens interactive spreadsheet'
  SQL2GDX1         'model has a gdx viewer call'
  SQL2GMS          'model has an ask call'
  SQLServer        'model has an SQL server call'
  Sudoku           'model opens interactive spreadsheet'
  transxls         'model opens interactive spreadsheet'
  triobal          'model opens interactive spreadsheet'
  tsvngdx          'model needs two gdx files as input and uses WinMerge'
  TrnsxcllStarter  'model opens interactive spreadsheet'

$ifThen %sysenv.GHOST% == KumaNew
  dBASE            'sql2gms does not find "provider"'
  DBTimestamp2     'sql2gms does not find "provider"'
  Distances2       'sql2gms does not find "provider"'
  Excel            'sql2gms does not find "provider"'
  IndexMapping3    'sql2gms does not find "provider"'
  IndexMapping4     sql2gms does not find "provider"'
  ReadingSets      'sql2gms does not find "provider"'
  SalesProfitDB5   'sql2gms does not find "provider"'
  SalesProfitDB6   'sql2gms does not find "provider"'
  SQLSr5           'sql2gms does not find "provider"'
  Text             'sql2gms does not find "provider"'
  SQL2GDX2         'sql2gms does not find "provider", popup without test failing'
$endIf
  /;

Set WinOnly(m)  /
  SingleAsk,    MultipleAsk,
  RadioButton,  CheckListbox,   Combobox,       Fileopenbox,    Filesavebox,
  GDXXRW_AUTOOPEN
  GDXXRWExample5  *GDXXRWExample10,
  GDXXRWExample11a,GDXXRWExample11b,
  GDXXRWExample12 *GDXXRWExample21,
  GDX2ACCESSExample1*GDX2ACCESSExample5,
  Distances1,   Distances2,
  SalesProfitDB1,SalesProfitDB2c,SalesProfitDB2m,SalesProfitDB3*SalesProfitDB7,
  DBTimestamp1, DBTimestamp2,
  IndexMapping1*IndexMapping4,
  MDB2GMS,      MDBSr5,         MDB2GDX1,       MDB2GDX2,
  Wiring,       PopulateV,
  SQL2GMS,      SQLSr5,         SQL2GDX1,       SQL2GDX2,       SQLServer,
  Excel,        Text,           dBASE,          ReadSet,        readdata
  ReadTrnsportData1,ReadTrnsportData2,ReadMultiDimPar,ReadMultiRange,
  GDXViewerExample,
  Sudoku,       Samurai,        CHP,            CHP2,
  Portfolio,    transxls,       tsvngdx,        tompivot,       TrnsxcllStarter
  ReadingSets,  mdbReadingSets
  /;

$onempty
set mdlstdoutskip(m) 'skips for stdout check' /
  GDXDUMPExample15   'demonstrates simple use of gdxdump, writes to stdout'
/;
set mdlstderrskip(m) 'skips for stderr check' /
/;
$offempty

$if %system.filesys% == UNIX ignore(WinOnly) = yes;

scalar
  rc     / 0 /
  tot    / 0 /,
  err    / 0 /,
  stderr / 0 /,
  stdout / 0 /,
  cnt    / 0 /;

file oneTest  / 'onetest.gms' /         //Getting test from testlib and executing test
     stdTest  / 'stdtest.gms' /         //Checking if stderr and stdout are empty
     allTests / '%ALL%'  /
     ferr / '%FAIL%' /
     rmme / 'rmme.gms'  /
     log  / ''          /
     fx;

$if %ALL% == all_data.gms putclose allTests '* These are the tests we ran' /;
$if %FAIL% == failures_data.gms putclose ferr '* These are the tests that failed' /;

putclose rmme '* Delete all directories of tests without problems' /;
allTests.ap = 1;
ferr.ap = 1;
rmme.ap = 1;

$if not set DIRNAME $set DIRNAME "'%PREFIX%_data_' m.tl:0 "

loop(runtests(m)$(not ignore(m)),
  cnt = cnt + 1;
  tot = tot + 1;
  put_utility fx 'shell' / 'rm -rf ' %DIRNAME%;
  put_utility fx 'shell' / 'mkdir ' %DIRNAME%;
  put oneTest
     '$call datalib -q ' m.tl:0
   / '$if errorlevel 1 $abort'
   / '$call =gams ' m.tl:0 ' %FLAGS%';
  putclose oneTest
   / '$if errorlevel 1 $set err 1'
   / '$if set err scalar err /%err%/'
   / "$if %err% == 1 $abort 'Problem'";
  put_utility fx 'log' / 'Calling ' m.tl:0;
  put_utility fx 'shell' / 'mv -f onetest.gms ' %DIRNAME% ' && cd ' %DIRNAME% ' && gams onetest lo=%GAMS.lo% --err=0 gdx=..%SLASH%err > stdout.txt 2>stderr.txt'; rc=1; execute_load 'err' rc=err;
  putclose stdTest                                                                                          //Checking if stderr and stdout are empty
     '$call =test -s ' %DIRNAME% '%SLASH%stderr.txt'
   / '$if errorlevel 1 $set stderr 0'
   / '$if set stderr scalar stderr /%stderr%/'
   / '$call =test -s ' %DIRNAME% '%SLASH%stdout.txt'
   / '$if errorlevel 1 $set stdout 0'
   / '$if set stdout scalar stdout /%stdout%/'
  execute 'gams stdtest.gms lo=2 --stderr=1 --stdout=1 gdx=std'; stderr=1; stdout=1; execute_load 'std' stderr,stdout;
  put allTests;
  put '$call =gams datatest %FLAGS% --fail=failures_data.tmp --test=' m.tl:0 ' ';
  if {rc,     put '--ftrace=1 '};
  if {stderr and not mdlstderrskip(m), put '--fstderr=1 '};
  if {stdout and not mdlstdoutskip(m), put '--fstdout=1 '};
  putclose allTests '--dir='%DIRNAME% /;
  if {(rc or (stderr and not mdlstderrskip(m)) or (stdout) and not mdlstdoutskip(m)),
    err = err + 1;
    put ferr;                                                                                         // failure_data.gms
    put '$call =gams datatest %FLAGS% --fail=failures_data.tmp --test=' m.tl:0 ' ';                   // --fail defines alternative failures file
    if {rc,     put '--ftrace=1 '};                                                                   // execution error
    if {stderr and not mdlstderrskip(m), put '--fstderr=1 '};                                      // writing to standard error
    if {stdout and not mdlstdoutskip(m), put '--fstdout=1 '};                                      // writing to standard output
    putclose ferr '--dir='%DIRNAME% /;                                                        // name of kept directory
  else
    putclose rmme '$call rm -rf ' %DIRNAME% /;
  };
  if(cnt=5,
    execute "=gams rmme lo=0";
    cnt = 0;
    execute "echo '* Delete all directories of tests without problems' > rmme.gms";
  );
);

execute "=gams rmme lo=0";

putclose oneTest '*Total tests: ', tot:0:0, '  Failed tests: ', err:0:0 ;
$if %FAIL% == failures_data.gms execute 'cat onetest.gms >> %FAIL%'

execute 'rm -f rmme.* err.gdx std.gdx onetest.gms stdtest.*';

put log;
if {(err > 0),
  put 'There were errors: ', err:0:0, ' out of ',
       tot:0:0, ' tests failed.' /;
  put 'See the file failures_data.gms to reproduce the failed runs'/;
  put 'You have some failures. See failures_data.gms for details.';
else
  put 'Congratulations!  All ', tot:0:0, ' tests passed.'/;
};

put 'See the file %ALL%.gms to reproduce all the runs'/;