Skip to content

Commit 97d3767

Browse files
committed
create tmp directory with utbot FileUtil
1 parent bccf488 commit 97d3767

4 files changed

Lines changed: 15 additions & 9 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.utbot.python
22

33
import com.squareup.moshi.Moshi
44
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
5+
import org.utbot.common.FileUtil
56
import org.utbot.framework.codegen.*
67
import org.utbot.framework.codegen.model.CodeGenerator
78
import org.utbot.framework.codegen.model.constructor.CgMethodTestSet
@@ -18,6 +19,7 @@ import org.utbot.python.utils.getLineOfFunction
1819
import java.io.File
1920
import java.nio.file.Path
2021
import kotlin.io.path.Path
22+
import kotlin.io.path.deleteExisting
2123
import kotlin.io.path.name
2224
import kotlin.io.path.pathString
2325

@@ -57,7 +59,7 @@ object PythonTestGenerationProcessor {
5759
Cleaner.restart()
5860

5961
try {
60-
FileManager.assignTestSourceRoot(testSourceRoot)
62+
FileManager.setup(testSourceRoot)
6163

6264
if (!doNotCheckRequirements) {
6365
checkingRequirementsAction()

utbot-python/src/main/kotlin/org/utbot/python/utils/Cleaner.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ object Cleaner {
66
fun addFunction(f: () -> Unit) {
77
val oldClean = clean
88
val newClean = {
9-
oldClean()
109
f()
10+
oldClean()
1111
}
1212
clean = newClean
1313
}

utbot-python/src/main/kotlin/org/utbot/python/utils/FileManager.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
package org.utbot.python.utils
22

3+
import org.utbot.common.FileUtil
34
import java.io.File
5+
import java.nio.file.Path
46
import java.nio.file.Paths
7+
import kotlin.io.path.deleteExisting
8+
import kotlin.io.path.exists
59

610
object FileManager {
711
private var testSourceRoot: String = ""
8-
private const val tmpFolderName = ".tmp"
12+
private lateinit var tmpDirectory: Path
913
private var nextId = 0
1014

11-
fun assignTestSourceRoot(testSourceRoot: String) {
15+
fun setup(testSourceRoot: String) {
16+
tmpDirectory = FileUtil.createTempDirectory("python-test-generation")
17+
Cleaner.addFunction { tmpDirectory.deleteExisting() }
18+
1219
this.testSourceRoot = testSourceRoot
1320
val testsFolder = File(testSourceRoot)
1421
if (!testsFolder.exists())
1522
testsFolder.mkdirs()
16-
val tmpFolder = Paths.get(testSourceRoot, tmpFolderName).toFile()
17-
if (!tmpFolder.exists())
18-
tmpFolder.mkdir()
1923
}
2024

2125
fun assignTemporaryFile(fileName_: String? = null, tag: String? = null, addToCleaner: Boolean = true): File {
2226
val fileName = fileName_ ?: ("${nextId++}_" + (tag ?: ""))
23-
val fullpath = Paths.get(testSourceRoot, tmpFolderName, fileName)
27+
val fullpath = Paths.get(tmpDirectory.toString(), fileName)
2428
val result = fullpath.toFile()
2529
if (addToCleaner)
2630
Cleaner.addFunction { result.delete() }

utbot-python/todo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
### Относительно мелкие задачи
1111
- [ ] переписать создание файлов на Psi Documents
12-
- [ ] создавать временную директорию в правильном месте
12+
- [x] создавать временную директорию в правильном месте
1313
- [ ] обрабатывать аргументы по имени (kwargs), *args, **kwargs
1414
- [ ] заменить klaxon на moshi
1515
- [ ] Более полный сбор конструкторов (учет наследования)

0 commit comments

Comments
 (0)