From 0819a28ca858481fe0f2fc380250f40b4fe6af7d Mon Sep 17 00:00:00 2001 From: Ilya Muradyan Date: Wed, 9 Oct 2024 18:40:14 +0200 Subject: [PATCH] Load dependencies from annotations on classpath initialization in test-kit tests --- gradle.properties | 1 + jupyter-lib/test-kit-test/build.gradle.kts | 28 +++++++++++++++++++ .../testkit/test/JupyterReplTestingTest.kt | 0 .../test/JupyterReplWithResolverTest.kt | 5 ++++ .../testkit/test/NotebookParserTest.kt | 0 .../integrations/DatetimeTestIntegration.kt | 14 ++++++++++ .../src/test/testData/testNotebook1.ipynb | 0 jupyter-lib/test-kit/build.gradle.kts | 3 -- settings.gradle.kts | 1 + .../jupyter/repl/impl/ReplForJupyterImpl.kt | 3 +- 10 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 jupyter-lib/test-kit-test/build.gradle.kts rename jupyter-lib/{test-kit => test-kit-test}/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/JupyterReplTestingTest.kt (100%) rename jupyter-lib/{test-kit => test-kit-test}/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/JupyterReplWithResolverTest.kt (95%) rename jupyter-lib/{test-kit => test-kit-test}/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/NotebookParserTest.kt (100%) create mode 100644 jupyter-lib/test-kit-test/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/integrations/DatetimeTestIntegration.kt rename jupyter-lib/{test-kit => test-kit-test}/src/test/testData/testNotebook1.ipynb (100%) diff --git a/gradle.properties b/gradle.properties index 8e2fc00be..fa6f73869 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,6 +10,7 @@ gradleCompatibleKotlinLanguageLevel=1.8 kotlin.jupyter.add.api=false kotlin.jupyter.add.scanner=false +kotlin.jupyter.add.testkit=false artifactsPath=build/artifacts diff --git a/jupyter-lib/test-kit-test/build.gradle.kts b/jupyter-lib/test-kit-test/build.gradle.kts new file mode 100644 index 000000000..8f89c8815 --- /dev/null +++ b/jupyter-lib/test-kit-test/build.gradle.kts @@ -0,0 +1,28 @@ +plugins { + kotlin("libs.publisher") + kotlin("jvm") + kotlin("plugin.serialization") + kotlin("jupyter.api") +} + +repositories { + mavenCentral() +} + +dependencies { + testImplementation(projects.testKit) + testImplementation(libs.test.kotlintest.assertions) +} + +val rootShadowJar = ':' + build.SHADOW_JAR_TASK + +buildSettings { + withLanguageLevel(rootSettings.kotlinLanguageLevel) + withTests { + mustRunAfter(rootShadowJar) + } +} + +tasks.processJupyterApiResources { + libraryProducers = listOf("org.jetbrains.kotlinx.jupyter.testkit.test.integrations.DatetimeTestIntegration") +} diff --git a/jupyter-lib/test-kit/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/JupyterReplTestingTest.kt b/jupyter-lib/test-kit-test/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/JupyterReplTestingTest.kt similarity index 100% rename from jupyter-lib/test-kit/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/JupyterReplTestingTest.kt rename to jupyter-lib/test-kit-test/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/JupyterReplTestingTest.kt diff --git a/jupyter-lib/test-kit/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/JupyterReplWithResolverTest.kt b/jupyter-lib/test-kit-test/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/JupyterReplWithResolverTest.kt similarity index 95% rename from jupyter-lib/test-kit/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/JupyterReplWithResolverTest.kt rename to jupyter-lib/test-kit-test/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/JupyterReplWithResolverTest.kt index ed4fe6f79..552071227 100644 --- a/jupyter-lib/test-kit/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/JupyterReplWithResolverTest.kt +++ b/jupyter-lib/test-kit-test/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/JupyterReplWithResolverTest.kt @@ -74,4 +74,9 @@ class JupyterReplWithResolverTest : JupyterReplTestCase( exception.shouldBeTypeOf() exception.message shouldContain "Unresolved reference: multik" } + + @Test + fun `datetime is loaded and present`() { + execRendered("Clock.System.now()") + } } diff --git a/jupyter-lib/test-kit/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/NotebookParserTest.kt b/jupyter-lib/test-kit-test/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/NotebookParserTest.kt similarity index 100% rename from jupyter-lib/test-kit/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/NotebookParserTest.kt rename to jupyter-lib/test-kit-test/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/NotebookParserTest.kt diff --git a/jupyter-lib/test-kit-test/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/integrations/DatetimeTestIntegration.kt b/jupyter-lib/test-kit-test/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/integrations/DatetimeTestIntegration.kt new file mode 100644 index 000000000..1e137ab5c --- /dev/null +++ b/jupyter-lib/test-kit-test/src/test/kotlin/org/jetbrains/kotlinx/jupyter/testkit/test/integrations/DatetimeTestIntegration.kt @@ -0,0 +1,14 @@ +package org.jetbrains.kotlinx.jupyter.testkit.test.integrations + +import org.jetbrains.kotlinx.jupyter.api.libraries.JupyterIntegration +import org.jetbrains.kotlinx.jupyter.api.libraries.dependencies + +@Suppress("unused") +class DatetimeTestIntegration : JupyterIntegration() { + override fun Builder.onLoaded() { + dependencies { + implementation("org.jetbrains.kotlinx:kotlinx-datetime-jvm:0.6.1") + } + import("kotlinx.datetime.Clock") + } +} diff --git a/jupyter-lib/test-kit/src/test/testData/testNotebook1.ipynb b/jupyter-lib/test-kit-test/src/test/testData/testNotebook1.ipynb similarity index 100% rename from jupyter-lib/test-kit/src/test/testData/testNotebook1.ipynb rename to jupyter-lib/test-kit-test/src/test/testData/testNotebook1.ipynb diff --git a/jupyter-lib/test-kit/build.gradle.kts b/jupyter-lib/test-kit/build.gradle.kts index d512c587b..465391fe1 100644 --- a/jupyter-lib/test-kit/build.gradle.kts +++ b/jupyter-lib/test-kit/build.gradle.kts @@ -20,9 +20,6 @@ val rootShadowJar = ':' + build.SHADOW_JAR_TASK buildSettings { withLanguageLevel(rootSettings.kotlinLanguageLevel) - withTests { - mustRunAfter(rootShadowJar) - } } tasks.dokkaHtmlPartial { diff --git a/settings.gradle.kts b/settings.gradle.kts index 193424d8f..e5ebc8f5d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -26,6 +26,7 @@ libSubproject("shared-compiler") libSubproject("spring-starter") libSubproject("lib-ext") libSubproject("test-kit") +libSubproject("test-kit-test") exampleSubproject("getting-started") diff --git a/src/main/kotlin/org/jetbrains/kotlinx/jupyter/repl/impl/ReplForJupyterImpl.kt b/src/main/kotlin/org/jetbrains/kotlinx/jupyter/repl/impl/ReplForJupyterImpl.kt index a979e4dc4..e205de278 100644 --- a/src/main/kotlin/org/jetbrains/kotlinx/jupyter/repl/impl/ReplForJupyterImpl.kt +++ b/src/main/kotlin/org/jetbrains/kotlinx/jupyter/repl/impl/ReplForJupyterImpl.kt @@ -391,6 +391,7 @@ class ReplForJupyterImpl( private fun withEvalContext(action: () -> T): T { return synchronized(this) { + require(!evalContextEnabled) { "Recursive execution is not supported" } evalContextEnabled = true try { action() @@ -589,7 +590,7 @@ class ReplForJupyterImpl( } override fun eval(execution: ExecutionCallback): T { - return synchronized(this) { + return withEvalContext { executor.execute(execution) } }