Skip to content

Commit cc3700d

Browse files
committed
Added unit tests for Python CodeUnit and embedded python in .CLS files
1 parent 040e56a commit cc3700d

File tree

1 file changed

+29
-11
lines changed
  • internal/testing/unit_tests/UnitTest/TestCoverage/Unit

1 file changed

+29
-11
lines changed

internal/testing/unit_tests/UnitTest/TestCoverage/Unit/CodeUnit.cls

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Method TestCodeUnitCreation()
1616
#dim tCodeUnit As TestCoverage.Data.CodeUnit
1717
Set tClsName = $classname()_".CLS"
1818
Set tIntName = $classname()_".1.INT"
19+
Set tPyName = $classname()_".PY"
1920
Set tSC = ##class(TestCoverage.Data.CodeUnit).GetCurrentByName(tIntName,$Namespace,.tIntCodeUnit)
2021
Do $$$AssertStatusOK(tSC,"Found test coverage data for "_tIntName)
2122
Do $$$AssertEquals(tIntCodeUnit.Name,$classname()_".1")
@@ -27,28 +28,40 @@ Method TestCodeUnitCreation()
2728
Do $$$AssertEquals(tGenCodeUnit.Name,$classname()_".G1")
2829
Do $$$AssertEquals(tGenCodeUnit.Type,"INT")
2930

31+
3032
Set tSC = ##class(TestCoverage.Data.CodeUnit).GetCurrentByName(tClsName,$Namespace,.tClsCodeUnit)
3133
Do $$$AssertStatusOK(tSC,"Found test coverage data for "_tClsName)
3234
Do $$$AssertEquals(tClsCodeUnit.Name,$classname())
3335
Do $$$AssertEquals(tClsCodeUnit.Type,"CLS")
3436

37+
Set tSC = ##class(TestCoverage.Data.CodeUnit).GetCurrentByName(tPyName,$Namespace,.tPyCodeUnit)
38+
Do $$$AssertStatusOK(tSC,"Found test coverage data for "_tPyName)
39+
Do $$$AssertEquals(tPyCodeUnit.Name,$classname())
40+
Do $$$AssertEquals(tPyCodeUnit.Type,"PY")
41+
42+
Set tSC = tClsCodeUnit.UpdatePyExecutableLines($classname(),.tPyCodeUnit)
43+
Do $$$AssertStatusOK(tSC,"Found updated executable line data for "_tClsName)
44+
3545
Set tConstantReturnValueLine = tClsCodeUnit.MethodMap.GetAt("SampleConstantReturnValue")
3646
Set tCodeGeneratorLine = tClsCodeUnit.MethodMap.GetAt("SampleCodeGenerator")
3747
Set tNormalMethodLine = tClsCodeUnit.MethodMap.GetAt("SampleNormalMethod")
48+
Set tPythonMethodLine = tClsCodeUnit.MethodMap.GetAt("SamplePythonMethod")
3849

3950
Do $$$AssertNotEquals(tConstantReturnValueLine,"")
4051
Do $$$AssertNotEquals(tCodeGeneratorLine,"")
4152
Do $$$AssertNotEquals(tNormalMethodLine,"")
53+
Do $$$AssertNotEquals(tPythonMethodLine,"")
4254

