csv2gdx7.gms : CSVRead - Checking the Error Messages for incorrect Parameter Input

Description

The behavior of CSVRead is tested when specifying incorrect parameter input.

Contributor Jan-Erik Justkowiak, May 2018


Small Model of Type : GAMS


Category : GAMS Test library


Main file : csv2gdx7.gms

$title CSVRead - Checking the Error Messages for incorrect Parameter Input (CSV2GDX7,SEQ=752)

$onText
The behavior of CSVRead is tested when specifying incorrect parameter input.

Contributor Jan-Erik Justkowiak, May 2018
$offText

$onEcho > data.csv
,a,b,c,d,e,f,g
I,1,2,3,4,5,6,7.2
$offEcho

* Check for duplicate options! (Note: The error message is triggered no matter
* whether the parameter specifications are inconsinstent or not!)
$log 1. Duplicate ID
$call gamstool csvread data.csv id=x index=1 useHeader=y values=2..lastCol id=x trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 1. Error expected: Duplicate option: ID!
$log

$log 2. Duplicate useHeader
$call gamstool csvread data.csv id=x index=1 useHeader=y values=2..lastCol useHeader=y trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 2. Error expected: Duplicate option: useHeader!
$log

$log 3. Duplicate values
$call gamstool csvread data.csv id=x index=1 useHeader=y values=2..lastCol values=1..lastCol trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 3. Error expected: Duplicate option: value(s)!
$log

$log 4. Duplicate value
$call gamstool csvread data.csv id=x index=1 useHeader=y values=2 values=2 trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 4. Error expected: Duplicate option: value!
$log

$log 5. Duplicate index
$call gamstool csvread data.csv id=x index=1 useHeader=y values=2..lastCol index=1 trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 5. Error expected: Duplicate option: index!
$log

***------------option `output` has been replaced by `gdxOut` now in gamstool csvread------------***
$log 6. Duplicate gdxOut
$call gamstool csvread data.csv gdxOut=temp.gdx id=x index=1 useHeader=y values=2..lastCol gdxOut=temp.gdx trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 6. Error expected: Duplicate option: gdxOut!
$log

***------------option `storeZero` has been deprecated now in gamstool csvread------------***
*$log 7. Duplicate storeZero
*$call gamstool csvread data.csv id=x index=1 useHeader=y storeZero=y values=2..lastCol storeZero=y trace=0 gdxout=data.gdx
*$ifE errorLevel=0 $abort CSVRead should have failed after running 7. Error expected: Duplicate option: storeZero!
*$log

$log 8. Duplicate valueDim
$call gamstool csvread data.csv id=x index=1 useHeader=y valueDim=y values=2 valueDim=y trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 8. Error expected: Duplicate option: valueDim!
$log

***------------option `colCount` has been deprecated now in gamstool csvread------------***
*$log 9. Duplicate colCount
*$call gamstool csvread data.csv id=x index=1 useHeader=y colCount=7 values=2..lastCol colCount=7 trace=0 gdxout=data.gdx
*$ifE errorLevel=0 $abort CSVRead should have failed after running 9. Error expected: Duplicate option: colCount!
*$log

$log 10. Duplicate checkDate
$call gamstool csvread data.csv id=x index=1 useHeader=y checkDate=y values=2..lastCol checkDate=y trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 10. Error expected: Duplicate option: checkDate!
$log

$log 11. Duplicate autoRow
$call gamstool csvread data.csv id=x index=1 useHeader=y autoRow=r values=2..lastCol autoRow=r trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 11. Error expected: Duplicate option: autoRow!
$log

$log 12. Duplicate autoCol
$call gamstool csvread data.csv id=x index=1 useHeader=y autoCol=c values=2..8 autoCol=c trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 12. Error expected: Duplicate option: autoCol!
$log

$log 13. Duplicate fieldSep
$call gamstool csvread data.csv id=x index=1 useHeader=y fieldSep=comma values=2..lastCol fieldSep=comma trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 13. Error expected: Duplicate option: fieldSep!
$log

$log 14. Duplicate decimalSep
$call gamstool csvread data.csv id=x index=1 useHeader=y decimalSep=period values=2..lastCol decimalSep=period trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 14. Error expected: Duplicate option: decimalSep!
$log

