This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
databricks-test: Fix for multiple runs (#6)
- Loading branch information
Showing
6 changed files
with
117 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
FROM conda/miniconda3 | ||
|
||
RUN apt-get update | ||
RUN apt-get install -y gcc wget openjdk-8-jdk | ||
ARG SPARK_VERSION=2.4.4 | ||
ARG HADOOP_VERSION=2.7 | ||
|
||
# Install Spark runtime | ||
WORKDIR / | ||
RUN wget -q https://www-eu.apache.org/dist/spark/spark-2.4.4/spark-2.4.4-bin-hadoop2.7.tgz | ||
RUN tar -zxf spark-2.4.4-bin-hadoop2.7.tgz | ||
RUN rm spark-2.4.4-bin-hadoop2.7.tgz | ||
ENV SPARK_HOME /spark-2.4.4-bin-hadoop2.7 | ||
RUN apt-get update \ | ||
&& apt-get install -y \ | ||
wget \ | ||
apt-transport-https \ | ||
openjdk-8-jdk \ | ||
&& wget -q https://archive.apache.org/dist/spark/spark-${SPARK_VERSION}/spark-${SPARK_VERSION}-bin-hadoop${HADOOP_VERSION}.tgz \ | ||
&& tar -zxf spark-${SPARK_VERSION}-bin-hadoop${HADOOP_VERSION}.tgz \ | ||
&& rm spark-${SPARK_VERSION}-bin-hadoop${HADOOP_VERSION}.tgz | ||
|
||
RUN pip install pytest==5.3.1 pytest-mock==1.13.0 flake8==3.7.9 pyspark==2.4.4 pyarrow==0.13.0 | ||
ENV SPARK_HOME /spark-${SPARK_VERSION}-bin-hadoop${HADOOP_VERSION} | ||
|
||
RUN pip install pandas==0.24.2 | ||
RUN pip install pytest==5.3.1 pytest-mock==1.13.0 flake8==3.7.9 pyspark==${SPARK_VERSION} pyarrow==0.13.0 pandas==0.24.2 | ||
|
||
CMD ["python"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
setuptools.setup( | ||
name='databricks_test', | ||
version='0.0.1', | ||
version='0.0.4', | ||
author="Alexandre Gattiker", | ||
author_email="[email protected]", | ||
description="Unit testing and mocking for Databricks", | ||
|
19 changes: 19 additions & 0 deletions
19
Python/packages/databricks-test/tests/multiple_runs_notebook.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Databricks notebook source | ||
|
||
# COMMAND ---------- | ||
|
||
# Instrument for unit tests. This is only executed in local unit tests, not in Databricks. | ||
if 'dbutils' not in locals(): | ||
import databricks_test | ||
databricks_test.inject_variables() | ||
|
||
# COMMAND ---------- | ||
|
||
# Widgets for interactive development. | ||
dbutils.widgets.text("input", "") | ||
dbutils.widgets.text("output", "") | ||
|
||
# COMMAND ---------- | ||
|
||
with open(dbutils.widgets.get('output'), "w") as output_file: | ||
output_file.write(dbutils.widgets.get('input')) |
19 changes: 19 additions & 0 deletions
19
Python/packages/databricks-test/tests/multiple_runs_notebook2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Databricks notebook source | ||
|
||
# COMMAND ---------- | ||
|
||
# Instrument for unit tests. This is only executed in local unit tests, not in Databricks. | ||
if 'dbutils' not in locals(): | ||
import databricks_test | ||
databricks_test.inject_variables() | ||
|
||
# COMMAND ---------- | ||
|
||
# Widgets for interactive development. | ||
dbutils.widgets.text("input", "") | ||
dbutils.widgets.text("output", "") | ||
|
||
# COMMAND ---------- | ||
|
||
with open(dbutils.widgets.get('output'), "w") as output_file: | ||
output_file.write(dbutils.widgets.get('input')) |
49 changes: 49 additions & 0 deletions
49
Python/packages/databricks-test/tests/multiple_runs_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import databricks_test | ||
from tempfile import NamedTemporaryFile | ||
import uuid | ||
|
||
|
||
def run_notebook(notebook, run_num, dbrickstest): | ||
|
||
input = str(uuid.uuid4()) | ||
|
||
with NamedTemporaryFile() as tmp_dir: | ||
|
||
# Provide input and output location as widgets to notebook | ||
switch = { | ||
"input": input, | ||
"output": tmp_dir.name, | ||
} | ||
dbrickstest.dbutils.widgets.get.side_effect = lambda x: switch.get( | ||
x, "") | ||
|
||
# Run notebook | ||
dbrickstest.run_notebook(".", notebook) | ||
|
||
# Notebook writes the input parameter as output file | ||
with open(tmp_dir.name) as output_file: | ||
assert input == output_file.read(), f"Run #{run_num} output" | ||
|
||
|
||
def test_multiple_runs_in_same_session_1(): | ||
with databricks_test.session() as dbrickstest: | ||
run_notebook("multiple_runs_notebook", 1, dbrickstest) | ||
run_notebook("multiple_runs_notebook", 2, dbrickstest) | ||
|
||
with databricks_test.session() as dbrickstest: | ||
run_notebook("multiple_runs_notebook", 3, dbrickstest) | ||
|
||
|
||
def test_multiple_runs_in_same_session_and_run_other_session(): | ||
with databricks_test.session() as dbrickstest: | ||
run_notebook("multiple_runs_notebook", 4, dbrickstest) | ||
|
||
|
||
def test_multiple_runs_in_multiple_test_cases(): | ||
with databricks_test.session() as dbrickstest: | ||
run_notebook("multiple_runs_notebook2", 5, dbrickstest) | ||
|
||
|
||
def test_multiple_runs_in_multiple_test_cases2(): | ||
with databricks_test.session() as dbrickstest: | ||
run_notebook("multiple_runs_notebook2", 6, dbrickstest) |