Skip to content

Commit 9e6914b

Browse files
committed
Test Streams
For #24
1 parent 1374bbc commit 9e6914b

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

isc/py/Main.cls

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Class isc.py.Main
77
/// optionally return variable value.
88
/// serialization - currenlty: 0 - string serialization, 1 - repr serialization.
99
/// write ##class(isc.py.Main).SimpleString()
10-
ClassMethod SimpleString(code As %String = "", variable As %String = "", serialization As %Integer = 0, Output result) As %Status
10+
ClassMethod SimpleString(code As %String = "", variable As %String = "", serialization As %Integer = {##class(isc.py.Callout).#SerializationStr}, Output result) As %Status
1111
{
1212
#dim sc As %Status = $$$OK
1313

@@ -53,7 +53,7 @@ ClassMethod ExcuteCode(code As %Stream.Object, variable As %String = "") As %Sta
5353
if length>$$$MaxStringLength {
5454
set sc = ##class(isc.py.Callout).StreamInit(length)
5555
quit:$$$ISERR(sc) sc
56-
set sc = ##class(isc.py.Callout).StreamWrite(variable _ "=")
56+
set:hasVar sc = ##class(isc.py.Callout).StreamWrite(variable _ "=")
5757
quit:$$$ISERR(sc) sc
5858

5959
if $isObject(code) {
@@ -87,7 +87,7 @@ ClassMethod ExcuteCode(code As %Stream.Object, variable As %String = "") As %Sta
8787
/// variable - variable name
8888
/// useString - if variable length is less than $$$MaxStringLength, return string instead of stream. Ignored if variable length is more than $$$MaxStringLength
8989
/// set sc = ##class(isc.py.Main).GetVariable()
90-
ClassMethod GetVariable(variable As %String, serialization As %Integer = 0, ByRef stream As %Stream.Object, useString As %Boolean = {$$$NO}) As %Status
90+
ClassMethod GetVariable(variable As %String, serialization As %Integer = {##class(isc.py.Callout).#SerializationStr}, ByRef stream As %Stream.Object, useString As %Boolean = {$$$NO}) As %Status
9191
{
9292
#dim sc As %Status = $$$OK
9393
set sc = ..GetVariableInfo(variable, serialization, .defined, .type, .length)
@@ -130,7 +130,7 @@ ClassMethod GetVariable(variable As %String, serialization As %Integer = 0, ByRe
130130
/// type - variable type
131131
/// length - length (in symbols) of variable chosen serialization
132132
/// set sc = ##class(isc.py.Main).GetVariableInfo()
133-
ClassMethod GetVariableInfo(variable As %String = "", serialization As %Integer = 0, Output defined As %Boolean, Output type As %String, Output length As %String) As %Status
133+
ClassMethod GetVariableInfo(variable As %String = "", serialization As %Integer = {##class(isc.py.Callout).#SerializationStr}, Output defined As %Boolean, Output type As %String, Output length As %String) As %Status
134134
{
135135
#dim sc As %Status = $$$OK
136136
kill defined, type, length

isc/py/unit/TestCase.cls

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,37 @@ Method TestMultiline()
173173
do ##class(isc.py.Callout).SimpleString("del cube")
174174
}
175175

176-
/// Manually test production.
177-
/// do ##class(isc.py.unit.TestCase).TestProductionStream()
178-
ClassMethod PassProductionStream(count As %Integer = 1000000, separateLines As %Boolean = {$$$YES})
176+
Method TestStream()
179177
{
180178
set variable = "x"
179+
set iterations = 1000000
180+
set code = ..GetCodeStream(variable, iterations)
181+
182+
set sc = ##class(isc.py.Main).ExcuteCode(code)
183+
do $$$AssertStatusOK(sc, "Stream executed")
184+
185+
set sc = ##class(isc.py.Main).GetVariable(variable,, .result, $$$YES)
186+
do $$$AssertStatusOK(sc, "Variable returned")
187+
188+
do $$$AssertEquals(iterations, result, "Variable value is correct")
189+
}
190+
191+
ClassMethod GetCodeStream(variable As %String, iterations As %Integer = 1000000) As %Stream.GlobalCharacter
192+
{
181193
set stream = ##class(%Stream.GlobalCharacter).%New()
182-
for i=1:1:count {
194+
for i=1:1:iterations {
183195
do stream.WriteLine((variable _ "=" _ i))
184196
}
185197
do stream.%Save()
198+
quit stream
199+
}
200+
201+
/// Manually test production.
202+
/// do ##class(isc.py.unit.TestCase).TestProductionStream()
203+
ClassMethod PassProductionStream(count As %Integer = 1000000, separateLines As %Boolean = {$$$YES})
204+
{
205+
set variable = "x"
206+
set stream = ..GetCodeStream(variable, count)
186207

187208
write "Count: ", count, !
188209
write "SeparateLines: ", separateLines, !

0 commit comments

Comments
 (0)