How to use primitive class of io.kotest.assertions.print package

Best Kotest code snippet using io.kotest.assertions.print.primitive

executeTests.kt

Source:executeTests.kt Github

copy

Full Screen

1package org.jetbrains.kotlinx.jupyter.test2import ch.qos.logback.classic.Level.DEBUG3import ch.qos.logback.classic.Level.OFF4import io.kotest.matchers.paths.shouldBeAFile5import io.kotest.matchers.shouldBe6import jupyter.kotlin.providers.UserHandlesProvider7import kotlinx.serialization.json.Json8import kotlinx.serialization.json.JsonNull9import kotlinx.serialization.json.JsonObject10import kotlinx.serialization.json.JsonPrimitive11import kotlinx.serialization.json.decodeFromJsonElement12import org.jetbrains.kotlinx.jupyter.JupyterSockets13import org.jetbrains.kotlinx.jupyter.LoggingManagement.mainLoggerLevel14import org.jetbrains.kotlinx.jupyter.api.Notebook15import org.jetbrains.kotlinx.jupyter.api.SessionOptions16import org.jetbrains.kotlinx.jupyter.compiler.util.EvaluatedSnippetMetadata17import org.jetbrains.kotlinx.jupyter.messaging.ExecuteReply18import org.jetbrains.kotlinx.jupyter.messaging.ExecuteRequest19import org.jetbrains.kotlinx.jupyter.messaging.ExecutionResult20import org.jetbrains.kotlinx.jupyter.messaging.InputReply21import org.jetbrains.kotlinx.jupyter.messaging.IsCompleteReply22import org.jetbrains.kotlinx.jupyter.messaging.IsCompleteRequest23import org.jetbrains.kotlinx.jupyter.messaging.KernelStatus24import org.jetbrains.kotlinx.jupyter.messaging.Message25import org.jetbrains.kotlinx.jupyter.messaging.MessageType26import org.jetbrains.kotlinx.jupyter.messaging.StatusReply27import org.jetbrains.kotlinx.jupyter.messaging.StreamResponse28import org.jetbrains.kotlinx.jupyter.messaging.jsonObject29import org.junit.jupiter.api.Assertions.assertEquals30import org.junit.jupiter.api.Assertions.assertNull31import org.junit.jupiter.api.Test32import org.junit.jupiter.api.Timeout33import org.junit.jupiter.api.parallel.Execution34import org.junit.jupiter.api.parallel.ExecutionMode35import org.zeromq.ZMQ36import java.io.File37import java.net.URLClassLoader38import java.nio.file.Files39import java.util.concurrent.TimeUnit40import kotlin.io.path.readText41import kotlin.reflect.KProperty142import kotlin.reflect.full.memberProperties43import kotlin.test.assertNotNull44import kotlin.test.assertTrue45fun JsonObject.string(key: String): String {46 return (get(key) as JsonPrimitive).content47}48@Timeout(100, unit = TimeUnit.SECONDS)49@Execution(ExecutionMode.SAME_THREAD)50class ExecuteTests : KernelServerTestsBase() {51 private var context: ZMQ.Context? = null52 private var shell: ClientSocket? = null53 private var ioPub: ClientSocket? = null54 private var stdin: ClientSocket? = null55 override fun beforeEach() {56 try {57 context = ZMQ.context(1)58 shell = ClientSocket(context!!, JupyterSockets.SHELL)59 ioPub = ClientSocket(context!!, JupyterSockets.IOPUB)60 stdin = ClientSocket(context!!, JupyterSockets.STDIN)61 ioPub?.subscribe(byteArrayOf())62 shell?.connect()63 ioPub?.connect()64 stdin?.connect()65 } catch (e: Throwable) {66 afterEach()67 throw e68 }69 }70 override fun afterEach() {71 shell?.close()72 shell = null73 ioPub?.close()74 ioPub = null75 stdin?.close()76 stdin = null77 context?.term()78 context = null79 }80 private fun doExecute(81 code: String,82 hasResult: Boolean = true,83 ioPubChecker: (ZMQ.Socket) -> Unit = {},84 executeReplyChecker: (Message) -> Unit = {},85 inputs: List<String> = emptyList(),86 allowStdin: Boolean = true,87 storeHistory: Boolean = true88 ): Any? {89 try {90 val shell = this.shell!!91 val ioPub = this.ioPub!!92 val stdin = this.stdin!!93 shell.sendMessage(MessageType.EXECUTE_REQUEST, content = ExecuteRequest(code, allowStdin = allowStdin, storeHistory = storeHistory))94 inputs.forEach {95 stdin.sendMessage(MessageType.INPUT_REPLY, InputReply(it))96 }97 var msg = shell.receiveMessage()98 assertEquals(MessageType.EXECUTE_REPLY, msg.type)99 executeReplyChecker(msg)100 msg = ioPub.receiveMessage()101 assertEquals(MessageType.STATUS, msg.type)102 assertEquals(KernelStatus.BUSY, (msg.content as StatusReply).status)103 msg = ioPub.receiveMessage()104 assertEquals(MessageType.EXECUTE_INPUT, msg.type)105 ioPubChecker(ioPub)106 var response: Any? = null107 if (hasResult) {108 msg = ioPub.receiveMessage()109 val content = msg.content as ExecutionResult110 assertEquals(MessageType.EXECUTE_RESULT, msg.type)111 response = content.data112 }113 msg = ioPub.receiveMessage()114 assertEquals(MessageType.STATUS, msg.type)115 assertEquals(KernelStatus.IDLE, (msg.content as StatusReply).status)116 return response117 } catch (e: Throwable) {118 afterEach()119 throw e120 }121 }122 private fun executeWithNoStdin(code: String) {123 doExecute(124 code,125 hasResult = false,126 allowStdin = false,127 ioPubChecker = {128 val msg = it.receiveMessage()129 assertEquals(MessageType.STREAM, msg.type)130 assertStartsWith("Input from stdin is unsupported by the client", (msg.content as StreamResponse).text)131 }132 )133 }134 private fun doIsComplete(code: String): String {135 try {136 val shell = this.shell!!137 shell.sendMessage(MessageType.IS_COMPLETE_REQUEST, content = IsCompleteRequest(code))138 val responseMsg = shell.receiveMessage()139 assertEquals(MessageType.IS_COMPLETE_REPLY, responseMsg.type)140 val content = responseMsg.content as IsCompleteReply141 return content.status142 } catch (e: Throwable) {143 afterEach()144 throw e145 }146 }147 @Test148 fun testExecute() {149 val res = doExecute("2+2") as JsonObject150 assertEquals("4", res.string("text/plain"))151 }152 @Test153 fun testOutput() {154 val code =155 """156 for (i in 1..5) {157 Thread.sleep(200)158 print(i)159 }160 """.trimIndent()161 fun checker(ioPub: ZMQ.Socket) {162 for (i in 1..5) {163 val msg = ioPub.receiveMessage()164 assertEquals(MessageType.STREAM, msg.type)165 assertEquals(i.toString(), (msg.content as StreamResponse).text)166 }167 }168 val res = doExecute(code, false, ::checker)169 assertNull(res)170 }171 @Test172 fun testOutputMagic() {173 val code =174 """175 %output --max-buffer=2 --max-time=10000176 for (i in 1..5) {177 print(i)178 }179 """.trimIndent()180 val expected = arrayOf("12", "34", "5")181 fun checker(ioPub: ZMQ.Socket) {182 for (el in expected) {183 val msg = ioPub.receiveMessage()184 val content = msg.content185 assertEquals(MessageType.STREAM, msg.type)186 assertTrue(content is StreamResponse)187 assertEquals(el, content.text)188 }189 }190 val res = doExecute(code, false, ::checker)191 assertNull(res)192 }193 @Test194 fun testOutputStrings() {195 val code =196 """197 for (i in 1..5) {198 Thread.sleep(200)199 println("text" + i)200 }201 """.trimIndent()202 fun checker(ioPub: ZMQ.Socket) {203 for (i in 1..5) {204 val msg = ioPub.receiveMessage()205 assertEquals(MessageType.STREAM, msg.type)206 assertEquals("text$i" + System.lineSeparator(), (msg.content as StreamResponse).text)207 }208 }209 val res = doExecute(code, false, ::checker)210 assertNull(res)211 }212 // TODO: investigate, why this test is hanging213 @Test214 fun testReadLine() {215 val code =216 """217 val answer = readLine()218 answer219 """.trimIndent()220 val res = doExecute(code, inputs = listOf("42"))221 assertEquals(jsonObject("text/plain" to "42"), res)222 }223 @Test224 fun testCompiledData() {225 doExecute(226 """227 SessionOptions.serializeScriptData = true228 """.trimIndent(),229 hasResult = false230 )231 val code =232 """233 val xyz = 42234 """.trimIndent()235 val res = doExecute(236 code,237 hasResult = false,238 executeReplyChecker = { message ->239 val metadata = message.data.metadata240 assertTrue(metadata is JsonObject)241 val snippetMetadata = Json.decodeFromJsonElement<EvaluatedSnippetMetadata?>(242 metadata["eval_metadata"] ?: JsonNull243 )244 val compiledData = snippetMetadata?.compiledData245 assertNotNull(compiledData)246 val deserializer = org.jetbrains.kotlinx.jupyter.compiler.CompiledScriptsSerializer()247 val dir = Files.createTempDirectory("kotlin-jupyter-exec-test")248 dir.toFile().deleteOnExit()249 val classesDir = dir.resolve("classes")250 val sourcesDir = dir.resolve("sources")251 val names = deserializer.deserializeAndSave(compiledData, classesDir, sourcesDir)252 val kClassName = names.single()253 val classLoader = URLClassLoader(arrayOf(classesDir.toUri().toURL()), ClassLoader.getSystemClassLoader())254 val loadedClass = classLoader.loadClass(kClassName).kotlin255 @Suppress("UNCHECKED_CAST")256 val xyzProperty = loadedClass.memberProperties.single { it.name == "xyz" } as KProperty1<Any, Int>257 val constructor = loadedClass.constructors.single()258 val userHandlesProvider = object : UserHandlesProvider {259 override val host: Nothing? = null260 override val notebook: Notebook = NotebookMock261 override val sessionOptions: SessionOptions262 get() = throw NotImplementedError()263 }264 val instance = constructor.call(emptyArray<Any>(), userHandlesProvider)265 xyzProperty.get(instance) shouldBe 42266 val sourceFile = sourcesDir.resolve("Line_1.kts")267 sourceFile.shouldBeAFile()268 sourceFile.readText() shouldBe "val xyz = 42"269 }270 )271 assertNull(res)272 }273 @Test274 fun testLibraryLoadingErrors() {275 doExecute(276 """277 USE {278 import("xyz.ods")279 }280 """.trimIndent(),281 false,282 ioPubChecker = {283 val msg = it.receiveMessage()284 assertEquals(MessageType.STREAM, msg.type)285 val msgText = (msg.content as StreamResponse).text286 assertTrue("The problem is found in one of the loaded libraries" in msgText)287 }288 )289 }290 @Test291 fun testCounter() {292 fun checkCounter(message: Message, expectedCounter: Long) {293 val data = message.data.content as ExecuteReply294 assertEquals(expectedCounter, data.executionCount)295 }296 val res1 = doExecute("41", executeReplyChecker = { checkCounter(it, 1) })297 val res2 = doExecute("42", executeReplyChecker = { checkCounter(it, 2) })298 val res3 = doExecute(299 " \"\${Out[1]} \${Out[2]}\" ",300 storeHistory = false,301 executeReplyChecker = { checkCounter(it, 3) }302 )303 val res4 = doExecute(304 "try { Out[3] } catch(e: ArrayIndexOutOfBoundsException) { null }",305 storeHistory = false,306 executeReplyChecker = { checkCounter(it, 3) }307 )308 assertEquals(jsonObject("text/plain" to "41"), res1)309 assertEquals(jsonObject("text/plain" to "42"), res2)310 assertEquals(jsonObject("text/plain" to "41 42"), res3)311 assertEquals(jsonObject("text/plain" to "null"), res4)312 }313 @Test314 fun testReadLineWithNoStdin() {315 executeWithNoStdin("readLine() ?: \"blah\"")316 }317 @Test318 fun testStdinReadWithNoStdin() {319 executeWithNoStdin("System.`in`.read()")320 }321 @Test322 fun testIsComplete() {323 assertEquals("complete", doIsComplete("2 + 2"))324 assertEquals("incomplete", doIsComplete("fun f() : Int { return 1"))325 assertEquals(if (runInSeparateProcess) DEBUG else OFF, mainLoggerLevel())326 }327 @Test328 fun testLoggerAppender() {329 val file = File.createTempFile("kotlin-jupyter-logger-appender-test", ".txt")330 doExecute("%logHandler add f1 --file ${file.absolutePath}", false)331 val result1 = doExecute("2 + 2")332 assertEquals(jsonObject("text/plain" to "4"), result1)333 doExecute("%logHandler remove f1", false)334 val result2 = doExecute("3 + 4")335 assertEquals(jsonObject("text/plain" to "7"), result2)336 val logText = file.readText()337 assertTrue("2 + 2" in logText)338 assertTrue("3 + 4" !in logText)339 file.delete()340 }341}...

Full Screen

Full Screen

PrimitivePrintsTest.kt

Source:PrimitivePrintsTest.kt Github

copy

Full Screen

1package io.kotest.assertions.print2import io.kotest.core.spec.style.FunSpec3import io.kotest.matchers.shouldBe4import java.io.File5import java.nio.file.Paths6private val sep = File.separator7class PrimitivePrintsTest : FunSpec() {8 init {9 test("Detect show for string") {10 "my string".print().value shouldBe "\"my string\""11 "".print().value shouldBe "<empty string>"12 " ".print().value shouldBe "\"\\s\\s\\s\\s\\s\\s\""13 }14 test("detect show for char") {15 'a'.print().value shouldBe "'a'"16 }17 test("detect show for float") {18 14.3F.print().value shouldBe "14.3f"19 }20 test("detect show for long") {21 14L.print().value shouldBe "14L"22 }23 test("Detect show for any") {24 13.print().value shouldBe "13"25 true.print().value shouldBe "true"26 File("/a/b/c").print().value shouldBe "${sep}a${sep}b${sep}c"27 Paths.get("/a/b/c").print().value shouldBe "${sep}a${sep}b${sep}c"28 }29 test("detect show for boolean") {30 true.print().value shouldBe "true"31 false.print().value shouldBe "false"32 }33 test("BooleanPrint.print") {34 BooleanPrint.print(true).value shouldBe "true"35 BooleanPrint.print(false).value shouldBe "false"36 }37 test("CharPrint.char") {38 CharPrint.print('a').value shouldBe "'a'"39 CharPrint.print('w').value shouldBe "'w'"40 }41 test("detect show for BooleanArray") {42 booleanArrayOf(true, false, true).print().value shouldBe "[true, false, true]"43 }44 test("detect show for char array") {45 charArrayOf('a', 'g').print().value shouldBe "['a', 'g']"46 }47 }48}49data class WibbleWobble(val a: String, val b: Int)50class WibbleWobblePrint : Print<WibbleWobble> {51 override fun print(a: WibbleWobble): Printed = "wibble ${a.a} wobble ${a.b}".printed()52}...

Full Screen

Full Screen

primitive

Using AI Code Generation

copy

Full Screen

1import io.kotest.assertions.print.*2import io.kotest.assertions.throwables.*3import io.kotest.assertions.timing.*4import io.kotest.assertions.arrow.core.*5import io.kotest.assertions.arrow.either.*6import io.kotest.assertions.arrow.option.*7import io.kotest.assertions.arrow.validated.*8import io.kotest.assertions.arrow.datatypes.*9import io.kotest.assertions.arrow.*10import io.kotest.assertions.*11import io.kotest.assertions.show.*12import io.kotest.assertions.show.show.*13import io.kotest.assertions.show.showAny.*14import io.kotest.assertions.show.showCollection.*15import io.kotest.assertions.show.showMap.*16import io.kotest.assertions.show.showThrowable.*17import io.kotest.assertions.show.showMap.*18import io.kotest.assertions.show.showThrowable.*19import io.kotest.assert

Full Screen

Full Screen

primitive

Using AI Code Generation

copy

Full Screen

1 import io.kotest.assertions.print.Printed2 import io.kotest.assertions.print.printed3 import io.kotest.assertions.print.printedOrNull4 import io.kotest.assertions.throwables.shouldThrow5 import io.kotest.assertions.throwables.shouldThrowAny6 import io.kotest.assertions.throwables.shouldThrowExactly7 import io.kotest.assertions.throwables.shouldThrowExactlyAny8 import io.kotest.assertions.throwables.shouldThrowInstanceOf9 import io.kotest.assertions.throwables.shouldThrowInstanceOfAny10 import io.kotest.assertions.throwables.shouldThrowUnit11 import io.kotest.assertions.throwables.shouldThrowUnitAny12 import io.kotest.assertions.throwables.shouldThrowUnitExactly13 import io.kotest.assertions.throwables.shouldThrowUnitExactlyAny14 import io.kotest.assertions.throwables.shouldThrowUnitInstanceOf15 import io.kotest.assertions.throwables.shouldThrowUnitInstanceOfAny16 import io.kotest.assertions.throwables.throwable17 import io.kotest.assertions.throwables.throwableOrNull18 import io.kotest.assertions.time.shouldBeAfter19 import io.kotest.assertions.time.shouldBeAfterOrEqual20 import io.kotest.assertions.time.shouldBeBefore21 import io.kotest.assertions.time.shouldBeBeforeOrEqual22 import io.kotest.assertions.time.shouldBeBetween23 import io.kotest.assertions.time.shouldBeBetweenOrEqual24 import io.kotest.assertions.time.shouldBeBetweenOrOutside25 import io.kotest.assertions.time.shouldBeBetweenOrOutsideOrEqual26 import io.kotest.assertions.time.shouldBeBetweenOrOutsideOrEqualOrEqual27 import io.kotest.assertions.time.shouldBeBetweenOrOutsideOrEqualOrEqualOrEqual28 import io.kotest.assertions.time.shouldBeBetweenOrOutsideOrEqualOrEqualOrEqualOrEqual29 import io.kotest.assertions.time.shouldBeBetweenOrOutsideOrEqualOrEqualOrEqualOrEqualOrEqual30 import io.kotest.assertions.time.shouldBeBetweenOrOutsideOrEqualOrEqualOr

Full Screen

Full Screen

primitive

Using AI Code Generation

copy

Full Screen

1println(x)2print(y)3println(z)4print(a)5println(b)6print(c)7println(d)8print(e)9println(f)10print(g)11println(h)12print(i)13println(j)14print(k)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in primitive

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful