Skip to content

Commit fc391da

Browse files
committed
Remove instructions minimization
1 parent 4a34655 commit fc391da

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

utbot-python-executor/src/main/python/utbot_executor/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "utbot-executor"
3-
version = "1.9.9"
3+
version = "1.9.10"
44
description = ""
55
authors = ["Vyacheslav Tamarin <vyacheslav.tamarin@yandex.ru>"]
66
readme = "README.md"

utbot-python-executor/src/main/python/utbot_executor/utbot_executor/executor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def _run_calculate_function_value(
280280

281281
logging.debug("Coverage: %s", __tracer.counts)
282282
logging.debug("Fullpath: %s", fullpath)
283-
__stmts_with_def = [UtInstruction(__start, 0, True)] + list(__tracer.counts.keys())
283+
__stmts_with_def = [UtInstruction(__start, 0, True)] + __tracer.instructions
284284
__missed_filtered = [x for x in __all_code_stmts if x not in __stmts_with_def]
285285
logging.debug("Covered lines: %s", __stmts_with_def)
286286
logging.debug("Missed lines: %s", __missed_filtered)

utbot-python-executor/src/main/python/utbot_executor/utbot_executor/ut_tracer.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import dis
2-
import inspect
31
import logging
42
import os
53
import pathlib
@@ -19,7 +17,14 @@ def _modname(path):
1917

2018

2119
class UtCoverageSender:
22-
def __init__(self, coverage_id: str, host: str, port: int, use_thread: bool = False, send_coverage: bool = True):
20+
def __init__(
21+
self,
22+
coverage_id: str,
23+
host: str,
24+
port: int,
25+
use_thread: bool = False,
26+
send_coverage: bool = True,
27+
):
2328
self.coverage_id = coverage_id
2429
self.host = host
2530
self.port = port
@@ -59,7 +64,9 @@ def put_message(self, key: str):
5964

6065
class PureSender(UtCoverageSender):
6166
def __init__(self):
62-
super().__init__("000000", "localhost", 0, use_thread=False, send_coverage=False)
67+
super().__init__(
68+
"000000", "localhost", 0, use_thread=False, send_coverage=False
69+
)
6370

6471

6572
class UtTracer:
@@ -72,6 +79,7 @@ def __init__(
7279
):
7380
self.tested_file = tested_file
7481
self.counts: dict[UtInstruction, int] = {}
82+
self.instructions: list[UtInstruction] = []
7583
self.localtrace = self.localtrace_count
7684
self.globaltrace = self.globaltrace_lt
7785
self.ignore_dirs = ignore_dirs
@@ -88,10 +96,6 @@ def runfunc(self, func, /, *args, **kw):
8896
sys.settrace(None)
8997
return result
9098

91-
def coverage(self, filename: str) -> typing.List[int]:
92-
filename = _modname(filename)
93-
return [line for file, line in self.counts.keys() if file == filename]
94-
9599
def localtrace_count(self, frame, why, arg):
96100
filename = frame.f_code.co_filename
97101
lineno = frame.f_lineno
@@ -108,15 +112,18 @@ def localtrace_count(self, frame, why, arg):
108112
except Exception:
109113
pass
110114
self.counts[key] = self.counts.get(key, 0) + 1
115+
self.instructions.append(key)
111116
return self.localtrace
112117

113118
def globaltrace_lt(self, frame, why, arg):
114-
if why == 'call':
119+
if why == "call":
115120
if self.mode == TraceMode.Instructions:
116121
frame.f_trace_opcodes = True
117122
frame.f_trace_lines = False
118-
filename = frame.f_globals.get('__file__', None)
119-
if filename and all(not filename.startswith(d + os.sep) for d in self.ignore_dirs):
123+
filename = frame.f_globals.get("__file__", None)
124+
if filename and all(
125+
not filename.startswith(d + os.sep) for d in self.ignore_dirs
126+
):
120127
modulename = _modname(filename)
121128
if modulename is not None:
122129
return self.localtrace
@@ -140,10 +147,11 @@ def f(x):
140147
def g(x):
141148
xs = [[j for j in range(i)] for i in range(10)]
142149
return x * 2
150+
143151
return g1(x) * g(x) + 2
144152

145153

146154
if __name__ == "__main__":
147155
tracer = UtTracer(pathlib.Path(__file__), [], PureSender())
148156
tracer.runfunc(f, 2)
149-
print(tracer.counts)
157+
print(tracer.counts)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.9.9
1+
1.9.10

0 commit comments

Comments
 (0)