Skip to content

Commit d490651

Browse files
committed
fixed bug with cancel button and in ArgInfoCollector
1 parent 6ed0b4f commit d490651

File tree

14 files changed

+43
-44
lines changed

14 files changed

+43
-44
lines changed

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/python/PythonDialogProcessor.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ object PythonDialogProcessor {
124124

125125
val testCaseGenerator = PythonTestCaseGenerator.apply {
126126
init(
127-
testSourceRoot,
128127
model.directoriesForSysPath,
129128
model.moduleToImport,
130129
pythonPath,

utbot-python/types/find_and_check_types.py renamed to utbot-python/our_scripts/find_and_check_types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import types
1+
import our_scripts
22
from typing import Optional
33

44
import astor.code_gen
@@ -15,7 +15,7 @@ def find_all_classes_in_file(filename: str, prefix: str = '') -> list[str]:
1515
]
1616

1717

18-
def find_module_types(module_name: types.ModuleType) -> list[str]:
18+
def find_module_types(module_name: our_scripts.ModuleType) -> list[str]:
1919
def eval_name(name, module_name):
2020
return name if 'builtin' in module_name.__name__ else f'{module_name.__name__}.{name}'
2121

@@ -29,7 +29,7 @@ def eval_name(name, module_name):
2929
def find_import_types():
3030
return [
3131
(name, val) for name, val in globals().items()
32-
if isinstance(val, types.ModuleType)
32+
if isinstance(val, our_scripts.ModuleType)
3333
]
3434

3535

File renamed without changes.

utbot-python/src/main/kotlin/org/utbot/python/PythonEngine.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import java.io.File
1717

1818
class PythonEngine(
1919
private val methodUnderTest: PythonMethod,
20-
private val testSourceRoot: String,
2120
private val directoriesForSysPath: List<String>,
2221
private val moduleToImport: String,
2322
private val pythonPath: String,
@@ -39,13 +38,11 @@ class PythonEngine(
3938
parameterNameMap = { index -> methodUnderTest.arguments.getOrNull(index)?.name }
4039
}
4140

42-
var testsGenerated = 0
4341
fuzz(methodUnderTestDescription, concreteTypesModelProvider).forEach { values ->
4442
val modelList = values.map { it.model }
4543
val evalResult = PythonEvaluation.evaluate(
4644
methodUnderTest,
4745
modelList,
48-
testSourceRoot,
4946
directoriesForSysPath,
5047
moduleToImport,
5148
pythonPath
@@ -90,10 +87,6 @@ class PythonEngine(
9087
)
9188
)
9289
}
93-
94-
testsGenerated += 1
95-
if (testsGenerated == 100)
96-
return@sequence
9790
}
9891
}
9992
}

utbot-python/src/main/kotlin/org/utbot/python/PythonEvaluation.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import org.utbot.framework.plugin.api.UtModel
55
import org.utbot.python.code.PythonCodeGenerator
66
import org.utbot.python.utils.FileManager
77
import org.utbot.python.utils.runCommand
8-
import java.io.File
98

109

