Add a way to easily test units

This commit is contained in:
Ayaz Salikhov
2021-06-26 14:40:45 +03:00
parent 5211732116
commit 30a1d17085
16 changed files with 93 additions and 98 deletions

View File

@@ -7,23 +7,23 @@ import pytest
import os
LOGGER = logging.getLogger(__name__)
THIS_DIR = os.path.dirname(os.path.realpath(__file__))
@pytest.mark.parametrize("test_file,expected_file,description",
[
("matplotlib_1.py", "test.png",
"Test that matplotlib is able to plot a graph and write it as an image ..."),
("matplotlib_fonts_1.py", "test_fonts.png",
"Test cm-super latex labels in matplotlib ...")
])
@pytest.mark.parametrize(
"test_file,expected_file,description",
[
("matplotlib_1.py", "test.png", "Test that matplotlib is able to plot a graph and write it as an image ..."),
("matplotlib_fonts_1.py", "test_fonts.png", "Test cm-super latex labels in matplotlib ...")
]
)
def test_matplotlib(container, test_file, expected_file, description):
"""Various tests performed on matplotlib
- Test that matplotlib is able to plot a graph and write it as an image
- Test matplotlib latex fonts, which depend on the cm-super package
"""
host_data_dir = os.path.join(os.path.dirname(
os.path.realpath(__file__)), "data")
host_data_dir = os.path.join(THIS_DIR, "data")
cont_data_dir = "/home/jovyan/data"
output_dir = "/tmp"
LOGGER.info(description)

View File

@@ -1,32 +0,0 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import logging
import pytest
LOGGER = logging.getLogger(__name__)
@pytest.mark.parametrize(
"name,command_list",
[
(
"Sum series",
[
"import pandas as pd",
"import numpy as np",
"np.random.seed(0)",
"print(pd.Series(np.random.randint(0, 7, size=10)).sum())"
]
),
],
)
def test_pandas(container, name, command_list):
"""Basic pandas tests"""
LOGGER.info(f"Testing pandas: {name} ...")
command = ';'.join(command_list)
c = container.run(tty=True, command=["start.sh", "python", "-c", command])
rv = c.wait(timeout=30)
assert rv == 0 or rv["StatusCode"] == 0, f"Command {command} failed"
logs = c.logs(stdout=True).decode("utf-8")
LOGGER.debug(logs)

View File

@@ -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())