Skip to content

Commit 1bb4b34

Browse files
committed
Used activation of any providers only if current type allows it
1 parent efdf9ef commit 1bb4b34

File tree

11 files changed

+28
-22
lines changed

11 files changed

+28
-22
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ data class FuzzedUtType(
6666
val utType: UtType,
6767
val fuzzAny: Boolean = false,
6868
) {
69-
fun activateAny() = FuzzedUtType(utType, true)
7069

7170
fun isAny(): Boolean = utType.isAny()
7271
fun pythonName(): String = utType.pythonName()
@@ -75,9 +74,12 @@ data class FuzzedUtType(
7574
fun pythonTypeRepresentation(): String = utType.pythonTypeRepresentation()
7675

7776
companion object {
78-
fun Collection<UtType>.toFuzzed() = this.map { it.toFuzzed() }
79-
fun UtType.toFuzzed() = FuzzedUtType(this)
77+
fun FuzzedUtType.activateAny() = FuzzedUtType(this.utType, true)
78+
fun FuzzedUtType.activateAnyIf(parent: FuzzedUtType) = FuzzedUtType(this.utType, parent.fuzzAny)
8079
fun Collection<FuzzedUtType>.activateAny() = this.map { it.activateAny() }
80+
fun Collection<FuzzedUtType>.activateAnyIf(parent: FuzzedUtType) = this.map { it.activateAnyIf(parent) }
81+
fun UtType.toFuzzed() = FuzzedUtType(this)
82+
fun Collection<UtType>.toFuzzed() = this.map { it.toFuzzed() }
8183
}
8284
}
8385

@@ -232,7 +234,7 @@ class PythonFuzzing(
232234
if (globalIsCancelled()) {
233235
return true
234236
}
235-
if (description.limitManager.isCancelled()) {// || description.parameters.any { it.isAny() }) {
237+
if (description.limitManager.isCancelled() || description.parameters.any { it.isAny() }) {
236238
forkType(description, stats)
237239
if (description.limitManager.isRootManager) {
238240
return FakeWithTimeoutMode.isCancelled(description.limitManager)

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/provider/DictValueProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import org.utbot.fuzzing.Seed
55
import org.utbot.python.framework.api.python.PythonTree
66
import org.utbot.python.framework.api.python.util.pythonDictClassId
77
import org.utbot.python.fuzzing.FuzzedUtType
8-
import org.utbot.python.fuzzing.FuzzedUtType.Companion.activateAny
8+
import org.utbot.python.fuzzing.FuzzedUtType.Companion.activateAnyIf
99
import org.utbot.python.fuzzing.FuzzedUtType.Companion.toFuzzed
1010
import org.utbot.python.fuzzing.PythonFuzzedValue
1111
import org.utbot.python.fuzzing.PythonMethodDescription
@@ -27,7 +27,7 @@ object DictValueProvider : PythonValueProvider {
2727
"%var% = ${type.pythonTypeRepresentation()}"
2828
)
2929
},
30-
modify = Routine.ForEach(params.toFuzzed().activateAny()) { instance, _, arguments ->
30+
modify = Routine.ForEach(params.toFuzzed().activateAnyIf(type)) { instance, _, arguments ->
3131
val key = arguments[0].tree
3232
val value = arguments[1].tree
3333
val dict = instance.tree as PythonTree.DictNode

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/provider/IteratorValueProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import org.utbot.fuzzing.Seed
55
import org.utbot.python.framework.api.python.PythonTree
66
import org.utbot.python.framework.api.python.util.pythonIteratorClassId
77
import org.utbot.python.fuzzing.FuzzedUtType
8-
import org.utbot.python.fuzzing.FuzzedUtType.Companion.activateAny
8+
import org.utbot.python.fuzzing.FuzzedUtType.Companion.activateAnyIf
99
import org.utbot.python.fuzzing.FuzzedUtType.Companion.toFuzzed
1010
import org.utbot.python.fuzzing.PythonFuzzedValue
1111
import org.utbot.python.fuzzing.PythonMethodDescription
@@ -29,7 +29,7 @@ object IteratorValueProvider : PythonValueProvider {
2929
"%var% = ${type.pythonTypeRepresentation()}"
3030
)
3131
},
32-
modify = Routine.ForEach(param.toFuzzed().activateAny()) { self, i, values ->
32+
modify = Routine.ForEach(param.toFuzzed().activateAnyIf(type)) { self, i, values ->
3333
(self.tree as PythonTree.IteratorNode).items[i] = values.first().tree
3434
}
3535
))

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/provider/ListValueProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import org.utbot.fuzzing.Seed
55
import org.utbot.python.framework.api.python.PythonTree
66
import org.utbot.python.framework.api.python.util.pythonListClassId
77
import org.utbot.python.fuzzing.FuzzedUtType
8-
import org.utbot.python.fuzzing.FuzzedUtType.Companion.activateAny
8+
import org.utbot.python.fuzzing.FuzzedUtType.Companion.activateAnyIf
99
import org.utbot.python.fuzzing.FuzzedUtType.Companion.toFuzzed
1010
import org.utbot.python.fuzzing.PythonFuzzedValue
1111
import org.utbot.python.fuzzing.PythonMethodDescription
@@ -29,7 +29,7 @@ object ListValueProvider : PythonValueProvider {
2929
"%var% = ${type.pythonTypeRepresentation()}"
3030
)
3131
},
32-
modify = Routine.ForEach(param.toFuzzed().activateAny()) { self, i, values ->
32+
modify = Routine.ForEach(param.toFuzzed().activateAnyIf(type)) { self, i, values ->
3333
(self.tree as PythonTree.ListNode).items[i] = values.first().tree
3434
}
3535
))

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/provider/OptionalValueProvider.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.utbot.fuzzing.Routine
44
import org.utbot.fuzzing.Seed
55
import org.utbot.python.framework.api.python.PythonTree
66
import org.utbot.python.fuzzing.FuzzedUtType
7+
import org.utbot.python.fuzzing.FuzzedUtType.Companion.activateAnyIf
78
import org.utbot.python.fuzzing.FuzzedUtType.Companion.toFuzzed
89
import org.utbot.python.fuzzing.PythonFuzzedValue
910
import org.utbot.python.fuzzing.PythonMethodDescription
@@ -19,9 +20,9 @@ object OptionalValueProvider : PythonValueProvider {
1920

2021
override fun generate(description: PythonMethodDescription, type: FuzzedUtType) = sequence {
2122
val params = type.utType.pythonAnnotationParameters()
22-
params.toFuzzed().forEach { unionParam ->
23+
params.forEach { unionParam ->
2324
yield(Seed.Recursive(
24-
construct = Routine.Create(listOf(unionParam)) { v -> v.first() },
25+
construct = Routine.Create(listOf(unionParam).toFuzzed().activateAnyIf(type)) { v -> v.first() },
2526
empty = Routine.Empty { PythonFuzzedValue(PythonTree.fromNone()) }
2627
))
2728
}

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/provider/SetValueProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import org.utbot.fuzzing.Seed
55
import org.utbot.python.framework.api.python.PythonTree
66
import org.utbot.python.framework.api.python.util.pythonSetClassId
77
import org.utbot.python.fuzzing.FuzzedUtType
8-
import org.utbot.python.fuzzing.FuzzedUtType.Companion.activateAny
8+
import org.utbot.python.fuzzing.FuzzedUtType.Companion.activateAnyIf
99
import org.utbot.python.fuzzing.FuzzedUtType.Companion.toFuzzed
1010
import org.utbot.python.fuzzing.PythonFuzzedValue
1111
import org.utbot.python.fuzzing.PythonMethodDescription
@@ -27,7 +27,7 @@ object SetValueProvider : PythonValueProvider {
2727
"%var% = ${type.pythonTypeRepresentation()}"
2828
)
2929
},
30-
modify = Routine.ForEach(params.toFuzzed().activateAny()) { instance, _, arguments ->
30+
modify = Routine.ForEach(params.toFuzzed().activateAnyIf(type)) { instance, _, arguments ->
3131
val item = arguments[0].tree
3232
val set = instance.tree as PythonTree.SetNode
3333
set.items.add(item)

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/provider/SubtypeValueProvider.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.utbot.fuzzing.Routine
44
import org.utbot.fuzzing.Seed
55
import org.utbot.python.framework.api.python.PythonTree
66
import org.utbot.python.fuzzing.FuzzedUtType
7+
import org.utbot.python.fuzzing.FuzzedUtType.Companion.activateAnyIf
78
import org.utbot.python.fuzzing.FuzzedUtType.Companion.toFuzzed
89
import org.utbot.python.fuzzing.PythonFuzzedValue
910
import org.utbot.python.fuzzing.PythonMethodDescription
@@ -36,7 +37,7 @@ class SubtypeValueProvider(
3637
subtypes.forEach { subtype ->
3738
yield(
3839
Seed.Recursive(
39-
construct = Routine.Create(listOf(subtype).toFuzzed()) { v -> v.first() },
40+
construct = Routine.Create(listOf(subtype).toFuzzed().activateAnyIf(type)) { v -> v.first() },
4041
empty = Routine.Empty { PythonFuzzedValue(PythonTree.FakeNode) }
4142
))
4243
}

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/provider/TupleFixSizeValueProvider.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import org.utbot.fuzzing.Routine
44
import org.utbot.fuzzing.Seed
55
import org.utbot.python.framework.api.python.PythonTree
66
import org.utbot.python.fuzzing.FuzzedUtType
7-
import org.utbot.python.fuzzing.FuzzedUtType.Companion.activateAny
7+
import org.utbot.python.fuzzing.FuzzedUtType.Companion.activateAnyIf
88
import org.utbot.python.fuzzing.FuzzedUtType.Companion.toFuzzed
99
import org.utbot.python.fuzzing.PythonFuzzedValue
1010
import org.utbot.python.fuzzing.PythonMethodDescription
@@ -22,12 +22,12 @@ object TupleFixSizeValueProvider : PythonValueProvider {
2222
val length = params.size
2323
val modifications = emptyList<Routine.Call<FuzzedUtType, PythonFuzzedValue>>().toMutableList()
2424
for (i in 0 until length) {
25-
modifications.add(Routine.Call(listOf(params[i]).toFuzzed().activateAny()) { instance, arguments ->
25+
modifications.add(Routine.Call(listOf(params[i]).toFuzzed().activateAnyIf(type)) { instance, arguments ->
2626
(instance.tree as PythonTree.TupleNode).items[i] = arguments.first().tree
2727
})
2828
}
2929
yield(Seed.Recursive(
30-
construct = Routine.Create(params.toFuzzed().activateAny()) { v ->
30+
construct = Routine.Create(params.toFuzzed().activateAnyIf(type)) { v ->
3131
PythonFuzzedValue(
3232
PythonTree.TupleNode(v.withIndex().associate { it.index to it.value.tree }.toMutableMap()),
3333
"%var% = ${type.pythonTypeRepresentation()}"

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/provider/TupleValueProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import org.utbot.fuzzing.Seed
55
import org.utbot.python.framework.api.python.PythonTree
66
import org.utbot.python.framework.api.python.util.pythonTupleClassId
77
import org.utbot.python.fuzzing.FuzzedUtType
8-
import org.utbot.python.fuzzing.FuzzedUtType.Companion.activateAny
8+
import org.utbot.python.fuzzing.FuzzedUtType.Companion.activateAnyIf
99
import org.utbot.python.fuzzing.FuzzedUtType.Companion.toFuzzed
1010
import org.utbot.python.fuzzing.PythonFuzzedValue
1111
import org.utbot.python.fuzzing.PythonMethodDescription
@@ -33,7 +33,7 @@ object TupleValueProvider : PythonValueProvider {
3333
"%var% = ${type.pythonTypeRepresentation()}"
3434
)
3535
},
36-
modify = Routine.ForEach(param.toFuzzed().activateAny()) { self, i, values ->
36+
modify = Routine.ForEach(param.toFuzzed().activateAnyIf(type)) { self, i, values ->
3737
(self.tree as PythonTree.TupleNode).items[i] = values.first().tree
3838
}
3939
))

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/provider/TypeAliasValueProvider.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.utbot.fuzzing.Routine
44
import org.utbot.fuzzing.Seed
55
import org.utbot.python.framework.api.python.PythonTree
66
import org.utbot.python.fuzzing.FuzzedUtType
7+
import org.utbot.python.fuzzing.FuzzedUtType.Companion.activateAnyIf
78
import org.utbot.python.fuzzing.FuzzedUtType.Companion.toFuzzed
89
import org.utbot.python.fuzzing.PythonFuzzedValue
910
import org.utbot.python.fuzzing.PythonMethodDescription
@@ -22,7 +23,7 @@ object TypeAliasValueProvider : PythonValueProvider {
2223
val compositeType = PythonTypeAliasDescription.castToCompatibleTypeApi(type.utType)
2324
return sequenceOf(
2425
Seed.Recursive(
25-
construct = Routine.Create(listOf(compositeType.members[0]).toFuzzed()) { v -> v.first() },
26+
construct = Routine.Create(listOf(compositeType.members[0]).toFuzzed().activateAnyIf(type)) { v -> v.first() },
2627
empty = Routine.Empty { PythonFuzzedValue(PythonTree.FakeNode) }
2728
)
2829
)

0 commit comments

Comments
 (0)