@@ -163,11 +163,6 @@ ClassMethod GetCurrentByName(pInternalName As %String, pSourceNamespace As %Stri
163
163
Set $Bit (tMethodMask ,j ) = 1
164
164
}
165
165
Set tMethodSignature = $list (pDocumentText , tStartLine )
166
- Set tSubUnit = ##class (TestCoverage.Data.CodeSubUnit.Method ).%New ()
167
- Set tSubUnit .Name = tMethod
168
- Set tSubUnit .DisplaySignature = tMethodSignature
169
- Set tSubUnit .Mask = tMethodMask
170
- Do pCodeUnit .SubUnits .Insert (tSubUnit )
171
166
}
172
167
}
173
168
Else {
@@ -194,6 +189,8 @@ ClassMethod GetCurrentByName(pInternalName As %String, pSourceNamespace As %Stri
194
189
Set tSubUnit .Name = tMethod
195
190
Set tSubUnit .DisplaySignature = tMethodSignature
196
191
Set tSubUnit .Mask = tMethodMask
192
+ set NormalizedSignature = $zconvert ($zstrip (tMethodSignature , " *W" ), " l" )
193
+ set tSubUnit .IsPythonMethod = (NormalizedSignature [ " [language=python]" )
197
194
Do pCodeUnit .SubUnits .Insert (tSubUnit )
198
195
Set tMethod = " "
199
196
Set tMethodSignature = " "
@@ -506,15 +503,28 @@ Method UpdateComplexity() As %Status
506
503
If (..Type '= " CLS" ) {
507
504
Quit
508
505
}
509
-
506
+
507
+ // python methods
508
+ If (##class (TestCoverage.Manager ).HasPython (..Name )) {
509
+ do ##class (TestCoverage.Data.CodeUnit ).GetCurrentByName (..Name _ " .PY" , , .pPyCodeUnit , )
510
+ set tDocumentText = pPyCodeUnit .Lines .Serialize ()
511
+ set tMethodComplexities = ..GetPythonComplexities (tDocumentText )
512
+ }
513
+
510
514
Set tKey = " "
511
515
For {
512
516
Set tSubUnit = ..SubUnits .GetNext (.tKey )
513
517
If (tKey = " " ) {
514
518
Quit
515
519
}
516
- $$$ThrowOnError(tSubUnit .UpdateComplexity ())
520
+ If (tSubUnit .IsPythonMethod ) {
521
+ set tSubUnit .Complexity = tMethodComplexities ." __getitem__" (tSubUnit .Name )
522
+ $$$ThrowOnError(tSubUnit .%Save (0 ))
523
+ } Else {
524
+ $$$ThrowOnError(tSubUnit .UpdateComplexity ())
525
+ }
517
526
}
527
+
518
528
519
529
$$$ThrowOnError(..%Save ())
520
530
} Catch e {
@@ -523,6 +533,20 @@ Method UpdateComplexity() As %Status
523
533
Quit tSC
524
534
}
525
535
536
+ ClassMethod GetPythonComplexities (pDocumentText ) [ Language = python ]
537
+ {
538
+ from radon .complexity import cc _visit
539
+ import iris
540
+ source _lines = iris .cls ('%SYS .Python ').ToList (pDocumentText )
541
+ source _code = " \n" .join (source _lines )
542
+ visitor = cc _visit (source _code )
543
+ class _info = visitor [0 ]
544
+ method _complexities = {}
545
+ for method in class _info .methods :
546
+ method _complexities [method .name ] = method .complexity
547
+ return method _complexities
548
+ }
549
+
526
550
Method GetMethodOffset (pAbsoluteLine As %Integer , Output pMethod As %String , Output pOffset As %Integer )
527
551
{
528
552
}
0 commit comments