aboutsummaryrefslogtreecommitdiff
path: root/sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestUtils.scala
diff options
context:
space:
mode:
Diffstat (limited to 'sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestUtils.scala')
-rw-r--r--sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestUtils.scala28
1 files changed, 27 insertions, 1 deletions
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestUtils.scala b/sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestUtils.scala
index 6a4cc95d36..b5ad73b746 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestUtils.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/test/SQLTestUtils.scala
@@ -20,7 +20,7 @@ package org.apache.spark.sql.test
import java.io.File
import java.net.URI
import java.nio.file.Files
-import java.util.UUID
+import java.util.{Locale, UUID}
import scala.language.implicitConversions
import scala.util.control.NonFatal
@@ -229,6 +229,32 @@ private[sql] trait SQLTestUtils
}
/**
+ * Drops database `dbName` after calling `f`.
+ */
+ protected def withDatabase(dbNames: String*)(f: => Unit): Unit = {
+ try f finally {
+ dbNames.foreach { name =>
+ spark.sql(s"DROP DATABASE IF EXISTS $name")
+ }
+ }
+ }
+
+ /**
+ * Enables Locale `language` before executing `f`, then switches back to the default locale of JVM
+ * after `f` returns.
+ */
+ protected def withLocale(language: String)(f: => Unit): Unit = {
+ val originalLocale = Locale.getDefault
+ try {
+ // Add Locale setting
+ Locale.setDefault(new Locale(language))
+ f
+ } finally {
+ Locale.setDefault(originalLocale)
+ }
+ }
+
+ /**
* Activates database `db` before executing `f`, then switches back to `default` database after
* `f` returns.
*/