Skip to content

Commit 1e0f4e4

Browse files
committed
style: addressed Tim's comments on pr 37 (and simplified the sql statement)
1 parent d30dcdf commit 1e0f4e4

File tree

5 files changed

+28
-41
lines changed

5 files changed

+28
-41
lines changed

cls/TestCoverage/Data/CodeUnit.cls

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -251,38 +251,24 @@ Method UpdatePyExecutableLines(pName As %String, ByRef pPyCodeUnit) As %Status
251251

252252
Set tFromHash = pPyCodeUnit.Hash
253253
Set tToHash = ..Hash
254-
255-
&sql(
256-
DECLARE C1 CURSOR FOR
257-
SELECT map.ToLine
258-
INTO :hToLine
259-
FROM TestCoverage_Data.CodeUnitMap map
260-
JOIN TestCoverage_Data.CodeUnit fromCodeUnit
261-
ON map.FromHash = fromCodeUnit.Hash
262-
JOIN TestCoverage_Data.CodeUnit toCodeUnit
263-
ON map.ToHash = toCodeUnit.Hash
264-
AND fromCodeUnit.Hash = :tFromHash
265-
AND toCodeUnit.Hash = :tToHash
266-
WHERE TestCoverage.BIT_VALUE(fromCodeUnit.ExecutableLines,map.FromLine) <> 0
267-
)
268-
&sql(OPEN C1)
269-
If (SQLCODE < 0) {
270-
Throw ##class(%Exception.SQL).CreateFromSQLCODE(SQLCODE,%msg)
254+
set sql = "SELECT map.ToLine FROM TestCoverage_Data.CodeUnitMap map " _
255+
"JOIN TestCoverage_Data.CodeUnit fromCodeUnit " _
256+
"ON fromCodeUnit.Hash = map.FromHash " _
257+
"WHERE map.FromHash = ? " _
258+
"AND map.ToHash = ? " _
259+
"AND TestCoverage.BIT_VALUE(fromCodeUnit.ExecutableLines,map.FromLine) <> 0"
260+
261+
set resultSet = ##class(%SQL.Statement).%ExecDirect(, sql, tFromHash, tToHash)
262+
If (resultSet.%SQLCODE < 0) {
263+
Throw ##class(%Exception.SQL).CreateFromSQLCODE(resultSet.%SQLCODE, resultSet.%Message)
271264
}
272-
For {
273-
&SQL(FETCH C1)
274-
If (SQLCODE < 0) {
275-
Throw ##class(%Exception.SQL).CreateFromSQLCODE(SQLCODE,%msg)
276-
} ElseIf (SQLCODE) {
277-
Quit
278-
}
279-
// Process the fetched rows
280-
// hToLine contains the line number in the .cls file corresponding to executable lines in the .py file
265+
while resultSet.%Next(.tSC) {
266+
$$$ThrowOnError(tSC)
267+
Set hToLine = resultSet.%GetData(1)
281268
Set $Bit(tBitString, hToLine) = 1
282269
}
283-
&sql(CLOSE C1)
284-
If (SQLCODE < 0) {
285-
Throw ##class(%Exception.SQL).CreateFromSQLCODE(SQLCODE,%msg)
270+
If (resultSet.%SQLCODE < 0) {
271+
Throw ##class(%Exception.SQL).CreateFromSQLCODE(resultSet.%SQLCODE, resultSet.%Message)
286272
}
287273
}
288274
Set ..ExecutableLines = $BITLOGIC(..ExecutableLines | tBitString)
@@ -362,8 +348,6 @@ Method UpdateSourceMap(pSourceNamespace As %String, ByRef pCache) As %Status
362348
Set tMethodName = tMethod
363349
Set tFullMap(tMethodStart) = $lb("CLS", tClass,tMethodName, -1, -1) ; -1 because the class
364350
; definition doesn't have the +1 offset from the {
365-
366-
Do ..MethodMap.GetNext(.tMethod)
367351
For i = tMethodStart+1:1:tMethodEnd {
368352
Set tClassLineNum = i-tMethodStart
369353
Set tFullMap(i) = $lb("CLS", tClass,tMethodName, tClassLineNum, tClassLineNum)
@@ -375,6 +359,7 @@ Method UpdateSourceMap(pSourceNamespace As %String, ByRef pCache) As %Status
375359
Set tSC = $$$ERROR($$$GeneralError,"Compiled .py code doesn't match .CLS python code ")
376360
}
377361
}
362+
Do ..MethodMap.GetNext(.tMethod)
378363
}
379364
}
380365