4355
// tTestLines(line number) = $ListBuild(description, executable (default 1), mapped (default 1), mapped from hash (if relevant), mapped from line (if relevant))
4456
Set tTestLines(tConstantReturnValueLine+2) = $ListBuild("SampleConstantReturnValue+1",0,0)
45-
Set tTestLines(tCodeGeneratorLine+2) = $ListBuild("SampleCodeGenerator+1",,,tGenCodeUnit.Hash,tGenCodeUnit.MethodMap.GetAt("SampleCodeGenerator")+1)
46-
Set tTestLines(tCodeGeneratorLine+3) = $ListBuild("SampleCodeGenerator+2",,,tGenCodeUnit.Hash,tGenCodeUnit.MethodMap.GetAt("SampleCodeGenerator")+2)
47-
Set tTestLines(tCodeGeneratorLine+4) = $ListBuild("SampleCodeGenerator+3",,,tGenCodeUnit.Hash,tGenCodeUnit.MethodMap.GetAt("SampleCodeGenerator")+3)
57+
Set tTestLines(tCodeGeneratorLine+2) = $ListBuild("SampleCodeGenerator+1",,,tGenCodeUnit.Hash,tGenCodeUnit.MethodMap.GetAt("SampleCodeGenerator")+1, "INT")
58+
Set tTestLines(tCodeGeneratorLine+3) = $ListBuild("SampleCodeGenerator+2",,,tGenCodeUnit.Hash,tGenCodeUnit.MethodMap.GetAt("SampleCodeGenerator")+2, "INT")
59+
Set tTestLines(tCodeGeneratorLine+4) = $ListBuild("SampleCodeGenerator+3",,,tGenCodeUnit.Hash,tGenCodeUnit.MethodMap.GetAt("SampleCodeGenerator")+3, "INT")
4860
Set methodLabel = $Select($System.Version.GetMajor()<2023:"z",1:"")_"SampleNormalMethod"
49-
Set tTestLines(tNormalMethodLine+2) = $ListBuild("SampleNormalMethod+1",,,tIntCodeUnit.Hash,tIntCodeUnit.MethodMap.GetAt(methodLabel)+1)
50-
Set tTestLines(tNormalMethodLine+3) = $ListBuild("SampleNormalMethod+2",,,tIntCodeUnit.Hash,tIntCodeUnit.MethodMap.GetAt(methodLabel)+2)
51-
61+
Set tTestLines(tNormalMethodLine+2) = $ListBuild("SampleNormalMethod+1",,,tIntCodeUnit.Hash,tIntCodeUnit.MethodMap.GetAt(methodLabel)+1, "INT")
62+
Set tTestLines(tNormalMethodLine+3) = $ListBuild("SampleNormalMethod+2",,,tIntCodeUnit.Hash,tIntCodeUnit.MethodMap.GetAt(methodLabel)+2, "INT")
63+
Set tTestLines(tPythonMethodLine+2) = $ListBuild("SamplePythonMethod+1",,,tPyCodeUnit.Hash,tPyCodeUnit.MethodMap.GetAt("SamplePythonMethod")+1, "PY")
64+
Set tTestLines(tPythonMethodLine+3) = $ListBuild("SamplePythonMethod+2",,,tPyCodeUnit.Hash,tPyCodeUnit.MethodMap.GetAt("SamplePythonMethod")+2, "PY")
5265
Set tLine = ""
5366
For {
5467
Set tLine = $Order(tTestLines(tLine),1,tInfo)
@@ -57,17 +70,17 @@ Method TestCodeUnitCreation()
5770
}
5871

5972
// Overwrite with defined values, leave defaults in AssertLineHandledCorrectly for undefined values (passing byref)
60-
Kill tDescription, tExecutable, tMapped, tExpectedFromHash, tExpectedFromLine
61-
Set $ListBuild(tDescription, tExecutable, tMapped, tExpectedFromHash, tExpectedFromLine) = tInfo
62-
Do ..AssertLineHandledCorrectly(tClsCodeUnit, tLine, .tDescription, .tExecutable, .tMapped, .tExpectedFromHash, .tExpectedFromLine)
73+
Kill tDescription, tExecutable, tMapped, tExpectedFromHash, tExpectedFromLine, tType
74+
Set $ListBuild(tDescription, tExecutable, tMapped, tExpectedFromHash, tExpectedFromLine, tType) = tInfo
75+
Do ..AssertLineHandledCorrectly(tClsCodeUnit, tLine, .tDescription, .tExecutable, .tMapped, .tExpectedFromHash, .tExpectedFromLine, .tType)
6376
}
6477
} Catch e {
6578
Set tSC = e.AsStatus()
6679
}
6780
Do $$$AssertStatusOK(tSC,"No unexpected errors occurred.")
6881
}
6982

70-
Method AssertLineHandledCorrectly(pClassCodeUnit As TestCoverage.Data.CodeUnit, pLine As %Integer, pDescription As %String = {"Line "_pLine}, pExecutable As %Boolean = 1, pMapped As %Boolean = 1, pExpectedFromHash As %String = "", pExpectedFromLine As %Integer = "") As %Boolean
83+
Method AssertLineHandledCorrectly(pClassCodeUnit As TestCoverage.Data.CodeUnit, pLine As %Integer, pDescription As %String = {"Line "_pLine}, pExecutable As %Boolean = 1, pMapped As %Boolean = 1, pExpectedFromHash As %String = "", pExpectedFromLine As %Integer = "", pType As %String = "INT") As %Boolean
7184
{
7285
Set tAllGood = 1
7386
If pExecutable {
@@ -78,7 +91,7 @@ Method AssertLineHandledCorrectly(pClassCodeUnit As TestCoverage.Data.CodeUnit,
7891

7992
&sql(select count(*),FromHash,FromLine into :tCount,:tFromHash,:tFromLine
8093
from TestCoverage_Data.CodeUnitMap
81-
where ToHash = :pClassCodeUnit.Hash and ToLine = :pLine and FromHash->Type = 'INT')
94+
where ToHash = :pClassCodeUnit.Hash and ToLine = :pLine and FromHash->Type = :pType)
8295
If (SQLCODE < 0) {
8396
Throw ##class(%Exception.SQL).CreateFromSQLCODE(SQLCODE,%msg)
8497
}
@@ -123,5 +136,10 @@ ClassMethod SampleNormalMethod()
123136
Quit y
124137
}
125138

139+
ClassMethod SamplePythonMethod() [ Language = python ]
140+
{
141+
import iris
142+
return 50
126143
}
127144

145+
}

0 commit comments

Comments
 (0)