-
Notifications
You must be signed in to change notification settings - Fork 3k
Add a way to easily test units #1386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
consideRatio
merged 19 commits into
jupyter:master
from
mathbunnyru:asalikhov/units_test
Jun 28, 2021
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
30a1d17
Add a way to easily test units
bbb91c4
Fix style
21927f8
Remove redundant upper
9bf2047
Fix style
856577b
Image name is a property
c662739
Simplify conftest
8477244
Add tests README
466a5fb
Fix syntax
a93c13a
Add pytest info
bf05f42
Some fixes
1cef89a
Fix link
e264a5e
Fix link
a305eaa
Fix container running
a3a0a5b
Fix
532d373
Apply suggestions from code review
mathbunnyru d17515a
Merge branch 'master' into asalikhov/units_test
9aafae7
Merge branch 'master' into asalikhov/units_test
52a91a3
assert after logs output
mathbunnyru c73a1d1
Update test/test_units.py
mathbunnyru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,4 @@ | ||
# Copyright (c) Jupyter Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||
|
||
import pyspark # noqa: F401 |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,9 @@ | ||
# Copyright (c) Jupyter Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
|
||
np.random.seed(0) | ||
print(pd.Series(np.random.randint(0, 7, size=10)).sum()) |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,7 @@ | ||
# Copyright (c) Jupyter Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||
import tensorflow as tf | ||
|
||
|
||
print(tf.constant('Hello, TensorFlow')) | ||
print(tf.reduce_sum(tf.random.normal([1000, 1000]))) |
This file contains hidden or 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,15 @@ | ||
# Docker stacks testing | ||
|
||
We test our images using `pytest` module. | ||
|
||
`conftest.py` and `pytest.ini` in the root of our repository define the environment in which tests are run. | ||
More info on pytest can be found [here](https://docs.pytest.org/en/latest/contents.html). | ||
|
||
There are two kinds of tests we use: | ||
|
||
- General tests - these are located in [this](https://github.com/jupyter/docker-stacks/blob/master/test) folder | ||
- Image specific tests - for example, [base-notebook/test](https://github.com/jupyter/docker-stacks/blob/master/base-notebook/test) folder | ||
|
||
We also have a way to easily run arbitrary python files in a container. | ||
This is useful for running unit tests of packages we use, so we put these files in `{image}/test/units` folder. | ||
An example of such a test is [unit_pandas.py](https://github.com/jupyter/docker-stacks/blob/master/scipy-notebook/test/units/unit_pandas.py). |
This file contains hidden or 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,35 @@ | ||
# Copyright (c) Jupyter Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||
|
||
import logging | ||
import os | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
THIS_DIR = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
|
||
def test_units(container): | ||
"""Various units tests | ||
Add a py file in the {image}/test/units dir and it will be automatically tested | ||
""" | ||
short_image_name = container.image_name[container.image_name.rfind('/') + 1:] | ||
host_data_dir = os.path.join(THIS_DIR, f"../{short_image_name}/test/units") | ||
LOGGER.info(f"Searching for units tests in {host_data_dir}") | ||
cont_data_dir = "/home/jovyan/data" | ||
|
||
if not os.path.exists(host_data_dir): | ||
LOGGER.info(f"Not found unit tests for image: {container.image_name}") | ||
return | ||
|
||
for test_file in os.listdir(host_data_dir): | ||
LOGGER.info(f"Running unit test: {test_file}") | ||
|
||
c = container.run( | ||
volumes={host_data_dir: {"bind": cont_data_dir, "mode": "ro"}}, | ||
tty=True, | ||
command=['start.sh', 'python', f'{cont_data_dir}/{test_file}'] | ||
) | ||
rv = c.wait(timeout=30) | ||
logs = c.logs(stdout=True).decode('utf-8') | ||
LOGGER.debug(logs) | ||
assert rv == 0 or rv["StatusCode"] == 0 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.