cls/TestCoverage/Data/Coverage.cls

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
Include TestCoverage
2+
13
IncludeGenerator TestCoverage
24

35
Class TestCoverage.Data.Coverage Extends %Persistent
@@ -102,9 +104,9 @@ ClassMethod StoreIntCoverage(pRun As %Integer, pTestPath As %String, pName As %S
102104
Else { // If pType = "PY"
103105
//^IRIS.TEMP.TestCoveragePy(ClassName) contains the number of covered lines in this class
104106
//^IRIS.TEMP.TestCoveragePy(ClassName, i) in increasing order contain the line numbers for the covered lines
105-
if $Data(^IRIS.TEMP.TestCoveragePY(pName)) {
106-
for i = 1:1:(^IRIS.TEMP.TestCoveragePY(pName)-1) {
107-
Set tLineNumber = ^IRIS.TEMP.TestCoveragePY(pName, i)
107+
if $Data($$$PyMonitorResults(pName)) {
108+
for i = 1:1:($$$PyMonitorResults(pName)-1) {
109+
Set tLineNumber = $$$PyMonitorResults(pName, i)
108110
Set $Bit(tCoveredLines, tLineNumber) = 1
109111
}
110112
}

cls/TestCoverage/Utils.cls

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,9 @@ ClassMethod GetClassLineExecutableFlags(pClassName As %String, ByRef pDocumentTe
431431

432432
ClassMethod CodeArrayToList(ByRef pCodeArray, Output pDocumentText As %List)
433433
{
434-
set pDocumentText = $lb()
435-
for i=1:1:pCodeArray(0) {
436-
set $list(pDocumentText, i) = pCodeArray(i)
434+
set pDocumentText = ""
435+
for i=1:1:$get(pCodeArray(0)) {
436+
set pDocumentText = pDocumentText _ $ListBuild(pCodeArray(i))
437437
}
438438
quit
439439
}

cls/TestCoverage/Utils/LineByLineMonitor.cls

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Include %occErrors
1+
Include (%occErrors, TestCoverage)
22

33
/// Wrapper around %Monitor.System.LineByLine to ensure that the monitor is stopped when it should be, and also
44
/// to wrap the decision about whether to stop/start the monitor or to just clear counters.
@@ -70,8 +70,7 @@ ClassMethod PyStartWithScope(pCoverageClasses As %List) [ Language = python ]
7070
# extracts the line number
7171
line_no = frame.f_lineno
7272
if class_name in tCoverageClasses and line_no != 1: # if this is in a covered class
73-
# print(f"A {event} encountered in {func_name}() in class {class_name} at line number {line_no}")
74-
tGlob = iris.gref('^IRIS.TEMP.TestCoveragePY')
73+
tGlob = iris.gref('^IRIS.TEMP.TestCoveragePY') # python doesn't have macros -- this is $$$PyMonitorResults
7574
curId = tGlob.get([class_name])
7675
if not curId:
7776
tGlob[class_name] = 1
@@ -84,7 +83,7 @@ ClassMethod PyStartWithScope(pCoverageClasses As %List) [ Language = python ]
8483

8584
ClassMethod PyClearCounters()
8685
{
87-
Kill ^IRIS.TEMP.TestCoveragePY
86+
Kill $$$PyMonitorResults
8887
}
8988

9089
ClassMethod PyStop() [ Language = python ]

inc/TestCoverage.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ ROUTINE TestCoverage [Type=INC]
33
#define StopTimer If (..Display["log") { Write ($zh-tStartTime)," seconds" }
44
#define METRICS "RtnLine","Time","TotalTime"
55
#define TestPathAllTests "all tests"
6+
#define PyMonitorResults ^IRIS.TEMP.TestCoveragePY

0 commit comments

Comments
 (0)