Description
Test functionality of the GAMS embedded code facility for Python during execution time Contributor: Clemens Westphal, July 2017
Small Model of Type : GAMS
Category : GAMS Test library
Main file : embpy02.gms
$title 'Test for embedded code facility' (EMBPY02,SEQ=736)
$onText
Test functionality of the GAMS embedded code facility for Python during execution time
Contributor: Clemens Westphal, July 2017
$offText
$log --- Using Python library %sysEnv.GMSPYTHONLIB%
$onUNDF
Set i / i1 text for i1
i2 text for i2 /
iout(i)
j / j1*j3 /
ij(i,j) / #i.#j /
i_want(i) / i1, i2 /
i_want_ex(i) / i1 text 1, i2 text 2 /
ij_want(i,j) / i1.j1, i1.j2 /
ij_want_merge(i,j) / i1.j1, i1.j2, i1.j3 /
ij_want_ex(i,j) / i1.j1 text 1, i1.j2 text 2/
svIdx / myUNDF, myNA, myPINF, myMINF, myEPS /;
Scalar p0 /3.14/
p0_want / 3.14 /;
Parameter p1(i) / #i 3.14 /
p2(i,j) / #i.#j 3.14 /
p1_want(i) / #i 3.14 /
p2_want(i,j) / i1.j1 3.14, i1.j2 3.14 /
p2_want_merge(i,j) / i1.j1 3.14, i1.j2 3.14, i1.j3 3.14 /
sv_want(svIdx) / myUNDF UNDF, myNA NA, myPINF INF, myMINF -INF, myEPS EPS /
svX(svIdx)
svY(svIdx);
Variable v0 / fx 3.14 /
v1(i) / #i.fx 3.14 /
v2(i,j) / #i.#j.fx 3.14 /
v0_want / l 3.14, m 0, lo 0, up 10, scale 1 /
v1_want(i) / i1.(l 3.14, m 0, lo 0, up 10, scale 1),
i2.(l 3.14, m 0, lo 0, up 10, scale 1) /
v2_want(i,j) / i1.j1.(l 3.14, m 0, lo 0, up 10, scale 1),
i1.j2.(l 3.14, m 0, lo 0, up 10, scale 1) /
v2_want_merge(i,j) / i1.j1.(l 3.14, m 0, lo 0, up 10, scale 1),
i1.j2.(l 3.14, m 0, lo 0, up 10, scale 1),
i1.j3.(l 3.14, m 0, lo 0, up 10, scale 1) /;
equation e0 / fx 3.14 /
e1(i) / #i.fx 3.14 /
e2(i,j) / #i.#j.fx 3.14 /
e0_want / l 3.14, m 0, lo 0, up 10, scale 1 /
e1_want(i) / i1.(l 3.14, m 0, lo 0, up 10, scale 1),
i2.(l 3.14, m 0, lo 0, up 10, scale 1) /
e2_want(i,j) / i1.j1.(l 3.14, m 0, lo 0, up 10, scale 1),
i1.j2.(l 3.14, m 0, lo 0, up 10, scale 1) /
e2_want_merge(i,j) / i1.j1.(l 3.14, m 0, lo 0, up 10, scale 1),
i1.j2.(l 3.14, m 0, lo 0, up 10, scale 1),
i1.j3.(l 3.14, m 0, lo 0, up 10, scale 1) /;
$call rm -f embpy02_log.txt
$onEchoV > checkData
execute_unload 'have.gdx', %1;
execute 'gdxdiff wanted.gdx have.gdx >> embpy02_log.txt';
abort$errorlevel '%2';
$offEcho
*** Test that an empty code block works
embeddedCode Python:
endEmbeddedCode
*** Test that an code block with comments only works
embeddedCode Python:
#
endEmbeddedCode
embeddedCode Python:
#
#
endEmbeddedCode
embeddedCode Python:
#
#
endEmbeddedCode
*** Test default list behavior ***
*Test 1.1: Test default list behavior of scalars
embeddedCode Python:
p0 = list(gams.get('p0'))
assert p0 == [3.14], \
"Test 1.1 failed in Python"
endEmbeddedCode
*Test 1.2: Test default list behavior of one dimensional parameters
embeddedCode Python:
p1 = list(gams.get('p1'))
assert p1 == [('i1', 3.14), ('i2', 3.14)], \
"Test 1.2 failed in Python"
endEmbeddedCode
*Test 1.3: Test default list behavior of multi dimensional parameters
embeddedCode Python:
p2 = list(gams.get('p2'))
assert p2 == [(('i1', 'j1'), 3.14), \
(('i1', 'j2'), 3.14), \
(('i1', 'j3'), 3.14), \
(('i2', 'j1'), 3.14), \
(('i2', 'j2'), 3.14), \
(('i2', 'j3'), 3.14)], \
"Test 1.3 failed in Python"
endEmbeddedCode
*Test 1.4: Test default list behavior of one dimensional sets
embeddedCode Python:
i = list(gams.get('i'))
assert i == ['i1', 'i2'], \
"Test 1.4 failed in Python"
endEmbeddedCode
*Test 1.5: Test default list behavior of multi dimensional sets
embeddedCode Python:
ij = list(gams.get('ij'))
assert ij == [('i1', 'j1'), ('i1', 'j2'), \
('i1', 'j3'), ('i2', 'j1'), \
('i2', 'j2'), ('i2', 'j3')], \
"Test 1.5 failed in Python"
endEmbeddedCode
*Test 1.6: Test default list behavior of scalar variables
embeddedCode Python:
v0 = list(gams.get('v0'))
assert v0 == [(3.14, 0, 3.14, 3.14, 1)], \
"Test 1.6 failed in Python"
endEmbeddedCode
*Test 1.7: Test default list behavior of one dimensional variables
embeddedCode Python:
v1 = list(gams.get('v1'))
assert v1 == [('i1', (3.14, 0, 3.14, 3.14, 1)), \
('i2', (3.14, 0, 3.14, 3.14, 1))], \
"Test 1.7 failed in Python"
endEmbeddedCode
*Test 1.8: Test default list behavior of multi dimensional variables
embeddedCode Python:
v2 = list(gams.get('v2'))
assert v2 == [(('i1', 'j1'), (3.14, 0, 3.14, 3.14, 1)), \
(('i1', 'j2'), (3.14, 0, 3.14, 3.14, 1)), \
(('i1', 'j3'), (3.14, 0, 3.14, 3.14, 1)), \
(('i2', 'j1'), (3.14, 0, 3.14, 3.14, 1)), \
(('i2', 'j2'), (3.14, 0, 3.14, 3.14, 1)), \
(('i2', 'j3'), (3.14, 0, 3.14, 3.14, 1))], \
"Test 1.8 failed in Python"
endEmbeddedCode
*Test 1.9: Test default list behavior of scalar equations
embeddedCode Python:
e0 = list(gams.get('e0'))
assert e0 == [(3.14, 0, 3.14, 3.14, 1)], \
"Test 1.9 failed in Python"
endEmbeddedCode
*Test 1.10: Test default list behavior of one dimensional equations
embeddedCode Python:
e1 = list(gams.get('e1'))
assert e1 == [('i1', (3.14, 0, 3.14, 3.14, 1)), \
('i2', (3.14, 0, 3.14, 3.14, 1))], \
"Test 1.10 failed in Python"
endEmbeddedCode
*Test 1.11: Test default list behavior of multi dimensional equations
embeddedCode Python:
e2 = list(gams.get('e2'))
assert e2 == [(('i1', 'j1'), (3.14, 0, 3.14, 3.14, 1)), \
(('i1', 'j2'), (3.14, 0, 3.14, 3.14, 1)), \
(('i1', 'j3'), (3.14, 0, 3.14, 3.14, 1)), \
(('i2', 'j1'), (3.14, 0, 3.14, 3.14, 1)), \
(('i2', 'j2'), (3.14, 0, 3.14, 3.14, 1)), \
(('i2', 'j3'), (3.14, 0, 3.14, 3.14, 1)) ], \
"Test 1.11 failed in Python"
endEmbeddedCode
*** Test different aspects of list behavior ***
*Test 2.1: Test list behavior of explanatory text
embeddedCode Python:
i = list(gams.get('i', valueFormat=ValueFormat.FLAT))
assert i == [('i1', 'text for i1'), ('i2', 'text for i2')], \
"Test 2.1a failed in Python"
endEmbeddedCode
*Test 2.1: Test list behavior of explanatory text
embeddedCode Python:
i = list(gams.get('i', valueFormat=ValueFormat.TUPLE))
assert i == [('i1', ('text for i1',)), ('i2', ('text for i2',))], \
"Test 2.1b failed in Python"
endEmbeddedCode
*** Test default list behavior using label indexes instead of strings ***
*Test 3.1: Test list behavior of scalars using label indexes
embeddedCode Python:
p0 = list(gams.get('p0', KeyType.INT))
assert p0 == [3.14], \
"Test 3.1 failed in Python"
endEmbeddedCode
*Test 3.2: Test list behavior of one dimensional parameters using label indexes
embeddedCode Python:
p1 = list(gams.get('p1', KeyType.INT))
assert p1 == [(1, 3.14), (2, 3.14)], \
"Test 3.2 failed in Python"
endEmbeddedCode
*Test 3.3: Test list behavior of multi dimensional parameters using label indexes
embeddedCode Python:
p2 = list(gams.get('p2', KeyType.INT))
assert p2 == [((1, 3), 3.14), \
((1, 4), 3.14), \
((1, 5), 3.14), \
((2, 3), 3.14), \
((2, 4), 3.14), \
((2, 5), 3.14)], \
"Test 3.3 failed in Python"
endEmbeddedCode
*Test 3.4: Test list behavior of one dimensional sets using label indexes
embeddedCode Python:
i = list(gams.get('i', KeyType.INT))
assert i == [1, 2], \
"Test 3.4 failed in Python"
endEmbeddedCode
*Test 3.5: Test list behavior of multi dimensional sets using label indexes
embeddedCode Python:
ij = list(gams.get('ij', KeyType.INT))
assert ij == [(1, 3), (1, 4), \
(1, 5), (2, 3), \
(2, 4), (2, 5)], \
"Test 3.5 failed in Python"
endEmbeddedCode
*Test 3.6: Test list behavior of scalar variables using label indexes
embeddedCode Python:
v0 = list(gams.get('v0', KeyType.INT))
assert v0 == [(3.14, 0, 3.14, 3.14, 1)], \
"Test 3.6 failed in Python"
endEmbeddedCode
*Test 3.7: Test list behavior of one dimensional variables using label indexes
embeddedCode Python:
v1 = list(gams.get('v1', KeyType.INT))
assert v1 == [(1, (3.14, 0, 3.14, 3.14, 1)), \
(2, (3.14, 0, 3.14, 3.14, 1))], \
"Test 3.7 failed in Python"
endEmbeddedCode
*Test 3.8: Test list behavior of multi dimensional variables using label indexes
embeddedCode Python:
v2 = list(gams.get('v2', KeyType.INT))
assert v2 == [((1, 3), (3.14, 0, 3.14, 3.14, 1)), \
((1, 4), (3.14, 0, 3.14, 3.14, 1)), \
((1, 5), (3.14, 0, 3.14, 3.14, 1)), \
((2, 3), (3.14, 0, 3.14, 3.14, 1)), \
((2, 4), (3.14, 0, 3.14, 3.14, 1)), \
((2, 5), (3.14, 0, 3.14, 3.14, 1))], \
"Test 3.8 failed in Python"
endEmbeddedCode
*Test 3.9: Test list behavior of scalar equations using label indexes
embeddedCode Python:
e0 = list(gams.get('e0', KeyType.INT))
assert e0 == [(3.14, 0, 3.14, 3.14, 1)], \
"Test 3.9 failed in Python"
endEmbeddedCode
*Test 3.10: Test list behavior of one dimensional equations using label indexes
embeddedCode Python:
e1 = list(gams.get('e1', KeyType.INT))
assert e1 == [(1, (3.14, 0, 3.14, 3.14, 1)), \
(2, (3.14, 0, 3.14, 3.14, 1))], \
"Test 3.10 failed in Python"
endEmbeddedCode
*Test 3.11: Test list behavior of multi dimensional equations using label indexes
embeddedCode Python:
e2 = list(gams.get('e2', KeyType.INT))
assert e2 == [((1, 3), (3.14, 0, 3.14, 3.14, 1)), \
((1, 4), (3.14, 0, 3.14, 3.14, 1)), \
((1, 5), (3.14, 0, 3.14, 3.14, 1)), \
((2, 3), (3.14, 0, 3.14, 3.14, 1)), \
((2, 4), (3.14, 0, 3.14, 3.14, 1)), \
((2, 5), (3.14, 0, 3.14, 3.14, 1)) ], \
"Test 3.11 failed in Python"
endEmbeddedCode
*** Test writing symbol data using labels ***
*Test 4.1: Test writing of scalars
execute_unload 'wanted.gdx', p0_want=p0;
option clear=p0;
embeddedCode Python:
data = [3.14]
gams.set('p0', data)
endEmbeddedCode p0
$batInclude checkData p0 'Test 4.1a failed in GAMS'
option clear=p0;
embeddedCode Python:
data = [(3.14,)]
gams.set('p0', data)
endEmbeddedCode p0
$batInclude checkData p0 'Test 4.1b failed in GAMS'
*Test 4.2: Test writing of one dimensional parameters
execute_unload 'wanted.gdx', p1_want=p1;
option clear=p1;
embeddedCode Python:
data = [("i1", 3.14), ("i2", 3.14)]
gams.set('p1', data)
endEmbeddedCode p1
$batInclude checkData p1 'Test 4.2a failed in GAMS'
option clear=p1;
embeddedCode Python:
data = [(("i1",), 3.14), (("i2",), 3.14)]
gams.set('p1', data)
endEmbeddedCode p1
$batInclude checkData p1 'Test 4.2b failed in GAMS'
option clear=p1;
embeddedCode Python:
data = [("i1", (3.14,)), ("i2", (3.14,))]
gams.set('p1', data)
endEmbeddedCode p1
$batInclude checkData p1 'Test 4.2c failed in GAMS'
option clear=p1;
embeddedCode Python:
data = [(("i1",), (3.14,)), (("i2",), (3.14,))]
gams.set('p1', data)
endEmbeddedCode p1
$batInclude checkData p1 'Test 4.2d failed in GAMS'
*Test 4.3: Test writing of multi dimensional parameters
execute_unload 'wanted.gdx', p2_want=p2;
option clear=p2;
embeddedCode Python:
data = [('i1', 'j1', 3.14), ('i1', 'j2', 3.14)]
gams.set('p2', data)
endEmbeddedCode p2
$batInclude checkData p2 'Test 4.3a failed in GAMS'
option clear=p2;
embeddedCode Python:
data = [(('i1', 'j1'), 3.14), (('i1', 'j2'), 3.14)]
gams.set('p2', data)
endEmbeddedCode p2
$batInclude checkData p2 'Test 4.3b failed in GAMS'
option clear=p2;
embeddedCode Python:
data = [('i1', 'j1', (3.14,)), ('i1', 'j2', (3.14,))]
gams.set('p2', data)
endEmbeddedCode p2
$batInclude checkData p2 'Test 4.3c failed in GAMS'
option clear=p2;
embeddedCode Python:
data = [(('i1', 'j1'), (3.14,)), (('i1', 'j2'), (3.14,))]
gams.set('p2', data)
endEmbeddedCode p2
$batInclude checkData p2 'Test 4.3d failed in GAMS'
*Test 4.4: Test writing of one dimensional sets
execute_unload 'wanted.gdx', i_want=iout;
option clear=iout;
embeddedCode Python:
data = ['i1', 'i2']
gams.set('iout', data)
endEmbeddedCode iout
$batInclude checkData iout 'Test 4.4a failed in GAMS'
option clear=iout;
embeddedCode Python:
data = [('i1',), ('i2',)]
gams.set('iout', data)
endEmbeddedCode iout
$batInclude checkData iout 'Test 4.4b failed in GAMS'
execute_unload 'wanted.gdx', i_want_ex=iout;
option clear=iout;
embeddedCode Python:
data = [('i1', "text 1"), ('i2', "text 2")]
gams.set('iout', data)
endEmbeddedCode iout
$batInclude checkData iout 'Test 4.4c failed in GAMS'
option clear=iout;
embeddedCode Python:
data = [(('i1',), "text 1"), (('i2',), "text 2")]
gams.set('iout', data)
endEmbeddedCode iout
$batInclude checkData iout 'Test 4.4d failed in GAMS'
option clear=iout;
embeddedCode Python:
data = [('i1', ("text 1",)), ('i2', ("text 2",))]
gams.set('iout', data)
endEmbeddedCode iout
$batInclude checkData iout 'Test 4.4e failed in GAMS'
option clear=iout;
embeddedCode Python:
data = [(('i1',), ("text 1",)), (('i2',), ("text 2",))]
gams.set('iout', data)
endEmbeddedCode iout
$batInclude checkData iout 'Test 4.4f failed in GAMS'
*Test 4.5: Test writing of multi dimensional sets
execute_unload 'wanted.gdx', ij_want=ij;
option clear=ij;
embeddedCode Python:
data = [('i1', 'j1'), ('i1', 'j2')]
gams.set('ij', data)
endEmbeddedCode ij
$batInclude checkData ij 'Test 4.5a failed in GAMS'
option clear=ij;
embeddedCode Python:
data = [(('i1', 'j1'),), (('i1', 'j2'),)]
gams.set('ij', data)
endEmbeddedCode ij
$batInclude checkData ij 'Test 4.5b failed in GAMS'
execute_unload 'wanted.gdx', ij_want_ex=ij;
option clear=ij;
embeddedCode Python:
data = [('i1', 'j1', 'text 1'), ('i1', 'j2', 'text 2')]
gams.set('ij', data)
endEmbeddedCode ij
$batInclude checkData ij 'Test 4.5c failed in GAMS'
option clear=ij;
embeddedCode Python:
data = [(('i1', 'j1'), 'text 1'), (('i1', 'j2'), 'text 2')]
gams.set('ij', data)
endEmbeddedCode ij
$batInclude checkData ij 'Test 4.5d failed in GAMS'
option clear=ij;
embeddedCode Python:
data = [('i1', 'j1', ('text 1',)), ('i1', 'j2', ('text 2',))]
gams.set('ij', data)
endEmbeddedCode ij
$batInclude checkData ij 'Test 4.5e failed in GAMS'
option clear=ij;
embeddedCode Python:
data = [(('i1', 'j1'), ('text 1',)), (('i1', 'j2'), ('text 2',))]
gams.set('ij', data)
endEmbeddedCode ij
$batInclude checkData ij 'Test 4.5f failed in GAMS'
*Test 4.6: Test writing of scalar variable
execute_unload 'wanted.gdx', v0_want=v0;
option clear=v0;
embeddedCode Python:
data = [(3.14, 0, 0, 10, 1)]
gams.set('v0', data)
endEmbeddedCode v0
$batInclude checkData v0 'Test 4.6a failed in GAMS'
*Test 4.7: Test writing of one dimensonal variables
execute_unload 'wanted.gdx', v1_want=v1;
option clear=v1;
embeddedCode Python:
data = [("i1", 3.14, 0, 0, 10, 1), ("i2", 3.14, 0, 0, 10, 1)]
gams.set('v1', data)
endEmbeddedCode v1
$batInclude checkData v1 'Test 4.7a failed in GAMS'
option clear=v1;
embeddedCode Python:
data = [(("i1",), 3.14, 0, 0, 10, 1), (("i2",), 3.14, 0, 0, 10, 1)]
gams.set('v1', data)
endEmbeddedCode v1
$batInclude checkData v1 'Test 4.7b failed in GAMS'
option clear=v1;
embeddedCode Python:
data = [("i1", (3.14, 0, 0, 10, 1)), ("i2", (3.14, 0, 0, 10, 1))]
gams.set('v1', data)
endEmbeddedCode v1
$batInclude checkData v1 'Test 4.7c failed in GAMS'
option clear=v1;
embeddedCode Python:
data = [(("i1",), (3.14, 0, 0, 10, 1)), (("i2",), (3.14, 0, 0, 10, 1))]
gams.set('v1', data)
endEmbeddedCode v1
$batInclude checkData v1 'Test 4.7d failed in GAMS'
*Test 4.8: Test writing of multi dimensonal variables
execute_unload 'wanted.gdx', v2_want=v2;
option clear=v2;
embeddedCode Python:
data = [("i1", "j1", 3.14, 0, 0, 10, 1), ("i1", "j2", 3.14, 0, 0, 10, 1)]
gams.set('v2', data)
endEmbeddedCode v2
$batInclude checkData v2 'Test 4.8a failed in GAMS'
option clear=v2;
embeddedCode Python:
data = [(("i1", "j1"), 3.14, 0, 0, 10, 1), (("i1", "j2"), 3.14, 0, 0, 10, 1)]
gams.set('v2', data)
endEmbeddedCode v2
$batInclude checkData v2 'Test 4.8b failed in GAMS'
option clear=v2;
embeddedCode Python:
data = [("i1", "j1", (3.14, 0, 0, 10, 1)), ("i1", "j2", (3.14, 0, 0, 10, 1))]
gams.set('v2', data)
endEmbeddedCode v2
$batInclude checkData v2 'Test 4.8c failed in GAMS'
option clear=v2;
embeddedCode Python:
data = [(("i1", "j1"), (3.14, 0, 0, 10, 1)), (("i1", "j2"), (3.14, 0, 0, 10, 1))]
gams.set('v2', data)
endEmbeddedCode v2
$batInclude checkData v2 'Test 4.8d failed in GAMS'
*Test 4.9: Test writing of scalar equations
execute_unload 'wanted.gdx', e0_want=e0;
option clear=e0;
embeddedCode Python:
data = [(3.14, 0, 0, 10, 1)]
gams.set('e0', data)
endEmbeddedCode e0
$batInclude checkData e0 'Test 4.9 failed in GAMS'
*Test 4.10: Test writing of one dimensonal equations
execute_unload 'wanted.gdx', e1_want=e1;
option clear=e1;
embeddedCode Python:
data = [("i1", 3.14, 0, 0, 10, 1), ("i2", 3.14, 0, 0, 10, 1)]
gams.set('e1', data)
endEmbeddedCode e1
$batInclude checkData e1 'Test 4.10a failed in GAMS'
option clear=e1;
embeddedCode Python:
data = [(("i1",), 3.14, 0, 0, 10, 1), (("i2",), 3.14, 0, 0, 10, 1)]
gams.set('e1', data)
endEmbeddedCode e1
$batInclude checkData e1 'Test 4.10b failed in GAMS'
option clear=e1;
embeddedCode Python:
data = [("i1", (3.14, 0, 0, 10, 1)), ("i2", (3.14, 0, 0, 10, 1))]
gams.set('e1', data)
endEmbeddedCode e1
$batInclude checkData e1 'Test 4.10c failed in GAMS'
option clear=e1;
embeddedCode Python:
data = [(("i1",), (3.14, 0, 0, 10, 1)), (("i2",), (3.14, 0, 0, 10, 1))]
gams.set('e1', data)
endEmbeddedCode e1
$batInclude checkData e1 'Test 4.10d failed in GAMS'
*Test 4.11: Test writing of multi dimensonal equations
execute_unload 'wanted.gdx', e2_want=e2;
option clear=e2;
embeddedCode Python:
data = [("i1", "j1", 3.14, 0, 0, 10, 1), ("i1", "j2", 3.14, 0, 0, 10, 1)]
gams.set('e2', data)
endEmbeddedCode e2
$batInclude checkData e2 'Test 4.11a failed in GAMS'
option clear=e2;
embeddedCode Python:
data = [(("i1", "j1"), 3.14, 0, 0, 10, 1), (("i1", "j2"), 3.14, 0, 0, 10, 1)]
gams.set('e2', data)
endEmbeddedCode e2
$batInclude checkData e2 'Test 4.11b failed in GAMS'
option clear=e2;
embeddedCode Python:
data = [("i1", "j1", (3.14, 0, 0, 10, 1)), ("i1", "j2", (3.14, 0, 0, 10, 1))]
gams.set('e2', data)
endEmbeddedCode e2
$batInclude checkData e2 'Test 4.11c failed in GAMS'
option clear=e2;
embeddedCode Python:
data = [(("i1", "j1"), (3.14, 0, 0, 10, 1)), (("i1", "j2"), (3.14, 0, 0, 10, 1))]
gams.set('e2', data)
endEmbeddedCode e2
$batInclude checkData e2 'Test 4.11d failed in GAMS'
*** Test writing symbol data using label indexes instead of strings ***
*Test 5.1: Test writing of scalars using label indexes
execute_unload 'wanted.gdx', p0_want=p0;
option clear=p0;
embeddedCode Python:
data = [3.14]
gams.set('p0', data)
endEmbeddedCode p0
$batInclude checkData p0 'Test 5.1a failed in GAMS'
option clear=p0;
embeddedCode Python:
data = [(3.14,)]
gams.set('p0', data)
endEmbeddedCode p0
$batInclude checkData p0 'Test 5.1b failed in GAMS'
*Test 5.2: Test writing of one dimensional parameters using label indexes
execute_unload 'wanted.gdx', p1_want=p1;
option clear=p1;
embeddedCode Python:
data = [(1, 3.14), (2, 3.14)]
gams.set('p1', data)
endEmbeddedCode p1
$batInclude checkData p1 'Test 5.2a failed in GAMS'
option clear=p1;
embeddedCode Python:
data = [((1,), 3.14), ((2,), 3.14)]
gams.set('p1', data)
endEmbeddedCode p1
$batInclude checkData p1 'Test 5.2b failed in GAMS'
option clear=p1;
embeddedCode Python:
data = [(1, (3.14,)), (2, (3.14,))]
gams.set('p1', data)
endEmbeddedCode p1
$batInclude checkData p1 'Test 5.2c failed in GAMS'
option clear=p1;
embeddedCode Python:
data = [((1,), (3.14,)), ((2,), (3.14,))]
gams.set('p1', data)
endEmbeddedCode p1
$batInclude checkData p1 'Test 5.2d failed in GAMS'
*Test 5.3: Test writing of multi dimensional parameters using label indexes
execute_unload 'wanted.gdx', p2_want=p2;
option clear=p2;
embeddedCode Python:
data = [(1, 3, 3.14), (1, 4, 3.14)]
gams.set('p2', data)
endEmbeddedCode p2
$batInclude checkData p2 'Test 5.3a failed in GAMS'
option clear=p2;
embeddedCode Python:
data = [((1, 3), 3.14), ((1, 4), 3.14)]
gams.set('p2', data)
endEmbeddedCode p2
$batInclude checkData p2 'Test 5.3b failed in GAMS'
option clear=p2;
embeddedCode Python:
data = [(1, 3, (3.14,)), (1, 4, (3.14,))]
gams.set('p2', data)
endEmbeddedCode p2
$batInclude checkData p2 'Test 5.3c failed in GAMS'
option clear=p2;
embeddedCode Python:
data = [((1, 3), (3.14,)), ((1, 4), (3.14,))]
gams.set('p2', data)
endEmbeddedCode p2
$batInclude checkData p2 'Test 5.3d failed in GAMS'
*Test 5.4: Test writing of one dimensional sets using label indexes
execute_unload 'wanted.gdx', i_want=iout;
option clear=iout;
embeddedCode Python:
data = [1, 2]
gams.set('iout', data)
endEmbeddedCode iout
$batInclude checkData iout 'Test 5.4a failed in GAMS'
option clear=iout;
embeddedCode Python:
data = [(1,), (2,)]
gams.set('iout', data)
endEmbeddedCode iout
$batInclude checkData iout 'Test 5.4b failed in GAMS'
execute_unload 'wanted.gdx', i_want_ex=iout;
option clear=iout;
embeddedCode Python:
data = [(1, "text 1"), (2, "text 2")]
gams.set('iout', data)
endEmbeddedCode iout
$batInclude checkData iout 'Test 5.4c failed in GAMS'
option clear=iout;
embeddedCode Python:
data = [((1,), "text 1"), ((2,), "text 2")]
gams.set('iout', data)
endEmbeddedCode iout
$batInclude checkData iout 'Test 5.4d failed in GAMS'
option clear=iout;
embeddedCode Python:
data = [(1, ("text 1",)), (2, ("text 2",))]
gams.set('iout', data)
endEmbeddedCode iout
$batInclude checkData iout 'Test 5.4e failed in GAMS'
option clear=iout;
embeddedCode Python:
data = [((1,), ("text 1",)), ((2,), ("text 2",))]
gams.set('iout', data)
endEmbeddedCode iout
$batInclude checkData iout 'Test 5.4f failed in GAMS'
*Test 5.5: Test writing of multi dimensional sets using label indexes
execute_unload 'wanted.gdx', ij_want=ij;
option clear=ij;
embeddedCode Python:
data = [(1, 3), (1, 4)]
gams.set('ij', data)
endEmbeddedCode ij
$batInclude checkData ij 'Test 5.5a failed in GAMS'
option clear=ij;
embeddedCode Python:
data = [((1, 3),), ((1, 4),)]
gams.set('ij', data)
endEmbeddedCode ij
$batInclude checkData ij 'Test 5.5b failed in GAMS'
execute_unload 'wanted.gdx', ij_want_ex=ij;
option clear=ij;
embeddedCode Python:
data = [(1, 3, 'text 1'), (1, 4, 'text 2')]
gams.set('ij', data)
endEmbeddedCode ij
$batInclude checkData ij 'Test 5.5c failed in GAMS'
option clear=ij;
embeddedCode Python:
data = [((1, 3), 'text 1'), ((1, 4), 'text 2')]
gams.set('ij', data)
endEmbeddedCode ij
$batInclude checkData ij 'Test 5.5d failed in GAMS'
option clear=ij;
embeddedCode Python:
data = [(1, 3, ('text 1',)), (1, 4, ('text 2',))]
gams.set('ij', data)
endEmbeddedCode ij
$batInclude checkData ij 'Test 5.5e failed in GAMS'
option clear=ij;
embeddedCode Python:
data = [((1, 3), ('text 1',)), ((1, 4), ('text 2',))]
gams.set('ij', data)
endEmbeddedCode ij
$batInclude checkData ij 'Test 5.5f failed in GAMS'
*Test 5.6: Test writing of scalar variable using label indexes
execute_unload 'wanted.gdx', v0_want=v0;
option clear=v0;
embeddedCode Python:
data = [(3.14, 0, 0, 10, 1)]
gams.set('v0', data)
endEmbeddedCode v0
$batInclude checkData v0 'Test 5.6a failed in GAMS'
*Test 5.7: Test writing of one dimensonal variables using label indexes
execute_unload 'wanted.gdx', v1_want=v1;
embeddedCode Python:
data = [(1, 3.14, 0, 0, 10, 1), (2, 3.14, 0, 0, 10, 1)]
gams.set('v1', data)
endEmbeddedCode v1
$batInclude checkData v1 'Test 5.7a failed in GAMS'
option clear=v1;
embeddedCode Python:
data = [((1,), 3.14, 0, 0, 10, 1), ((2,), 3.14, 0, 0, 10, 1)]
gams.set('v1', data)
endEmbeddedCode v1
$batInclude checkData v1 'Test 5.7b failed in GAMS'
option clear=v1;
embeddedCode Python:
data = [(1, (3.14, 0, 0, 10, 1)), (2, (3.14, 0, 0, 10, 1))]
gams.set('v1', data)
endEmbeddedCode v1
$batInclude checkData v1 'Test 5.7c failed in GAMS'
option clear=v1;
embeddedCode Python:
data = [((1,), (3.14, 0, 0, 10, 1)), ((2,), (3.14, 0, 0, 10, 1))]
gams.set('v1', data)
endEmbeddedCode v1
$batInclude checkData v1 'Test 5.7d failed in GAMS'
*Test 5.8: Test writing of multi dimensonal variables using label indexes
execute_unload 'wanted.gdx', v2_want=v2;
option clear=v2;
embeddedCode Python:
data = [(1, 3, 3.14, 0, 0, 10, 1), (1, 4, 3.14, 0, 0, 10, 1)]
gams.set('v2', data)
endEmbeddedCode v2
$batInclude checkData v2 'Test 5.8a failed in GAMS'
option clear=v2;
embeddedCode Python:
data = [((1, 3), 3.14, 0, 0, 10, 1), ((1, 4), 3.14, 0, 0, 10, 1)]
gams.set('v2', data)
endEmbeddedCode v2
$batInclude checkData v2 'Test 5.8b failed in GAMS'
option clear=v2;
embeddedCode Python:
data = [(1, 3, (3.14, 0, 0, 10, 1)), (1, 4, (3.14, 0, 0, 10, 1))]
gams.set('v2', data)
endEmbeddedCode v2
$batInclude checkData v2 'Test 5.8c failed in GAMS'
option clear=v2;
embeddedCode Python:
data = [((1, 3), (3.14, 0, 0, 10, 1)), ((1, 4), (3.14, 0, 0, 10, 1))]
gams.set('v2', data)
endEmbeddedCode v2
$batInclude checkData v2 'Test 5.8d failed in GAMS'
*Test 5.9: Test writing of scalar equations using label indexes
execute_unload 'wanted.gdx', e0_want=e0;
option clear=e0;
embeddedCode Python:
data = [(3.14, 0, 0, 10, 1)]
gams.set('e0', data)
endEmbeddedCode e0
$batInclude checkData e0 'Test 5.9 failed in GAMS'
*Test 5.10: Test writing of one dimensonal equations using label indexes
execute_unload 'wanted.gdx', e1_want=e1;
option clear=e1;
embeddedCode Python:
data = [(1, 3.14, 0, 0, 10, 1), (2, 3.14, 0, 0, 10, 1)]
gams.set('e1', data)
endEmbeddedCode e1
$batInclude checkData e1 'Test 5.10a failed in GAMS'
option clear=e1;
embeddedCode Python:
data = [((1,), 3.14, 0, 0, 10, 1), ((2,), 3.14, 0, 0, 10, 1)]
gams.set('e1', data)
endEmbeddedCode e1
$batInclude checkData e1 'Test 5.10b failed in GAMS'
option clear=e1;
embeddedCode Python:
data = [(1, (3.14, 0, 0, 10, 1)), (2, (3.14, 0, 0, 10, 1))]
gams.set('e1', data)
endEmbeddedCode e1
$batInclude checkData e1 'Test 5.10c failed in GAMS'
option clear=e1;
embeddedCode Python:
data = [((1,), (3.14, 0, 0, 10, 1)), ((2,), (3.14, 0, 0, 10, 1))]
gams.set('e1', data)
endEmbeddedCode e1
$batInclude checkData e1 'Test 5.10d failed in GAMS'
*Test 5.11: Test writing of multi dimensonal equations using label indexes
execute_unload 'wanted.gdx', e2_want=e2;
option clear=e2;
embeddedCode Python:
data = [(1, 3, 3.14, 0, 0, 10, 1), (1, 4, 3.14, 0, 0, 10, 1)]
gams.set('e2', data)
endEmbeddedCode e2
$batInclude checkData e2 'Test 5.11a failed in GAMS'
option clear=e2;
embeddedCode Python:
data = [((1, 3), 3.14, 0, 0, 10, 1), ((1, 4), 3.14, 0, 0, 10, 1)]
gams.set('e2', data)
endEmbeddedCode e2
$batInclude checkData e2 'Test 5.11b failed in GAMS'
option clear=e2;
embeddedCode Python:
data = [(1, 3, (3.14, 0, 0, 10, 1)), (1, 4, (3.14, 0, 0, 10, 1))]
gams.set('e2', data)
endEmbeddedCode e2
$batInclude checkData e2 'Test 5.11c failed in GAMS'
option clear=e2;
embeddedCode Python:
data = [((1, 3), (3.14, 0, 0, 10, 1)), ((1, 4), (3.14, 0, 0, 10, 1))]
gams.set('e2', data)
endEmbeddedCode e2
$batInclude checkData e2 'Test 5.11d failed in GAMS'
*** Test adding/retrieving labels/label indexes
*Test 6.1: Test retrieving label indexes from label
embeddedCode Python:
label = gams.getUel(1)
assert label == 'i1', \
"Test 6.1 failed in Python"
label = gams.getUel(3)
assert label == 'j1', \
"Test 6.1 failed in Python"
endEmbeddedCode
*Test 6.2: Test merging/adding of labels
embeddedCode Python:
labelIndex = gams.mergeUel("i2")
assert labelIndex == 2, \
"Test 6.2 failed in Python"
nrUels = gams.getUelCount()
assert nrUels == 10, \
"Test 6.2 failed in Python"
#Note that we can not add new UELs using mergeUel during execution time
endEmbeddedCode
*** Test set() method using mergeType=MergeType.MERGE using labels
*Test 7.1: Test mergeType=MergeType.MERGE with parameters
execute_unload 'wanted.gdx', p2_want_merge=p2;
option clear=p2;
embeddedCode Python:
data = [('i1', 'j1', 3.14), ('i1', 'j2', 3.14)]
gams.set('p2', data)
endEmbeddedCode p2
embeddedCode Python:
data = [('i1', 'j2', 3.14), ('i1', 'j3', 3.14)]
gams.set('p2', data, mergeType=MergeType.MERGE)
endEmbeddedCode p2
$batInclude checkData p2 'Test 7.1 failed in GAMS'
*Test 7.2: Test mergeType=MergeType.MERGE with sets
execute_unload 'wanted.gdx', ij_want_merge=ij;
option clear=ij;
embeddedCode Python:
data = [('i1', 'j1'), ('i1', 'j2')]
gams.set('ij', data)
endEmbeddedCode ij
embeddedCode Python:
data = [('i1', 'j2'), ('i1', 'j3')]
gams.set('ij', data, mergeType=MergeType.MERGE)
endEmbeddedCode ij
$batInclude checkData ij 'Test 7.2 failed in GAMS'
*Test 7.3: Test mergeType=MergeType.MERGE with variables
execute_unload 'wanted.gdx', v2_want_merge=v2;
option clear=v2;
embeddedCode Python:
data = [("i1", "j1", 3.14, 0, 0, 10, 1), ("i1", "j2", 3.14, 0, 0, 10, 1)]
gams.set('v2', data)
endEmbeddedCode v2
embeddedCode Python:
data = [("i1", "j2", 3.14, 0, 0, 10, 1), ("i1", "j3", 3.14, 0, 0, 10, 1)]
gams.set('v2', data, mergeType=MergeType.MERGE)
endEmbeddedCode v2
$batInclude checkData v2 'Test 7.3 failed in GAMS'
*Test 7.4: Test mergeType=MergeType.MERGE with equations
execute_unload 'wanted.gdx', e2_want_merge=e2;
option clear=e2;
embeddedCode Python:
data = [("i1", "j1", 3.14, 0, 0, 10, 1), ("i1", "j2", 3.14, 0, 0, 10, 1)]
gams.set('e2', data)
endEmbeddedCode e2
embeddedCode Python:
data = [("i1", "j2", 3.14, 0, 0, 10, 1), ("i1", "j3", 3.14, 0, 0, 10, 1)]
gams.set('e2', data, mergeType=MergeType.MERGE)
endEmbeddedCode e2
$batInclude checkData e2 'Test 7.4 failed in GAMS'
*** Test set() method using mergeType=MergeType.MERGE using label indexes instead of strings
*Test 8.1: Test mergeType=MergeType.MERGE with parameters using label indexes
execute_unload 'wanted.gdx', p2_want_merge=p2;
option clear=p2;
embeddedCode Python:
data = [(1, 3, 3.14), (1, 4, 3.14)]
gams.set('p2', data)
endEmbeddedCode p2
embeddedCode Python:
data = [(1, 4, 3.14), (1, 5, 3.14)]
gams.set('p2', data, mergeType=MergeType.MERGE)
endEmbeddedCode p2
$batInclude checkData p2 'Test 8.1 failed in GAMS'
*Test 8.2: Test mergeType=MergeType.MERGE with sets using label indexes
execute_unload 'wanted.gdx', ij_want_merge=ij;
option clear=ij;
embeddedCode Python:
data = [(1, 3), (1, 4)]
gams.set('ij', data)
endEmbeddedCode ij
embeddedCode Python:
data = [(1, 4), (1, 5)]
gams.set('ij', data, mergeType=MergeType.MERGE)
endEmbeddedCode ij
$batInclude checkData ij 'Test 8.2 failed in GAMS'
*Test 8.3: Test mergeType=MergeType.MERGE with variables using label indexes
execute_unload 'wanted.gdx', v2_want_merge=v2;
option clear=v2;
embeddedCode Python:
data = [(1, 3, 3.14, 0, 0, 10, 1), (1, 4, 3.14, 0, 0, 10, 1)]
gams.set('v2', data)
endEmbeddedCode v2
embeddedCode Python:
data = [(1, 4, 3.14, 0, 0, 10, 1), (1, 5, 3.14, 0, 0, 10, 1)]
gams.set('v2', data, mergeType=MergeType.MERGE)
endEmbeddedCode v2
$batInclude checkData v2 'Test 8.3 failed in GAMS'
*Test 8.4: Test mergeType=MergeType.MERGE with equations using label indexes
execute_unload 'wanted.gdx', e2_want_merge=e2;
option clear=e2;
embeddedCode Python:
data = [(1, 3, 3.14, 0, 0, 10, 1), (1, 4, 3.14, 0, 0, 10, 1)]
gams.set('e2', data)
endEmbeddedCode e2
embeddedCode Python:
data = [(1, 4, 3.14, 0, 0, 10, 1), (1, 5, 3.14, 0, 0, 10, 1)]
gams.set('e2', data, mergeType=MergeType.MERGE)
endEmbeddedCode e2
$batInclude checkData e2 'Test 8.4 failed in GAMS'
*** Miscellaneous tests
*Test 9.1: Test reading of empty symbols
option clear=p2;
embeddedCode Python:
p2 = list(gams.get('p2'))
assert p2 == [], \
"Test 9.1 failed in Python"
endEmbeddedCode
*Test 9.2: Test writing of empty symbols
option clear=p2_want;
execute_unload 'wanted.gdx', p2_want=p2;
embeddedCode Python:
data = []
gams.set('p2', data)
endEmbeddedCode p2
$batInclude checkData p2 'Test 9.2 failed in GAMS'
*Test 9.3: Test writing of empty scalars
option clear=p0_want;
execute_unload 'wanted.gdx', p0_want=p0;
embeddedCode Python:
data = []
gams.set('p0', data)
endEmbeddedCode p0
$batInclude checkData p0 'Test 9.3 failed in GAMS'
*Test 9.4: Test clear behavior of scalar symbols and their default values
option clear=p0_want;
option clear=e0_want;
positive variable xpos / l 0 /;
negative variable xneg / l 0 /;
execute_unload 'wanted.gdx', p0_want=p0, e0_want=e0, xpos, xneg;
embeddedCode Python:
gams.db['p0'].clear()
gams.db['e0'].clear()
gams.db['xpos'].clear()
gams.db['xneg'].clear()
endEmbeddedCode p0, e0, xpos, xneg
$batInclude checkData 'p0 e0 xpos xneg' 'Test 9.4 failed in GAMS'
*Test 9.5: Test special values
embeddedCode Python:
gams.epsAsZero = False
sv = dict(gams.get('sv_want'))
if sv['myUNDF']!=GMS_SV_UNDEF:
raise ValueError('Test 9.5 failed in GAMS: Expect UNDEF')
if sv['myNA']==sv['myNA']:
raise ValueError('Test 9.5 failed in GAMS: Expect NAN')
if sv['myPINF']!=float('inf'):
raise ValueError('Test 9.5 failed in GAMS: Expect INF')
if sv['myMINF']!=float('-inf'):
raise ValueError('Test 9.5 failed in GAMS: Expect -INF')
if sv['myEPS']!= gams._eps:
raise ValueError('Test 9.5 failed in GAMS: Expect EPS')
gams.db['sv_want'].copy_symbol(gams.db['svX'])
gams.set('svY',[('myUNDF',GMS_SV_UNDEF),('myNA',float('nan')),('myPINF',float('inf')),('myMINF',float('-inf')),('myEPS',gams._eps)])
endEmbeddedCode svX svY
execute_unload 'wanted.gdx', sv_want=svX;
$batInclude checkData 'svX' 'Test 9.5 failed in GAMS (svX)'
execute_unload 'wanted.gdx', sv_want=svY;
$batInclude checkData 'svY' 'Test 9.5 failed in GAMS (svY)'
*Test 9.6: Test special values (EPS)
*Note that this test is different from the corresponding test in embpy01 since $onEps and $offEps do not have an effect during GAMS runtime
*Therefore we just check that $onEps has no effect
Parameter svZeroToZero(svIdx), svZeroToZero_want(svIdx);
$onEps
embeddedCode Python:
gams.db['svZeroToZero'].add_record('myEPS').value = 0
endEmbeddedCode svZeroToZero
execute_unload 'wanted.gdx', svZeroToZero_want=svZeroToZero;
$batInclude checkData 'svZeroToZero' 'Test 9.6 failed in GAMS (svZeroToZero)'
parameter witheps(*) / i1 1, i2 EPS /;
embeddedCode Python:
gams.ws.my_eps = 0
p = [ r.value for r in gams.db['witheps'] ]
assert p == [1.0, 0], \
"Test 9.7 failed in Python"
endEmbeddedCode
embeddedCode Python:
p = [ r.value for r in gams.db['witheps'] ]
assert p == [1.0, 4.94066E-324], \
"Test 9.8 failed in Python"
endEmbeddedCode
* Tests for long strings and auto indentation behavior
*Test 10.1: Test long strings : Skip of auto-indentation 1
embeddedCode Python:
s = """some
long
string
""" + '''and another''' + """ long
string
to
be added
"""
assert s == "some\nlong\n string\nand another long\nstring\n to\nbe added\n", \
"Test 10.1 failed in Python"
endEmbeddedCode
*Test 10.2: Test long strings : Skip of auto-indentation 2
embeddedCode Python:
s = '''some
long
string
''' + """and another""" + ''' long
string
to
be added
'''
assert s == "some\nlong\n string\nand another long\nstring\n to\nbe added\n", \
"Test 10.2 failed in Python"
endEmbeddedCode
*Test 10.3: Test long strings : embed """ in '''
embeddedCode Python:
s = '''some
long
string
""" + """and another""" + """ long
string
to
be added
'''
assert s == '''some\nlong\n string\n""" + """and another""" + """ long\nstring\n to\nbe added\n''', \
"Test 10.3 failed in Python"
endEmbeddedCode
*Test 10.4: Test long strings : embed ''' in """
embeddedCode Python:
s = """some
long
string
''' + '''and another''' + ''' long
string
to
be added
"""
assert s == """some\nlong\n string\n''' + '''and another''' + ''' long\nstring\n to\nbe added\n""", \
"Test 10.4 failed in Python"
endEmbeddedCode
*Test 10.5: Test behavior of line continuation character
embeddedCode Python:
s = "some string\
with line continuation\
characters"
assert s == "some string with line continuation characters", \
"Test 10.5 failed in Python"
endEmbeddedCode
*Test 10.6: Mix line continuation character with long strings
embeddedCode Python:
s = """some string\
with line continuation
characters"""
assert s == "some stringwith line continuation\ncharacters", \
"Test 10.6 failed in Python"
endEmbeddedCode
*Test 11: Run in a directory with long path name
$call mkdir 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
$onEcho > 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890%system.dirsep%ec11.gms
embeddedCode Python:
pass
endEmbeddedCode
$offEcho
$call.checkErrorLevel gams ec11 lo=%GAMS.lo% cdir=123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
*Test 12: Test for specifying source encoding
* UTF-8 is the default
$onEmbeddedCode Python:
with open('ec_utf8.inc', 'w', encoding='utf-8') as f:
f.write("embeddedCode Python:\n")
f.write("s = 'öäü'\n")
f.write("endEmbeddedCode")
$offEmbeddedCode
$include ec_utf8.inc
* Change encoding to cp1252
$onEmbeddedCode Python:
with open('ec_cp1252.inc', 'w', encoding='cp1252') as f:
f.write("embeddedCode Python:\n")
f.write("# coding=cp1252\n")
f.write("s = 'öäü'\n")
f.write("endEmbeddedCode")
$offEmbeddedCode
$include ec_cp1252.inc
* cp1252 is still set from the previous embedded code section
$onEmbeddedCode Python:
with open('ec_cp1252_2.inc', 'w', encoding='cp1252') as f:
f.write("embeddedCode Python:\n")
f.write("s = 'öäü'\n")
f.write("endEmbeddedCode")
$offEmbeddedCode
$include ec_cp1252_2.inc
* need to revert to UTF-8
$onEmbeddedCode Python:
with open('ec_utf8_2.inc', 'w', encoding='utf-8') as f:
f.write("embeddedCode Python:\n")
f.write("# coding=utf-8\n")
f.write("s = 'öäü'\n")
f.write("endEmbeddedCode")
$offEmbeddedCode
$include ec_utf8_2.inc
*Test 13: Test for correct alias to universe
$onEcho > ec13.gms
Set s(*); Alias (*,uni);
$echo Alias (uni, *); > unialias_expect.txt
embeddedCode Python:
gams.wsWorkingDir = '.'
gams.db.export('unialias.gdx')
endEmbeddedCode
execute.checkErrorLevel 'gdxdump unialias.gdx | grep Alias > unialias.txt'
execute.checkErrorLevel 'diff unialias.txt unialias_expect.txt > %system.NullFile%'
$offEcho
$call.checkErrorLevel gams ec13.gms lo=%GAMS.lo%
*Test 14: Test implicit dimension setting when loading symbol with unknown dimension
$onEcho > ec14.gms
Scalar f /90/;
$offEcho
$call.checkErrorLevel gams ec14.gms lo=%GAMS.lo% gdx=ec14
Parameter f Parameter with unknown dimension;
execute_load 'ec14.gdx', f;
abort$(f<>90) 'f should be 90', f;
*Test 15: Test gams.printLog with lo=0
$onEcho > test_printlog.gms
embeddedCode Python:
gams.printLog("some log")
endEmbeddedCode
$offEcho
execute.checkErrorLevel "gams test_printlog.gms lo=0"
*Test 16: Test printLog with "%"
$onEchoV > print_log_percent.gms
embeddedCode Python:
gams.printLog("%file% was not specified")
endEmbeddedCode
$offEcho
$call.checkErrorLevel gams print_log_percent.gms > print_log_percent.log
$onEmbeddedCode Python:
with open("print_log_percent.log", "r")as f:
if f.read().count("%file%") != 1:
raise Exception('Expected "%file%" to be contained in log output once')
$offEmbeddedCode
*Test 17: Test gams.printLog end parameter
$onEcho > test_printlog_newline.gms
embeddedCode Python:
gams.printLog("s1")
gams.printLog("s2")
gams.printLog("s3", end="\n")
gams.printLog("s4", end="")
gams.printLog("s5", end="x")
endEmbeddedCode
$offEcho
execute.checkErrorLevel "gams test_printlog_newline.gms > log_newline.txt";
embeddedCode Python:
with open("log_newline.txt", "r") as f:
s = f.read()
if "s1\ns2\ns3\ns4s5x" not in s:
raise Exception("Unexpected log content.")
endEmbeddedCode
*Test 18: Test EC arguments containing quotes
put_utility "ecArguments" / "argument containing 'single' and " '"double" quotes';
embeddedCode Python:
args = gams.arguments
if args != '''argument containing 'single' and "double" quotes''':
raise Exception("gams.arguments not as expected")
endEmbeddedCode