1110
sealed class EvaluationResult
@@ -26,7 +25,6 @@ object PythonEvaluation {
2625
fun evaluate(
2726
method: PythonMethod,
2827
methodArguments: List<UtModel>,
29-
testSourceRoot: String,
3028
directoriesForSysPath: List<String>,
3129
moduleToImport: String,
3230
pythonPath: String

utbot-python/src/main/kotlin/org/utbot/python/PythonTestCaseGenerator.kt

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,23 @@ import org.utbot.python.utils.annotationToClassId
1010
import java.io.File
1111

1212
object PythonTestCaseGenerator {
13-
lateinit var testSourceRoot: String
14-
lateinit var directoriesForSysPath: List<String>
15-
lateinit var moduleToImport: String
16-
lateinit var pythonPath: String
17-
lateinit var projectRoot: String
18-
lateinit var fileOfMethod: String
19-
lateinit var isCancelled: () -> Boolean
13+
private lateinit var directoriesForSysPath: List<String>
14+
private lateinit var moduleToImport: String
15+
private lateinit var pythonPath: String
16+
private lateinit var projectRoot: String
17+
private lateinit var fileOfMethod: String
18+
private lateinit var isCancelled: () -> Boolean
19+
20+
private const val maxTestCount = 30
2021

2122
fun init(
22-
testSourceRoot: String,
2323
directoriesForSysPath: List<String>,
2424
moduleToImport: String,
2525
pythonPath: String,
2626
projectRoot: String,
2727
fileOfMethod: String,
2828
isCancelled: () -> Boolean
2929
) {
30-
this.testSourceRoot = testSourceRoot
3130
this.directoriesForSysPath = directoriesForSysPath
3231
this.moduleToImport = moduleToImport
3332
this.pythonPath = pythonPath
@@ -52,27 +51,36 @@ object PythonTestCaseGenerator {
5251
val executions = mutableListOf<PythonExecution>()
5352
val errors = mutableListOf<PythonError>()
5453

55-
annotationSequence.forEach typeSelection@{ annotations ->
56-
if (isCancelled())
57-
return@typeSelection
58-
59-
val engine = PythonEngine(
60-
method,
61-
testSourceRoot,
62-
directoriesForSysPath,
63-
moduleToImport,
64-
pythonPath,
65-
argInfoCollector.getConstants(),
66-
annotations
67-
)
54+
var testsGenerated = 0
6855

69-
engine.fuzzing().forEach fuzzing@{
56+
run breaking@ {
57+
annotationSequence.forEach { annotations ->
7058
if (isCancelled())
71-
return@fuzzing
72-
when (it) {
73-
is PythonExecution -> executions += it
74-
is PythonError -> errors += it
59+
return@breaking
60+
61+
val engine = PythonEngine(
62+
method,
63+
directoriesForSysPath,
64+
moduleToImport,
65+
pythonPath,
66+
argInfoCollector.getConstants(),
67+
annotations
68+
)
69+
70+
engine.fuzzing().forEach {
71+
if (isCancelled())
72+
return@breaking
73+
when (it) {
74+
is PythonExecution -> executions += it
75+
is PythonError -> errors += it
76+
}
77+
testsGenerated += 1
78+
if (testsGenerated >= maxTestCount)
79+
return@breaking
7580
}
81+
82+
if (testsGenerated >= maxTestCount)
83+
return@breaking
7684
}
7785
}
7886

@@ -100,7 +108,6 @@ object PythonTestCaseGenerator {
100108
argInfoCollector,
101109
method,
102110
existingAnnotations,
103-
testSourceRoot,
104111
moduleToImport,
105112
directoriesForSysPath,
106113
pythonPath,
@@ -154,7 +161,6 @@ object PythonTestCaseGenerator {
154161
argInfoCollector: ArgInfoCollector,
155162
methodUnderTest: PythonMethod,
156163
existingAnnotations: Map<String, String>,
157-
testSourceRoot: String,
158164
moduleToImport: String,
159165
directoriesForSysPath: List<String>,
160166
pythonPath: String,

utbot-python/src/main/kotlin/org/utbot/python/code/ArgInfoCollector.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import io.github.danielnaczo.python3parser.model.expr.operators.binaryops.compar
1313
import io.github.danielnaczo.python3parser.model.expr.atoms.Name
1414
import io.github.danielnaczo.python3parser.model.expr.atoms.Num
1515
import io.github.danielnaczo.python3parser.model.expr.atoms.Str
16+
import io.github.danielnaczo.python3parser.model.expr.atoms.trailers.arguments.Arguments
1617
import io.github.danielnaczo.python3parser.model.expr.operators.Operator
1718
import io.github.danielnaczo.python3parser.model.expr.operators.binaryops.*
1819
import io.github.danielnaczo.python3parser.model.expr.operators.binaryops.boolops.Or
@@ -106,7 +107,7 @@ class ArgInfoCollector(val method: PythonMethod, val argumentTypes: List<ClassId
106107
val names: List<Parser<(String) -> A, A, N>> = paramNames.map { paramName ->
107108
map0(refl(name(equal(paramName))), paramName)
108109
}
109-
return names.reduce { acc, elem -> or(acc, elem) }
110+
return names.fold(reject()) { acc, elem -> or(acc, elem) }
110111
}
111112

112113
private fun getStr(str: String): String {
@@ -183,11 +184,13 @@ class ArgInfoCollector(val method: PythonMethod, val argumentTypes: List<ClassId
183184
paramNames.map { paramName ->
184185
map0(anyIndexed(refl(name(equal(paramName)))), paramName)
185186
}
187+
val argPat: Parser<(String) -> (Int) -> ResFuncArg, ResFuncArg, List<Expression>> =
188+
argNamePatterns.fold(reject()) { acc, elem -> or(acc, elem) }
186189
val pat = functionCallWithPrefix(
187190
fprefix = drop(),
188191
fid = apply(),
189192
farguments = arguments(
190-
fargs = argNamePatterns.reduce { acc, elem -> or(acc, elem) },
193+
fargs = argPat,
191194
drop(), drop(), drop()
192195
)
193196
)

0 commit comments

Comments
 (0)