***------------option `password` has been deprecated now in gamstool csvread------------***
*$log 15. Duplicate password
*$call gamstool csvread data.csv id=x index=1 useHeader=y password=123 values=2..lastCol password=123 trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
*$ifE errorLevel=0 $abort CSVRead should have failed after running 15. Error expected: Duplicate option: password!
*$log
*-------------------------------------------------------------------------------


* We want to read the values of column 2 and 4-7 by using the value and values option
* This will fail
*$log 16. Value und values Option | The option `value` has been removed from the gamstool csvread
*$call gamstool csvread data.csv id=x index=1 useHeader=y value=2 values=4..7 trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
*$ifE errorLevel=0 $abort CSVRead should have failed after running 16. Error expected: Duplicate option: Value!
*$log

* Each column must be specified within the values option
* This will succeed
$log 17.
$call gamstool csvread data.csv id=x index=1 useHeader=y values=2,4..7 trace=0 gdxout=data.gdx
$ifE errorLevel<>0 $abort Error: CSVRead should have succeeded after running 17.!
$log
*-------------------------------------------------------------------------------


* Calculations with the lastCol constant are not allowed
$log 18. Calculations with the lastCol constant
$call gamstool csvread data.csv id=x index=1 useHeader=y values=lastCol-1 trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 18. Error expected: Column assignation as string can only include integers, comma (,), colon (:) and symbolic constant lastCol.
$log
*-------------------------------------------------------------------------------


* Checking the error messages if fieldSep, decimalSep, useHeader, storeZero,
* valueDim or checkDate is set to an unknown value
$log 19. Incorrect fieldSep
$call gamstool csvread data.csv id=x index=1 useHeader=y values=2..lastCol fieldSep=coma trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 19. Error expected: Wrong fieldSeparator input: coma
$log

$log 20. Incorrect decimalSep
$call gamstool csvread data.csv id=x index=1 useHeader=y values=2..lastCol decimalSep=coma trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 20. Error expected: Wrong decimalSeparator input: coma
$log

$log 21. Incorrect useHeader
$call gamstool csvread data.csv id=x index=1 useHeader=ye values=2..lastCol trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 21. Wrong flag, useheader: ye
$log

***------------option `storeZero` has been deprecated now in gamstool csvread------------***
*$log 22. Incorrect storeZero
*$call gamstool csvread data.csv id=x index=1 useHeader=y storeZero=ye values=2..lastCol trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
*$ifE errorLevel=0 $abort CSVRead should have failed after running 22. Wrong flag, useheader: ye
*$log

$log 23. Incorrect valueDim
$call gamstool csvread data.csv id=x index=1 useHeader=y valueDim=ye values=2..lastCol trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 23. Wrong flag, useheader: ye
$log

$log 24. Incorrect checkDate
$call gamstool csvread data.csv id=x index=1 useHeader=y checkDate=ye values=2..lastCol trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 24. Wrong flag, useheader: ye
$log
*-------------------------------------------------------------------------------

* Check the messages if the column in value(s) or index option does not exists
$log 25. Incorrect value input - Bad column number
$call gamstool csvread data.csv id=x index=1 useHeader=y values=0 trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 25. Error expected: Usecols do not match columns, columns expected but not found: [0, -1]
$log

$log 26. Incorrect values input - Bad column number
$call gamstool csvread data.csv id=x index=1 useHeader=y values=0,5,6 trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 26. Error expected: Usecols do not match columns, columns expected but not found: [0, 4, 5, -1]
$log

$log 27. Incorrect index input - Bad column number
$call gamstool csvread data.csv id=x index=0 useHeader=y trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 27. Error expected: Usecols do not match columns, columns expected but not found: [-1]
$log

$log 28. Incorrect value input - Exceeding column count
$call gamstool csvread data.csv id=x index=1 useHeader=y values=10 trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 28. Error expected: Usecols do not match columns, columns expected but not found: [0, 9]
$log

$log 29. Incorrect values input - Exceeding column count
$call gamstool csvread data.csv id=x index=1 useHeader=y values=5,6,10 trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 29. Error expected: Usecols do not match columns, columns expected but not found: [0, 9, 4, 5]
$log

$log 30. Incorrect index input - Exceeding column count
$call gamstool csvread data.csv id=x index=10 useHeader=y trace=0 gdxout=data.gdx > %system.NullFile% 2>&1
$ifE errorLevel=0 $abort CSVRead should have failed after running 30. Error expected: Usecols do not match columns, columns expected but not found: [9]
$log
*-------------------------------------------------------------------------------