File tree Expand file tree Collapse file tree 6 files changed +20
-4
lines changed
utbot-cli-python/src/main/kotlin/org/utbot/cli/language/python
utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python
samples/easy_samples/test_package
src/main/kotlin/org/utbot/python/newtyping Expand file tree Collapse file tree 6 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import org.utbot.python.framework.codegen.model.Pytest
1717import org.utbot.python.framework.codegen.model.Unittest
1818import org.utbot.python.newtyping.ast.parseClassDefinition
1919import org.utbot.python.newtyping.ast.parseFunctionDefinition
20+ import org.utbot.python.newtyping.mypy.dropInitFile
2021import org.utbot.python.utils.*
2122import org.utbot.python.utils.RequirementsUtils.installRequirements
2223import org.utbot.python.utils.RequirementsUtils.requirements
@@ -234,7 +235,7 @@ class PythonGenerateTestsCommand : CliktCommand(
234235 pythonFilePath = sourceFile.toAbsolutePath(),
235236 pythonFileContent = sourceFileContent,
236237 directoriesForSysPath = directoriesForSysPath.map { it.toAbsolutePath() }.toSet(),
237- currentPythonModule = currentPythonModule,
238+ currentPythonModule = currentPythonModule.dropInitFile() ,
238239 pythonMethods = pythonMethods,
239240 containingClassName = pythonClass,
240241 timeout = timeout,
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ import org.utbot.python.PythonTestGenerationProcessor
4242import org.utbot.python.PythonTestGenerationProcessor.processTestGeneration
4343import org.utbot.python.framework.api.python.PythonClassId
4444import org.utbot.python.framework.codegen.PythonCgLanguageAssistant
45+ import org.utbot.python.newtyping.mypy.dropInitFile
4546import org.utbot.python.utils.RequirementsUtils.installRequirements
4647import org.utbot.python.utils.RequirementsUtils.requirements
4748import org.utbot.python.utils.camelToSnakeCase
@@ -174,7 +175,7 @@ object PythonDialogProcessor {
174175 realElements.toSet(),
175176 model.runtimeExceptionTestsBehaviour,
176177 directoriesForSysPath,
177- moduleToImport,
178+ moduleToImport.dropInitFile() ,
178179 file,
179180 realElements.first().getContainingClass() as PyClass ?
180181 )
Original file line number Diff line number Diff line change 1+ def init_function (x : int ):
2+ return x ** 2
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ class TypeInferenceProcessor(
6060 val (mypyStorage, report) = readMypyAnnotationStorageAndInitialErrors(
6161 pythonPath,
6262 path.toString(),
63- moduleOfSourceFile,
63+ moduleOfSourceFile.dropInitFile() ,
6464 configFile
6565 )
6666
Original file line number Diff line number Diff line change @@ -45,11 +45,13 @@ fun readMypyAnnotationStorageAndInitialErrors(
4545 )
4646 )
4747 val stderr = if (fileForMypyStderr.exists()) fileForMypyStderr.readText() else null
48+ val stdout = if (fileForMypyStdout.exists()) fileForMypyStdout.readText() else null
4849 val mypyExitStatus = if (fileForMypyExitStatus.exists()) fileForMypyExitStatus.readText() else null
4950 if (result.exitValue != 0 || mypyExitStatus != " 0" )
5051 error(" Something went wrong in initial mypy run. " +
5152 " \n Python stderr ${result.stderr} " +
52- " \n Mypy stderr: $stderr " )
53+ " \n Mypy stderr: $stderr " +
54+ " \n Mypy stdout: $stdout " )
5355 return Pair (
5456 readMypyAnnotationStorage(fileForAnnotationStorage.readText()),
5557 getErrorsAndNotes(fileForMypyStdout.readText())
Original file line number Diff line number Diff line change @@ -5,4 +5,14 @@ fun String.modifyWindowsPath(): String {
55 val (disk, path) = this .split(" :" , limit = 2 )
66 " \\\\ localhost\\ $disk $${path.replace(" /" , " \\ " )} "
77 } else this
8+ }
9+
10+ /* *
11+ * Remove .__init__ suffix if it exists.
12+ It resolves problem with duplication module names in mypy, e.g. mod.__init__ and mod
13+ */
14+ fun String.dropInitFile (): String {
15+ return if (this .endsWith(" .__init__" )) {
16+ this .dropLast(9 )
17+ } else this
818}
You can’t perform that action at this time.
0 commit comments