|
| 1 | +Class isc.py.unit.TestCase Extends %UnitTest.TestCase |
| 2 | +{ |
| 3 | + |
| 4 | +Method OnBeforeAllTests() As %Status |
| 5 | +{ |
| 6 | + do ##class(isc.py.Callout).Setup() |
| 7 | + quit $$$OK |
| 8 | +} |
| 9 | + |
| 10 | +Method TestBasic() |
| 11 | +{ |
| 12 | + set random = ##class(isc.py.Callout).GetRandom() |
| 13 | + do $$$AssertTrue(random<1, "GetRandom works") |
| 14 | +} |
| 15 | + |
| 16 | +Method TestBasicSimpleString() |
| 17 | +{ |
| 18 | + set random = ##class(isc.py.Callout).SimpleStringFull() |
| 19 | + do $$$AssertTrue(random<1, "SimpleStringFull works") |
| 20 | +} |
| 21 | + |
| 22 | +Method TestSimpleString() |
| 23 | +{ |
| 24 | + do ##class(isc.py.Callout).Finalize() |
| 25 | + set random = ##class(isc.py.Callout).SimpleString() |
| 26 | + do $$$AssertTrue(random<1, "SimpleString works") |
| 27 | + |
| 28 | + do ##class(isc.py.Callout).SimpleString("y=1") |
| 29 | + set y = ##class(isc.py.Callout).SimpleString(, "y") |
| 30 | + do $$$AssertEquals(y, 1, "Context is persisted") |
| 31 | + |
| 32 | + do ##class(isc.py.Callout).Finalize() |
| 33 | + |
| 34 | + set y = ##class(isc.py.Callout).SimpleString(, "y") |
| 35 | + do $$$AssertEquals(y, "", "Context successfully flushed") |
| 36 | +} |
| 37 | + |
| 38 | +Method TestLimit() |
| 39 | +{ |
| 40 | + do ##class(isc.py.Callout).Finalize() |
| 41 | + |
| 42 | + do ##class(isc.py.Callout).SimpleString("str1000=''.join('A' for _ in range(1000))") |
| 43 | + |
| 44 | + for limit = 32767,135108,$$$MaxStringLength { |
| 45 | + set quotient = limit\1000 |
| 46 | + set modulus = limit#1000 |
| 47 | + set str = ##class(isc.py.Callout).SimpleString("str=''.join(str1000 for i in range("_quotient_")) + str1000[:" _ modulus _ "]", "str") |
| 48 | + do $$$AssertEquals($l(str), limit, "Returned " _ limit _ " characters") |
| 49 | + } |
| 50 | + |
| 51 | + try { |
| 52 | + set limit = $$$MaxStringLength + 1 |
| 53 | + set quotient = limit\1000 |
| 54 | + set modulus = limit#1000 |
| 55 | + set str = ##class(isc.py.Callout).SimpleString("str=''.join(str1000 for i in range("_quotient_")) + str1000[:" _ modulus _ "]", "str") |
| 56 | + } catch ex { |
| 57 | + do $$$AssertEquals(ex.Name, "<FUNCTION>" , "Correctly failed to pass " _ limit _ " characters") |
| 58 | + } |
| 59 | + |
| 60 | + do $$$AssertTrue($isObject($g(ex)), "If failed then we managed to pass more characters than in character limit") |
| 61 | +} |
| 62 | + |
| 63 | +Method TestPassSpeedIn() |
| 64 | +{ |
| 65 | + set setChars = 6 |
| 66 | + set limit = 32767 - setChars |
| 67 | + set str = $tr($j("", limit), " ", "A") |
| 68 | + |
| 69 | + set rounds = 295 |
| 70 | + set start = $zh |
| 71 | + for i = 1:1:rounds { |
| 72 | + do ##class(isc.py.Callout).SimpleString("str='" _ str _ "'") |
| 73 | + } |
| 74 | + set end = $zh |
| 75 | + |
| 76 | + set time = end - start |
| 77 | + set megabytes = $fnumber((limit+setChars)*rounds/(1024**2), "", 2) |
| 78 | + set speed = $fnumber(megabytes/time, "", 2) |
| 79 | + |
| 80 | + do $$$LogMessage($$$FormatText("Passed in %1 Mb in %2 sec. Speed: %3 Mb/sec.", megabytes, time, speed)) |
| 81 | +} |
| 82 | + |
| 83 | +Method TestPassSpeedOut() |
| 84 | +{ |
| 85 | + set limit = $$$MaxStringLength |
| 86 | + set quotient = limit\1000 |
| 87 | + set modulus = limit#1000 |
| 88 | + do ##class(isc.py.Callout).SimpleString("str=''.join(str1000 for i in range("_quotient_")) + str1000[:" _ modulus _ "]", "str") |
| 89 | + |
| 90 | + set rounds = 295 |
| 91 | + set start = $zh |
| 92 | + for i = 1:1:rounds { |
| 93 | + set str = ##class(isc.py.Callout).SimpleString(, "str") |
| 94 | + kill str |
| 95 | + } |
| 96 | + set end = $zh |
| 97 | + |
| 98 | + set time = end - start |
| 99 | + set megabytes = $fnumber(limit*rounds/(1024**2), "", 2) |
| 100 | + set speed = $fnumber(megabytes/time, "", 2) |
| 101 | + |
| 102 | + do $$$LogMessage($$$FormatText("Passed out %1 Mb in %2 sec. Speed: %3 Mb/sec.", megabytes, time, speed)) |
| 103 | +} |
| 104 | + |
| 105 | +Method TestSetCallSpeed() |
| 106 | +{ |
| 107 | + do ##class(isc.py.Callout).SimpleString("str=''") |
| 108 | + set rounds = 100000 |
| 109 | + set start = $zh |
| 110 | + for i = 1:1:rounds { |
| 111 | + do ##class(isc.py.Callout).SimpleString("str=" _ i) |
| 112 | + } |
| 113 | + set end = $zh |
| 114 | + |
| 115 | + set time = end - start |
| 116 | + set speed = $fnumber(rounds/time, "", 2) |
| 117 | + |
| 118 | + do $$$LogMessage($$$FormatText("Called python %1 times in %2 sec. Speed: %3 calls/sec.", rounds, time, speed)) |
| 119 | +} |
| 120 | + |
| 121 | +Method TestUnicode() |
| 122 | +{ |
| 123 | + set unicode = "ПРИВЕТ" |
| 124 | + set result = ##class(isc.py.Callout).SimpleString("result='" _ unicode _ "'", "result") |
| 125 | + do $$$AssertEquals(unicode, result, "Passing unicode characters works") |
| 126 | +} |
| 127 | + |
| 128 | +} |
| 129 | + |
0 commit comments