Skip to content

Commit 8f4f772

Browse files
committed
Add protocol supporting
1 parent e18787a commit 8f4f772

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import org.utbot.python.framework.api.python.util.pythonAnyClassId
1818
import org.utbot.python.fuzzing.PythonFeedback
1919
import org.utbot.python.fuzzing.PythonFuzzing
2020
import org.utbot.python.fuzzing.PythonMethodDescription
21+
import org.utbot.python.newtyping.PythonTypeStorage
2122
import org.utbot.python.newtyping.general.Type
2223
import org.utbot.python.providers.PythonFuzzedMethodDescription
2324
import org.utbot.python.providers.defaultPythonModelProvider
@@ -39,7 +40,8 @@ class PythonEngine(
3940
private val fuzzedConcreteValues: List<FuzzedConcreteValue>,
4041
private val selectedTypeMap: Map<String, NormalizedPythonAnnotation>,
4142
private val timeoutForRun: Long,
42-
private val initialCoveredLines: Set<Int>
43+
private val initialCoveredLines: Set<Int>,
44+
private val pythonTypeStorage: PythonTypeStorage? = null,
4345
) {
4446

4547
private data class JobResult(
@@ -215,7 +217,7 @@ class PythonEngine(
215217

216218
val coveredLines = initialCoveredLines.toMutableSet()
217219

218-
PythonFuzzing { description, parameterValues ->
220+
PythonFuzzing(pythonTypeStorage!!) { description, parameterValues ->
219221

220222
val (thisObject, modelList) =
221223
if (methodUnderTest.containingPythonClassId == null)

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.utbot.python.code.ArgInfoCollector
1111
import org.utbot.python.framework.api.python.NormalizedPythonAnnotation
1212
import org.utbot.python.framework.api.python.util.pythonAnyClassId
1313
import org.utbot.python.newtyping.PythonTypeDescription
14+
import org.utbot.python.newtyping.PythonTypeStorage
1415
import org.utbot.python.newtyping.general.FunctionTypeCreator
1516
import org.utbot.python.newtyping.runmypy.RunMypy
1617
import org.utbot.python.typing.AnnotationFinder.findAnnotations
@@ -92,7 +93,8 @@ object PythonTestCaseGenerator {
9293
emptyList(),
9394
method.arguments.zip(args).associate { it.first.name to NormalizedPythonAnnotation((it.second.meta as PythonTypeDescription).name.toString()) },
9495
timeoutForRun,
95-
coveredLines
96+
coveredLines,
97+
PythonTypeStorage.get(storage)
9698
)
9799

98100
var coverageLimit = 10
@@ -192,7 +194,7 @@ object PythonTestCaseGenerator {
192194
argInfoCollector.getConstants(),
193195
annotations,
194196
timeoutForRun,
195-
coveredLines
197+
coveredLines,
196198
)
197199

198200
var coverageLimit = 10

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/PythonApi.kt

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import org.utbot.python.fuzzing.provider.StrValueProvider
2121
import org.utbot.python.fuzzing.provider.TupleFixSizeValueProvider
2222
import org.utbot.python.fuzzing.provider.TupleValueProvider
2323
import org.utbot.python.fuzzing.provider.UnionValueProvider
24+
import org.utbot.python.newtyping.PythonProtocolDescription
25+
import org.utbot.python.newtyping.PythonSubtypeChecker
26+
import org.utbot.python.newtyping.PythonTypeStorage
2427
import org.utbot.python.newtyping.general.Type
2528

2629
data class PythonFuzzedConcreteValue(
@@ -64,24 +67,31 @@ fun pythonDefaultValueProviders(idGenerator: IdGenerator<Long>) = listOf(
6467
)
6568

6669
class PythonFuzzing(
67-
val execute: suspend (description: PythonMethodDescription, values: List<PythonTreeModel>) -> PythonFeedback
70+
val pythonTypeStorage: PythonTypeStorage,
71+
val execute: suspend (description: PythonMethodDescription, values: List<PythonTreeModel>) -> PythonFeedback,
6872
) : Fuzzing<Type, PythonTreeModel, PythonMethodDescription, PythonFeedback> {
69-
override fun generate(description: PythonMethodDescription, type: Type): Sequence<Seed<Type, PythonTreeModel>> {
73+
fun generateDefault(description: PythonMethodDescription, type: Type): Sequence<Seed<Type, PythonTreeModel>> {
7074
val idGenerator = PythonIdGenerator()
7175
return pythonDefaultValueProviders(idGenerator).asSequence().flatMap { provider ->
72-
try {
73-
if (provider.accept(type)) {
74-
provider.generate(description, type)
75-
} else {
76-
emptySequence()
77-
}
78-
} catch (t: Throwable) {
79-
logger.error(t) { "Error occurs in value provider: $provider" }
76+
if (provider.accept(type)) {
77+
provider.generate(description, type)
78+
} else {
8079
emptySequence()
8180
}
8281
}
8382
}
8483

84+
override fun generate(description: PythonMethodDescription, type: Type): Sequence<Seed<Type, PythonTreeModel>> {
85+
var providers = generateDefault(description, type)
86+
if (type.meta is PythonProtocolDescription) {
87+
val subtypes = pythonTypeStorage.allTypes.filter {
88+
PythonSubtypeChecker.checkIfRightIsSubtypeOfLeft(type, it, pythonTypeStorage)
89+
}
90+
subtypes.forEach { providers += generateDefault(description, it) }
91+
}
92+
return providers
93+
}
94+
8595
override suspend fun handle(description: PythonMethodDescription, values: List<PythonTreeModel>): PythonFeedback {
8696
return execute(description, values)
8797
}

0 commit comments

Comments
 (0)