Skip to content

Commit b0f215b

Browse files
authored
Merge pull request #53 from intersystems/UnnamedClasses
Unnamed classes
2 parents 5e85d48 + 3e95e0a commit b0f215b

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [4.0.3] - Unreleased
9+
10+
### Changed
11+
- #52: Method mapping code now doesn't use AST's endline_no property to support older python versions
12+
- #53: Ignore traced commands from code without a class name
13+
814
## [4.0.2] - 2024-08-16
915

1016
### Fixed

cls/TestCoverage/Utils.cls

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,8 @@ ClassMethod GetPythonMethodMapping(pDocumentText) [ Language = python ]
451451
import iris
452452
import ast
453453
source_lines = iris.cls('%SYS.Python').ToList(pDocumentText)
454-
source_lines = [line + "\n" for line in source_lines] # contains a list of each line of the source code
455454

456-
source = ''.join(source_lines)
455+
source = '\n'.join(source_lines)
457456
tree = ast.parse(source)
458457
line_function_map = [None] * (len(source_lines)+2)
459458
method_map = {} # dictionary from the method name to its start and ending line number
@@ -473,22 +472,21 @@ ClassMethod GetPythonMethodMapping(pDocumentText) [ Language = python ]
473472
def visit_FunctionDef(self, node):
474473
if self.outermost_function is None:
475474
self.outermost_function = node.name
476-
method_map[node.name] = (node.lineno-1, node.end_lineno-1)
475+
start_line = node.lineno
476+
end_line = self.get_end_line(node)
477+
method_map[node.name] = (start_line, end_line)
477478

478479
self.current_function = node.name
479-
for lineno in range(node.lineno, node.end_lineno + 1):
480+
for lineno in range(node.lineno, self.get_end_line(node) + 1):
480481
line_function_map[lineno-1] = self.outermost_function
481482

482483
self.generic_visit(node)
483484
self.current_function = None
484485
if self.outermost_function == node.name:
485486
self.outermost_function = None
486-
487-
# preprocessing the ending line number for each function
488-
tree_with_line_numbers = ast.increment_lineno(tree, n=1)
489-
for node in ast.walk(tree_with_line_numbers):
490-
if isinstance(node, ast.FunctionDef):
491-
node.end_lineno = node.body[-1].end_lineno
487+
@staticmethod
488+
def get_end_line(node):
489+
return max(child.lineno for child in ast.walk(node) if hasattr(child, 'lineno'))
492490

493491
FunctionMapper().visit(tree)
494492
return (line_function_map, method_map)

cls/TestCoverage/Utils/LineByLineMonitor.cls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ ClassMethod PyStartWithScope(pCoverageClasses As %List) [ Language = python ]
7676
# extracts frame code
7777
code = frame.f_code
7878
# extracts calling function name and the class that the function is in
79-
class_name = frame.f_globals['__name__']
79+
class_name = frame.f_globals.get('__name__', None) # Use get to avoid KeyError
8080
# extracts the line number
8181
line_no = frame.f_lineno
82-
if class_name in tCoverageClasses and line_no > 1: # if this is in a covered class
82+
if class_name and class_name in tCoverageClasses and line_no > 1: # if this is in a covered class
8383
tGlob = iris.gref('^IRIS.Temp.TestCoveragePY') # python doesn't have macros -- this is $$$PyMonitorResults
8484
# $$$PyMonitorResults(classname, linenumber) = the number of times that linenumber in that class was covered
8585

module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Export generator="Cache" version="25">
33
<Document name="TestCoverage.ZPM"><Module>
44
<Name>TestCoverage</Name>
5-
<Version>4.0.2</Version>
5+
<Version>4.0.3</Version>
66
<Description>Run your typical ObjectScript %UnitTest tests and see which lines of your code are executed. Includes Cobertura-style reporting for use in continuous integration tools.</Description>
77
<Packaging>module</Packaging>
88
<Resource Name="TestCoverage.PKG" Directory="cls" />

0 commit comments

Comments
 (0)