@@ -39,6 +39,8 @@ class PythonGenerateTestsCommand : CliktCommand(
3939 help = " File with Python code to generate tests for."
4040 )
4141
42+ private fun absSourceFile () = sourceFile.toAbsolutePath()
43+
4244 private val pythonClass by option(
4345 " -c" , " --class" ,
4446 help = " Specify top-level (ordinary, not nested) class under test. " +
@@ -132,7 +134,7 @@ class PythonGenerateTestsCommand : CliktCommand(
132134 Success (
133135 topLevelFunctions
134136 .mapNotNull { parseFunctionDefinition(it) }
135- .map { PythonMethodHeader (it.name.toString(), sourceFile , null ) }
137+ .map { PythonMethodHeader (it.name.toString(), absSourceFile() , null ) }
136138 )
137139 else {
138140 val topLevelClassMethods = topLevelClasses
@@ -142,7 +144,7 @@ class PythonGenerateTestsCommand : CliktCommand(
142144 .mapNotNull { parseFunctionDefinition(it) }
143145 .map { function ->
144146 val parsedClassName = PythonClassId (cls.name.toString())
145- PythonMethodHeader (function.name.toString(), sourceFile , parsedClassName)
147+ PythonMethodHeader (function.name.toString(), absSourceFile() , parsedClassName)
146148 }
147149 }
148150 if (topLevelClassMethods.isNotEmpty()) {
@@ -154,7 +156,7 @@ class PythonGenerateTestsCommand : CliktCommand(
154156 val pythonMethodsOpt = selectedMethods.map { functionName ->
155157 topLevelFunctions
156158 .mapNotNull { parseFunctionDefinition(it) }
157- .map { PythonMethodHeader (it.name.toString(), sourceFile , null ) }
159+ .map { PythonMethodHeader (it.name.toString(), absSourceFile() , null ) }
158160 .find { it.name == functionName }
159161 ?.let { Success (it) }
160162 ? : Fail (" Couldn't find top-level function $functionName in the source file." )
@@ -174,7 +176,7 @@ class PythonGenerateTestsCommand : CliktCommand(
174176 val fineMethods = methods
175177 .filter { ! forbiddenMethods.contains(it.name.toString()) }
176178 .map {
177- PythonMethodHeader (it.name.toString(), sourceFile , parsedClassId)
179+ PythonMethodHeader (it.name.toString(), absSourceFile() , parsedClassId)
178180 }
179181 if (fineMethods.isNotEmpty())
180182 Success (fineMethods)
@@ -201,8 +203,8 @@ class PythonGenerateTestsCommand : CliktCommand(
201203
202204 @Suppress(" UNCHECKED_CAST" )
203205 private fun calculateValues (): Optional <Unit > {
204- val currentPythonModuleOpt = findCurrentPythonModule(directoriesForSysPath, sourceFile )
205- sourceFileContent = File (sourceFile ).readText()
206+ val currentPythonModuleOpt = findCurrentPythonModule(directoriesForSysPath, absSourceFile() )
207+ sourceFileContent = File (absSourceFile() ).readText()
206208 val pythonMethodsOpt = bind(currentPythonModuleOpt) { getPythonMethods() }
207209
208210 return bind(pack(currentPythonModuleOpt, pythonMethodsOpt)) {
@@ -232,7 +234,7 @@ class PythonGenerateTestsCommand : CliktCommand(
232234
233235 val config = PythonTestGenerationConfig (
234236 pythonPath = pythonPath,
235- testFileInformation = TestFileInformation (sourceFile.toAbsolutePath (), sourceFileContent, currentPythonModule.dropInitFile()),
237+ testFileInformation = TestFileInformation (absSourceFile (), sourceFileContent, currentPythonModule.dropInitFile()),
236238 sysPathDirectories = directoriesForSysPath.map { it.toAbsolutePath() } .toSet(),
237239 testedMethods = pythonMethods,
238240 timeout = timeout,
0 commit comments