Skip to content

Commit 7e5eb95

Browse files
authored
Test examples notebooks with library descriptor (#439)
Improve `NotebooksTest` to also test the Jupyter integration. Before this change, by using Kotlin scripting `DependsOn` and imports, the library's integration with Kotlin Jupyter was not tested. After this change, by using the `%use` magic line, Kotlin Jupyter will use the library's integration as part of the test. Currently, that integration is merely importing some classes, but this change is still an improvement in that it increases coverage.
1 parent d1927be commit 7e5eb95

File tree

1 file changed

+16
-8
lines changed
  • library/src/examplesTest/kotlin/com/gabrielfeo/develocity/api/example/notebook

1 file changed

+16
-8
lines changed

library/src/examplesTest/kotlin/com/gabrielfeo/develocity/api/example/notebook/NotebooksTest.kt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import org.junit.jupiter.api.BeforeEach
77
import org.junit.jupiter.api.Test
88
import org.junit.jupiter.api.assertDoesNotThrow
99
import org.junit.jupiter.api.io.TempDir
10+
import java.net.URI
1011
import java.nio.file.Path
1112
import kotlin.io.path.Path
1213
import kotlin.io.path.absolute
1314
import kotlin.io.path.div
15+
import kotlin.io.path.writeText
1416

1517
class NotebooksTest {
1618

@@ -53,17 +55,23 @@ class NotebooksTest {
5355

5456
private fun forceUseOfMavenLocalSnapshotArtifact(sourceNotebook: Path): Path {
5557
val mavenLocal = Path(System.getProperty("user.home"), ".m2/repository").toUri()
58+
val libraryDescriptor = (tempDir / "develocity-api-kotlin.json").apply {
59+
writeText(buildLibraryDescriptor(version = "SNAPSHOT", repository = mavenLocal))
60+
}
5661
return jupyter.replaceMagics(
5762
path = sourceNotebook,
5863
replacePattern = Regex("""(?:DependsOn|%use).*develocity-api-kotlin.*"""),
59-
replacement = listOf(
60-
"""@file:DependsOn("com.gabrielfeo:develocity-api-kotlin:SNAPSHOT")""",
61-
"""@file:Repository("$mavenLocal")""",
62-
"""%trackClasspath on""",
63-
"""import com.gabrielfeo.develocity.api.*""",
64-
"""import com.gabrielfeo.develocity.api.model.*""",
65-
"""import com.gabrielfeo.develocity.api.extension.*""",
66-
).joinToString("\n")
64+
replacement = """
65+
%use develocity-api-kotlin@file[$libraryDescriptor]
66+
%trackClasspath on
67+
""".trimIndent()
6768
)
6869
}
70+
71+
private fun buildLibraryDescriptor(version: String, repository: URI) = """
72+
{
73+
"dependencies": ["com.gabrielfeo:develocity-api-kotlin:$version"],
74+
"repositories": ["$repository"]
75+
}
76+
""".trimIndent()
6977
}

0 commit comments

Comments
 (0)