Skip to content

Commit f8b4f68

Browse files
committed
added debug logging
1 parent 14f3e43 commit f8b4f68

5 files changed

Lines changed: 25 additions & 5 deletions

File tree

utbot-cli/src/main/kotlin/org/utbot/cli/python/PythonGenerateTestsCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class PythonGenerateTestsCommand: CliktCommand(
9191
if (module != null)
9292
return Success(module)
9393
}
94-
return Fail("Couldn't find path for $sourceFile in --python-path option. Please, specify it.")
94+
return Fail("Couldn't find path for $sourceFile in --sys-path option. Please, specify it.")
9595
}
9696

9797
private val forbiddenMethods = listOf("__init__", "__new__")

utbot-python/samples/general.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ def k(x: typing.Any):
148148

149149
# interesting case with sets
150150
def set_small_data_labels(dates):
151+
if len(dates) == 0:
152+
return None
151153
if all(x.hour == 0 and x.minute == 0 for x in dates):
152154
return [x.strftime('%Y-%m-%d') for x in dates]
153155
else:

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ object PythonTestCaseGenerator {
6262
initialArgumentTypes[0] = NormalizedPythonAnnotation(method.containingPythonClassId!!.name)
6363
}
6464

65+
logger.debug("Collecting hints about arguments")
6566
val argInfoCollector = ArgInfoCollector(method, initialArgumentTypes)
67+
logger.debug("Collected.")
6668
val annotationSequence = getAnnotations(method, initialArgumentTypes, argInfoCollector, isCancelled)
6769

6870
val executions = mutableListOf<UtExecution>()
@@ -75,6 +77,10 @@ object PythonTestCaseGenerator {
7577
if (isCancelled())
7678
return@breaking
7779

80+
logger.debug("Found annotations: ${
81+
annotations.map { "${it.key}: ${it.value}" }.joinToString(" ")
82+
}")
83+
7884
val engine = PythonEngine(
7985
method,
8086
directoriesForSysPath,

utbot-python/src/main/kotlin/org/utbot/python/typing/FindAnnotations.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.utbot.python.typing
22

3+
import mu.KotlinLogging
34
import org.utbot.framework.plugin.api.NormalizedPythonAnnotation
45
import org.utbot.framework.plugin.api.PythonClassId
56
import org.utbot.framework.plugin.api.pythonAnyClassId
@@ -8,8 +9,12 @@ import org.utbot.python.code.ArgInfoCollector
89
import org.utbot.python.utils.*
910
import java.io.File
1011

12+
private val logger = KotlinLogging.logger {}
13+
1114
object AnnotationFinder {
1215

16+
private const val MAX_CANDIDATES_FOR_PARAM = 100
17+
1318
fun findAnnotations(
1419
argInfoCollector: ArgInfoCollector,
1520
methodUnderTest: PythonMethod,
@@ -22,7 +27,9 @@ object AnnotationFinder {
2227
storageForMypyMessages: MutableList<MypyAnnotations.MypyReportLine>
2328
): Sequence<Map<String, NormalizedPythonAnnotation>> {
2429

30+
logger.debug("Finding candidates...")
2531
val annotationsToCheck = findTypeCandidates(argInfoCollector, existingAnnotations)
32+
logger.debug("Found")
2633

2734
return MypyAnnotations.getCheckedByMypyAnnotations(
2835
methodUnderTest,
@@ -108,7 +115,7 @@ object AnnotationFinder {
108115
increaseForGenerics(candidates)
109116
}
110117
increaseForProjectClasses(candidates)
111-
return candidatesMapToRating(candidates)
118+
return candidatesMapToRating(candidates).take(MAX_CANDIDATES_FOR_PARAM)
112119
}
113120

114121
private fun getGeneralTypeRating(
@@ -133,11 +140,9 @@ object AnnotationFinder {
133140
foundCandidates.forEach { increaseValue(candidates, it, add) }
134141
}
135142
increaseForProjectClasses(candidates)
136-
return candidatesMapToRating(candidates)
143+
return candidatesMapToRating(candidates).take(MAX_CANDIDATES_FOR_PARAM / 2)
137144
}
138145

139-
private const val MAX_CANDIDATES_FOR_PARAM = 100
140-
141146
private fun getArgCandidates(
142147
generalTypeRating: List<NormalizedPythonAnnotation>,
143148
argStorages: List<ArgInfoCollector.Hint> = emptyList(),

utbot-python/src/main/kotlin/org/utbot/python/typing/MypyAnnotations.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.utbot.python.typing
22

3+
import mu.KotlinLogging
34
import org.utbot.framework.plugin.api.NormalizedPythonAnnotation
45
import org.utbot.python.utils.Cleaner
56
import org.utbot.python.utils.FileManager
@@ -10,6 +11,7 @@ import org.utbot.python.utils.getLineOfFunction
1011
import org.utbot.python.utils.runCommand
1112
import java.io.File
1213

14+
private val logger = KotlinLogging.logger {}
1315

1416
object MypyAnnotations {
1517
const val TEMPORARY_MYPY_FILE = "<TEMPORARY MYPY FILE>"
@@ -41,6 +43,7 @@ object MypyAnnotations {
4143
val configFile = setConfigFile(directoriesForSysPath)
4244
Cleaner.addFunction { stopMypy(pythonPath) }
4345

46+
logger.debug("First mypy run")
4447
val defaultOutputAsString = mypyCheck(pythonPath, fileWithCode, configFile)
4548
val defaultErrorsAndNotes = getErrorsAndNotes(defaultOutputAsString, codeWithoutAnnotations, fileWithCode)
4649

@@ -64,6 +67,10 @@ object MypyAnnotations {
6467
return@sequence
6568
}
6669

70+
logger.debug("Checking annotations: ${
71+
generatedAnnotations.joinToString { "${it.first}: ${it.second}" }
72+
}")
73+
6774
val annotationMap = generatedAnnotations.toMap()
6875
val codeWithAnnotations = generateMypyCheckCode(
6976
method,

0 commit comments

Comments
 (0)