Skip to content

Commit 6dd5f5e

Browse files
committed
Add cli arguments
1 parent e0f3332 commit 6dd5f5e

7 files changed

Lines changed: 59 additions & 17 deletions

File tree

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import org.utbot.python.PythonTestSet
1616
import org.utbot.python.utils.RequirementsInstaller
1717
import org.utbot.python.TestFileInformation
1818
import org.utbot.python.code.PythonCode
19+
import org.utbot.python.evaluation.utils.PythonCoverageMode
20+
import org.utbot.python.evaluation.utils.toPythonCoverageMode
1921
import org.utbot.python.framework.api.python.PythonClassId
2022
import org.utbot.python.framework.codegen.model.Pytest
2123
import org.utbot.python.framework.codegen.model.Unittest
@@ -117,6 +119,13 @@ class PythonGenerateTestsCommand : CliktCommand(
117119
private val doNotGenerateRegressionSuite by option("--do-not-generate-regression-suite", help = "Do not generate regression test suite")
118120
.flag(default = false)
119121

122+
private val coverageMeasureMode by option("--coverage-measure-mode", help = "Use LINES or INSTRUCTIONS for coverage measurement")
123+
.choice("INSTRUCTIONS", "LINES")
124+
.default("INSTRUCTIONS")
125+
126+
private val doNotSendCoverageContinuously by option("--do-not-send-coverage-continuously", help = "")
127+
.flag(default = false)
128+
120129
private val testFramework: TestFramework
121130
get() =
122131
when (testFrameworkAsString) {
@@ -252,7 +261,9 @@ class PythonGenerateTestsCommand : CliktCommand(
252261
testSourceRootPath = Paths.get(output.toAbsolutePath()).parent.toAbsolutePath(),
253262
withMinimization = !doNotMinimize,
254263
isCanceled = { false },
255-
runtimeExceptionTestsBehaviour = RuntimeExceptionTestsBehaviour.valueOf(runtimeExceptionTestsBehaviour)
264+
runtimeExceptionTestsBehaviour = RuntimeExceptionTestsBehaviour.valueOf(runtimeExceptionTestsBehaviour),
265+
coverageMeasureMode = coverageMeasureMode.toPythonCoverageMode() ?: PythonCoverageMode.Instructions,
266+
sendCoverageContinuously = !doNotSendCoverageContinuously
256267
)
257268

258269
val processor = PythonCliProcessor(

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import org.utbot.python.evaluation.*
1212
import org.utbot.python.evaluation.serialization.MemoryDump
1313
import org.utbot.python.evaluation.serialization.toPythonTree
1414
import org.utbot.python.evaluation.utils.CoverageIdGenerator
15-
import org.utbot.python.evaluation.utils.PyInstruction
16-
import org.utbot.python.evaluation.utils.coveredLinesToInstructions
15+
import org.utbot.python.evaluation.utils.PythonCoverageMode
1716
import org.utbot.python.evaluation.utils.makeInstructions
1817
import org.utbot.python.framework.api.python.PythonTree
1918
import org.utbot.python.framework.api.python.PythonTreeModel
@@ -44,6 +43,8 @@ class PythonEngine(
4443
private val fuzzedConcreteValues: List<PythonFuzzedConcreteValue>,
4544
private val timeoutForRun: Long,
4645
private val pythonTypeStorage: PythonTypeHintsStorage,
46+
private val coverageMode: PythonCoverageMode = PythonCoverageMode.Instructions,
47+
private val sendCoverageContinuously: Boolean = true,
4748
) {
4849

4950
private val cache = EvaluationCache()
@@ -302,6 +303,8 @@ class PythonEngine(
302303
serverSocket,
303304
pythonPath,
304305
until,
306+
coverageMode,
307+
sendCoverageContinuously,
305308
) { constructEvaluationInput(it) }
306309
} catch (_: TimeoutException) {
307310
return@flow

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.utbot.framework.minimization.minimizeExecutions
66
import org.utbot.framework.plugin.api.UtError
77
import org.utbot.framework.plugin.api.UtExecution
88
import org.utbot.framework.plugin.api.UtExecutionSuccess
9+
import org.utbot.python.evaluation.utils.PythonCoverageMode
910
import org.utbot.python.framework.api.python.PythonUtExecution
1011
import org.utbot.python.framework.api.python.util.pythonStrClassId
1112
import org.utbot.python.fuzzing.*
@@ -40,7 +41,9 @@ class PythonTestCaseGenerator(
4041
private val timeoutForRun: Long = 0,
4142
private val sourceFileContent: String,
4243
private val mypyStorage: MypyInfoBuild,
43-
private val mypyReportLine: List<MypyReportLine>
44+
private val mypyReportLine: List<MypyReportLine>,
45+
private val coverageMode: PythonCoverageMode = PythonCoverageMode.Instructions,
46+
private val sendCoverageContinuously: Boolean = true,
4447
) {
4548

4649
private val storageForMypyMessages: MutableList<MypyReportLine> = mutableListOf()
@@ -153,7 +156,9 @@ class PythonTestCaseGenerator(
153156
pythonPath,
154157
constants,
155158
timeoutForRun,
156-
PythonTypeHintsStorage.get(mypyStorage)
159+
PythonTypeHintsStorage.get(mypyStorage),
160+
coverageMode,
161+
sendCoverageContinuously,
157162
)
158163
val namesInModule = mypyStorage.names
159164
.getOrDefault(curModule, emptyList())

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

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

33
import org.utbot.framework.codegen.domain.RuntimeExceptionTestsBehaviour
44
import org.utbot.framework.codegen.domain.TestFramework
5+
import org.utbot.python.evaluation.utils.PythonCoverageMode
56
import java.nio.file.Path
67

78
data class TestFileInformation(
@@ -22,4 +23,6 @@ class PythonTestGenerationConfig(
2223
val withMinimization: Boolean,
2324
val isCanceled: () -> Boolean,
2425
val runtimeExceptionTestsBehaviour: RuntimeExceptionTestsBehaviour,
26+
val coverageMeasureMode: PythonCoverageMode = PythonCoverageMode.Instructions,
27+
val sendCoverageContinuously: Boolean = true,
2528
)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ abstract class PythonTestGenerationProcessor {
6767
timeoutForRun = configuration.timeoutForRun,
6868
sourceFileContent = configuration.testFileInformation.testedFileContent,
6969
mypyStorage = mypyStorage,
70-
mypyReportLine = emptyList()
70+
mypyReportLine = emptyList(),
71+
coverageMode = configuration.coverageMeasureMode,
72+
sendCoverageContinuously = configuration.sendCoverageContinuously,
7173
)
7274

7375
val until = startTime + configuration.timeout

utbot-python/src/main/kotlin/org/utbot/python/evaluation/PythonWorkerManager.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ import java.net.ServerSocket
1111
import java.net.Socket
1212
import java.net.SocketTimeoutException
1313
import org.apache.logging.log4j.LogManager
14+
import org.utbot.python.evaluation.utils.PythonCoverageMode
1415

1516
private val logger = KotlinLogging.logger {}
1617

1718
class PythonWorkerManager(
1819
private val serverSocket: ServerSocket,
1920
val pythonPath: String,
2021
val until: Long,
22+
private val coverageMeasureMode: PythonCoverageMode = PythonCoverageMode.Instructions,
23+
private val sendCoverageContinuously: Boolean = true,
2124
val pythonCodeExecutorConstructor: (PythonWorker) -> PythonCodeExecutor,
2225
) {
2326
var timeout: Long = 0
@@ -47,8 +50,8 @@ class PythonWorkerManager(
4750
coverageReceiver.address().second,
4851
"--logfile", logfile.absolutePath,
4952
"--loglevel", logLevel, // "DEBUG", "INFO", "WARNING", "ERROR"
50-
"--coverage_type", "instructions", // "lines", "instructions"
51-
"--send_coverage", // "--send_coverage", "--no-send_coverage"
53+
"--coverage_type", coverageMeasureMode.toString(), // "lines", "instructions"
54+
sendCoverageContinuously.toSendCoverageContinuouslyString(), // "--send_coverage", "--no-send_coverage"
5255
))
5356
timeout = max(until - processStartTime, 0)
5457
if (this::workerSocket.isInitialized && !workerSocket.isClosed) {
@@ -122,5 +125,13 @@ class PythonWorkerManager(
122125

123126
companion object {
124127
val logfile = TemporaryFileManager.createTemporaryFile("", "utbot_executor.log", "log", true)
128+
129+
fun Boolean.toSendCoverageContinuouslyString(): String {
130+
return if (this) {
131+
"--send_coverage"
132+
} else {
133+
"--no-send_coverage"
134+
}
135+
}
125136
}
126137
}

utbot-python/src/main/kotlin/org/utbot/python/evaluation/utils/Utils.kt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@ import org.utbot.python.PythonMethod
55
import org.utbot.python.framework.api.python.util.pythonAnyClassId
66
import org.utbot.python.newtyping.pythonTypeRepresentation
77

8-
fun coveredLinesToInstructions(coveredLines: Collection<Int>, method: PythonMethod): List<Instruction> {
9-
return coveredLines.map {
10-
Instruction(
11-
method.containingPythonClass?.pythonTypeRepresentation() ?: pythonAnyClassId.name,
12-
method.methodSignature(),
13-
it,
14-
it.toLong()
15-
)
8+
enum class PythonCoverageMode {
9+
Lines {
10+
override fun toString() = "lines"
11+
},
12+
13+
Instructions {
14+
override fun toString() = "instructions"
15+
}
16+
}
17+
18+
fun String.toPythonCoverageMode(): PythonCoverageMode? {
19+
return when (this.lowercase()) {
20+
"lines" -> PythonCoverageMode.Lines
21+
"instructions" -> PythonCoverageMode.Instructions
22+
else -> null
1623
}
1724
}
1825

@@ -47,4 +54,4 @@ fun makeInstructions(coveredInstructions: Collection<PyInstruction>, method: Pyt
4754
offset
4855
)
4956
}
50-
}
57+
}

0 commit comments

Comments
 (0)