|
1 | 1 | package org.jetbrains.kotlinx.dataframe.io
|
2 | 2 |
|
| 3 | +import io.kotest.assertions.withClue |
| 4 | +import io.kotest.matchers.collections.shouldBeIn |
3 | 5 | import io.kotest.matchers.shouldBe
|
4 | 6 | import org.intellij.lang.annotations.Language
|
| 7 | +import org.jetbrains.kotlinx.dataframe.AnyFrame |
5 | 8 | import org.jetbrains.kotlinx.dataframe.DataFrame
|
| 9 | +import org.jetbrains.kotlinx.dataframe.api.inferType |
6 | 10 | import org.jetbrains.kotlinx.dataframe.api.schema
|
7 | 11 | import org.jetbrains.kotlinx.dataframe.io.db.MsSql
|
| 12 | +import org.jetbrains.kotlinx.dataframe.schema.CompareResult |
8 | 13 | import java.sql.Connection
|
9 | 14 | import java.sql.ResultSet
|
10 | 15 | import kotlin.reflect.typeOf
|
@@ -128,3 +133,26 @@ internal fun inferNullability(connection: Connection) {
|
128 | 133 |
|
129 | 134 | connection.createStatement().execute("DROP TABLE TestTable1")
|
130 | 135 | }
|
| 136 | + |
| 137 | +/** |
| 138 | + * Helper to check whether the provided schema matches the inferred schema. |
| 139 | + * |
| 140 | + * It must hold that all types in the provided schema are equal or super to |
| 141 | + * the corresponding types in the inferred schema. |
| 142 | + */ |
| 143 | +@Suppress("INVISIBLE_REFERENCE") |
| 144 | +fun AnyFrame.assertInferredTypesMatchSchema() { |
| 145 | + withClue({ |
| 146 | + """ |
| 147 | + |Inferred schema must be <: Provided schema |
| 148 | + | |
| 149 | + |Inferred Schema: |
| 150 | + |${inferType().schema().toString().lines().joinToString("\n|")} |
| 151 | + | |
| 152 | + |Provided Schema: |
| 153 | + |${schema().toString().lines().joinToString("\n|")} |
| 154 | + """.trimMargin() |
| 155 | + }) { |
| 156 | + schema().compare(inferType().schema()).isSuperOrEqual() shouldBe true |
| 157 | + } |
| 158 | +} |
0 commit comments