Skip to content

Commit a4f1c57

Browse files
committed
UnitTests: removed string overload, added proxy object tests
1 parent 46cfa17 commit a4f1c57

File tree

1 file changed

+59
-14
lines changed

1 file changed

+59
-14
lines changed

isc/py/unit/TestCase.cls

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,25 @@ Method TestSimpleString()
1616
do ##class(isc.py.Callout).SimpleString("y=1")
1717
set y = ##class(isc.py.Callout).SimpleString(, "y")
1818
do $$$AssertEquals(y, 1, "Context is persisted")
19-
20-
do ##class(isc.py.Callout).Finalize()
21-
22-
set y = ##class(isc.py.Callout).SimpleString(, "y")
23-
do $$$AssertEquals(y, "", "Context successfully flushed")
2419
}
2520

2621
Method TestLimit()
2722
{
28-
do ##class(isc.py.Callout).Finalize()
2923

3024
do ##class(isc.py.Callout).SimpleString("str1000=''.join('A' for _ in range(1000))")
3125

3226
for limit = 32767,135108,$$$MaxStringLength {
3327
set quotient = limit\1000
3428
set modulus = limit#1000
35-
set str = ##class(isc.py.Callout).SimpleString("str=''.join(str1000 for i in range("_quotient_")) + str1000[:" _ modulus _ "]", "str")
36-
do $$$AssertEquals($l(str), limit, "Returned " _ limit _ " characters")
29+
set str1 = ##class(isc.py.Callout).SimpleString("str1=''.join(str1000 for i in range("_quotient_")) + str1000[:" _ modulus _ "]", "str1")
30+
do $$$AssertEquals($l(str1), limit, "Returned " _ limit _ " characters")
3731
}
3832

3933
try {
4034
set limit = $$$MaxStringLength + 1
4135
set quotient = limit\1000
4236
set modulus = limit#1000
43-
set str = ##class(isc.py.Callout).SimpleString("str=''.join(str1000 for i in range("_quotient_")) + str1000[:" _ modulus _ "]", "str")
37+
set str1 = ##class(isc.py.Callout).SimpleString("str1=''.join(str1000 for i in range("_quotient_")) + str1000[:" _ modulus _ "]", "str1")
4438
} catch ex {
4539
do $$$AssertEquals(ex.Name, "<FUNCTION>" , "Correctly failed to pass " _ limit _ " characters")
4640
}
@@ -57,7 +51,7 @@ Method TestPassSpeedIn()
5751
set rounds = 295
5852
set start = $zh
5953
for i = 1:1:rounds {
60-
do ##class(isc.py.Callout).SimpleString("str='" _ str _ "'")
54+
do ##class(isc.py.Callout).SimpleString("str1='" _ str _ "'")
6155
}
6256
set end = $zh
6357

@@ -73,12 +67,12 @@ Method TestPassSpeedOut()
7367
set limit = $$$MaxStringLength
7468
set quotient = limit\1000
7569
set modulus = limit#1000
76-
do ##class(isc.py.Callout).SimpleString("str=''.join(str1000 for i in range("_quotient_")) + str1000[:" _ modulus _ "]", "str")
70+
do ##class(isc.py.Callout).SimpleString("str1=''.join(str1000 for i in range("_quotient_")) + str1000[:" _ modulus _ "]", "str1")
7771

7872
set rounds = 295
7973
set start = $zh
8074
for i = 1:1:rounds {
81-
set str = ##class(isc.py.Callout).SimpleString(, "str")
75+
set str = ##class(isc.py.Callout).SimpleString(, "str1")
8276
kill str
8377
}
8478
set end = $zh
@@ -92,11 +86,11 @@ Method TestPassSpeedOut()
9286

9387
Method TestSetCallSpeed()
9488
{
95-
do ##class(isc.py.Callout).SimpleString("str=''")
89+
do ##class(isc.py.Callout).SimpleString("str1=''")
9690
set rounds = 100000
9791
set start = $zh
9892
for i = 1:1:rounds {
99-
do ##class(isc.py.Callout).SimpleString("str=" _ i)
93+
do ##class(isc.py.Callout).SimpleString("str1=" _ i)
10094
}
10195
set end = $zh
10296

@@ -444,5 +438,56 @@ Method TestExecuteFunctionArgs()
444438
do $$$AssertEquals(result, "Positional: Hello World! Keyword: Alice, Bob", "str.format returned expected string")
445439
}
446440

441+
Method TestProxyObject()
442+
{
443+
set sc = ##class(isc.py.init.Test).InitPerson()
444+
do $$$AssertStatusOK(sc, "Loaded person class")
445+
446+
set variable = "p1"
447+
448+
set nameRaw = "Ed"
449+
set name = ##class(isc.py.util.Converter).EscapeString(nameRaw)
450+
set age = 25
451+
set obj = ##class(isc.py.gw.DynamicObject).%New("Person", variable, ##class(isc.py.Callout).#SerializationStr, name, age, "'Test'")
452+
453+
set nameReturned = obj.name
454+
do $$$AssertEquals(nameRaw, nameReturned)
455+
456+
set name2 = "Bob"
457+
set obj.name = name2
458+
set nameReturned = obj.name
459+
460+
do $$$AssertEquals(name2, nameReturned)
461+
462+
set newProp = "Dog"
463+
set obj.pet = newProp
464+
set newPropReturned = obj.pet
465+
do $$$AssertEquals(newProp, newPropReturned)
466+
467+
set ageReturned = obj.getAge()
468+
do $$$AssertEquals(age, ageReturned)
469+
470+
set plus = 10
471+
set plusReturned = obj.getAgePlus(plus)
472+
do $$$AssertEquals(age + plus, plusReturned)
473+
474+
kill obj, nameReturned
475+
476+
set obj = ##class(isc.py.gw.DynamicObject).%New(, variable)
477+
478+
set nameReturned = obj.name
479+
do $$$AssertEquals(name2, nameReturned)
480+
481+
set sc = obj.%ToDynObj(.dynObj)
482+
483+
do $$$AssertEquals(obj.city, dynObj.city)
484+
485+
set sc = obj.%Destroy()
486+
do $$$AssertStatusOK(sc, "Destroyed person object")
487+
488+
set sc = ##class(isc.py.Main).GetVariableInfo(variable,,.defined)
489+
do $$$AssertNotTrue(defined, "Person object is undefined")
490+
}
491+
447492
}
448493

0 commit comments

Comments
 (0)