Skip to content

Cannot generate test for Python generics: No seed candidates generated #1822

@tyuldashev

Description

@tyuldashev

Description

When try to generate tests for User-defined generic types either no test are generated or exception is thrown.

To Reproduce

Steps to reproduce the behavior:

from typing import TypeVar, Generic
from logging import Logger

T = TypeVar('T')

class LoggedVar(Generic[T]):
    def __init__(self, value: T, name: str, logger: Logger) -> None:
        self.name = name
        self.logger = logger
        self.value = value

    def set(self, new: T) -> None:
        self.log('Set ' + repr(self.value))
        self.value = new

    def get(self) -> T:
        self.log('Get ' + repr(self.value))
        return self.value

    def log(self, message: str) -> None:
        self.logger.info('%s: %s', self.name, message)
  1. Use code above to reproduce problem, it's take from Python Typing documentation
  2. Invoke test generation for the class for individual functions.

Expected behavior

Tests are supposed to be generated.

Actual behavior

For get and log no tests are generated. For set and __init__ exception is thrown.

Visual proofs (screenshots, logs, images)

Exception:

org.utbot.fuzzing.NoSeedValueException: No seed candidates generated for type: org.utbot.python.newtyping.general.TypeParameter@6268f73a
	at org.utbot.fuzzing.FuzzingApi.produce(Api.kt:381)
	at org.utbot.fuzzing.FuzzingApi.fuzz(Api.kt:354)
	at org.utbot.fuzzing.FuzzingApi.fuzz$fuzzOne(Api.kt:277)
	at org.utbot.fuzzing.FuzzingApi.access$fuzz$fuzzOne(Api.kt:1)
	at org.utbot.fuzzing.FuzzingApi$fuzz$2$1.invokeSuspend(Api.kt:294)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlin.sequences.SequenceBuilderIterator.hasNext(SequenceBuilder.kt:129)
	at org.utbot.fuzzing.FuzzingApi.fuzz(Api.kt:707)
	at org.utbot.fuzzing.FuzzingApi.fuzz$default(Api.kt:261)
	at org.utbot.python.PythonEngine$fuzzing$1.invokeSuspend(PythonEngine.kt:250)
	at org.utbot.python.PythonEngine$fuzzing$1.invoke(PythonEngine.kt)
	at org.utbot.python.PythonEngine$fuzzing$1.invoke(PythonEngine.kt)
	at kotlinx.coroutines.flow.SafeFlow.collectSafely(Builders.kt:61)
	at kotlinx.coroutines.flow.AbstractFlow.collect(Flow.kt:230)
	at org.utbot.python.PythonTestCaseGenerator$generate$1.invokeSuspend(PythonTestCaseGenerator.kt:144)
	at org.utbot.python.PythonTestCaseGenerator$generate$1.invoke(PythonTestCaseGenerator.kt)
	at org.utbot.python.PythonTestCaseGenerator$generate$1.invoke(PythonTestCaseGenerator.kt)
	at org.utbot.python.PythonTestCaseGenerator$inferAnnotations$1.invokeSuspend(PythonTestCaseGenerator.kt:241)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:284)
	at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
	at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
	at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
	at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
	at org.utbot.python.PythonTestCaseGenerator.inferAnnotations(PythonTestCaseGenerator.kt:234)
	at org.utbot.python.PythonTestCaseGenerator.generate(PythonTestCaseGenerator.kt:113)
	at org.utbot.python.PythonTestGenerationProcessor.processTestGeneration(PythonTestGenerationProcessor.kt:109)
	at org.utbot.python.PythonTestGenerationProcessor.processTestGeneration$default(PythonTestGenerationProcessor.kt:32)
	at org.utbot.intellij.plugin.language.python.PythonDialogProcessor$createTests$1.run(PythonDialogProcessor.kt:171)
	at com.intellij.openapi.progress.impl.CoreProgressManager.startTask(CoreProgressManager.java:442)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.startTask(ProgressManagerImpl.java:114)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressAsynchronously$5(CoreProgressManager.java:493)
	at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$3(ProgressRunner.java:252)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:188)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$12(CoreProgressManager.java:608)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:683)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:639)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:607)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:175)
	at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:252)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
	at java.base/java.lang.Thread.run(Thread.java:833)

Metadata

Metadata

Labels

comp-codegenIssue is related to code generatorctg-bugIssue is a buglang-pythonIssue is related to python supportstatus-verifiedBug fix is verified

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions