Fix style in tests

This commit is contained in:
Ayaz Salikhov
2021-06-27 12:32:26 +03:00
parent 5211732116
commit 4828b4146f
12 changed files with 45 additions and 27 deletions

View File

@@ -7,6 +7,7 @@ import pytest
import os import os
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
THIS_DIR = os.path.dirname(os.path.realpath(__file__))
@pytest.mark.parametrize( @pytest.mark.parametrize(
@@ -16,7 +17,7 @@ LOGGER = logging.getLogger(__name__)
) )
def test_nbconvert(container, test_file): def test_nbconvert(container, test_file):
"""Check if Spark notebooks can be executed""" """Check if Spark notebooks can be executed"""
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" cont_data_dir = "/home/jovyan/data"
output_dir = "/tmp" output_dir = "/tmp"
timeout_ms = 600 timeout_ms = 600

View File

@@ -8,7 +8,7 @@ LOGGER = logging.getLogger(__name__)
@pytest.mark.parametrize( @pytest.mark.parametrize(
"package_manager, cmd", "package_manager, version_arg",
[ [
("apt", "--version"), ("apt", "--version"),
("conda", "--version"), ("conda", "--version"),
@@ -17,13 +17,14 @@ LOGGER = logging.getLogger(__name__)
("pip", "--version"), ("pip", "--version"),
], ],
) )
def test_package_manager(container, package_manager, cmd): def test_package_manager(container, package_manager, version_arg):
"""Test the notebook start-notebook script""" """Test the notebook start-notebook script"""
LOGGER.info( LOGGER.info(
f"Test that the package manager {package_manager} is working properly ..." f"Test that the package manager {package_manager} is working properly ..."
) )
c = container.run( c = container.run(
tty=True, command=["start.sh", "bash", "-c", f"{package_manager} {cmd}"] tty=True,
command=["start.sh", "bash", "-c", f"{package_manager} {version_arg}"]
) )
rv = c.wait(timeout=5) rv = c.wait(timeout=5)
logs = c.logs(stdout=True).decode("utf-8") logs = c.logs(stdout=True).decode("utf-8")

View File

@@ -9,7 +9,8 @@ LOGGER = logging.getLogger(__name__)
def test_pandoc(container): def test_pandoc(container):
"""Pandoc shall be able to convert MD to HTML.""" """Pandoc shall be able to convert MD to HTML."""
c = container.run( c = container.run(
tty=True, command=["start.sh", "bash", "-c", 'echo "**BOLD**" | pandoc'] tty=True,
command=["start.sh", "bash", "-c", 'echo "**BOLD**" | pandoc']
) )
c.wait(timeout=10) c.wait(timeout=10)
logs = c.logs(stdout=True).decode("utf-8") logs = c.logs(stdout=True).decode("utf-8")

View File

@@ -8,7 +8,11 @@ LOGGER = logging.getLogger(__name__)
@pytest.mark.parametrize( @pytest.mark.parametrize(
"env,expected_server", [(["JUPYTER_ENABLE_LAB=yes"], "lab"), (None, "notebook"), ], "env,expected_server",
[
(["JUPYTER_ENABLE_LAB=yes"], "lab"),
(None, "notebook"),
],
) )
def test_start_notebook(container, http_client, env, expected_server): def test_start_notebook(container, http_client, env, expected_server):
"""Test the notebook start-notebook script""" """Test the notebook start-notebook script"""

View File

@@ -33,10 +33,10 @@ def docker_client():
@pytest.fixture(scope='session') @pytest.fixture(scope='session')
def image_name(): def image_name():
"""Image name to test""" """Image name to test"""
return os.getenv('TEST_IMAGE', 'jupyter/base-notebook') return os.getenv('TEST_IMAGE')
class TrackedContainer(object): class TrackedContainer:
"""Wrapper that collects docker container configuration and delays """Wrapper that collects docker container configuration and delays
container creation/execution. container creation/execution.

View File

@@ -9,7 +9,8 @@ def test_julia(container):
"""Basic julia test""" """Basic julia test"""
LOGGER.info("Test that julia is correctly installed ...") LOGGER.info("Test that julia is correctly installed ...")
running_container = container.run( running_container = container.run(
tty=True, command=["start.sh", "bash", "-c", "sleep infinity"] tty=True,
command=["start.sh", "bash", "-c", "sleep infinity"]
) )
command = "julia --version" command = "julia --version"
cmd = running_container.exec_run(command) cmd = running_container.exec_run(command)

View File

@@ -10,7 +10,8 @@ def test_inkscape(container):
"""Inkscape shall be installed to be able to convert SVG files.""" """Inkscape shall be installed to be able to convert SVG files."""
LOGGER.info("Test that inkscape is working by printing its version ...") LOGGER.info("Test that inkscape is working by printing its version ...")
c = container.run( c = container.run(
tty=True, command=["start.sh", "bash", "-c", "inkscape --version"] tty=True,
command=["start.sh", "bash", "-c", "inkscape --version"]
) )
c.wait(timeout=10) c.wait(timeout=10)
logs = c.logs(stdout=True).decode("utf-8") logs = c.logs(stdout=True).decode("utf-8")

View File

@@ -7,18 +7,24 @@ import pytest
import os import os
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
THIS_DIR = os.path.dirname(os.path.realpath(__file__))
@pytest.mark.parametrize("test_file, output_format,", [ @pytest.mark.parametrize(
("notebook_math", "pdf"), ("notebook_math", "html"), "test_file, output_format",
("notebook_svg", "pdf"), ("notebook_svg", "html"), [
]) ("notebook_math", "pdf"),
("notebook_math", "html"),
("notebook_svg", "pdf"),
("notebook_svg", "html"),
],
)
def test_nbconvert(container, test_file, output_format): def test_nbconvert(container, test_file, output_format):
"""Check if nbconvert is able to convert a notebook file""" """Check if nbconvert is able to convert a notebook file"""
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" cont_data_dir = "/home/jovyan/data"
output_dir = "/tmp" output_dir = "/tmp"
LOGGER.info(f"Test that the example notebook {test_file} can be converted to {output_format.upper()} ...") LOGGER.info(f"Test that the example notebook {test_file} can be converted to {output_format} ...")
command = f"jupyter nbconvert {cont_data_dir}/{test_file}.ipynb --output-dir {output_dir} --to {output_format}" command = f"jupyter nbconvert {cont_data_dir}/{test_file}.ipynb --output-dir {output_dir} --to {output_format}"
c = container.run( c = container.run(
volumes={host_data_dir: {"bind": cont_data_dir, "mode": "ro"}}, volumes={host_data_dir: {"bind": cont_data_dir, "mode": "ro"}},

View File

@@ -1,5 +1,6 @@
docker docker
myst-parser myst-parser
packaging
plumbum plumbum
pre-commit pre-commit
pytest pytest

View File

@@ -26,7 +26,8 @@ def test_check_extension(container, extension):
""" """
LOGGER.info(f"Checking the extension: {extension} ...") LOGGER.info(f"Checking the extension: {extension} ...")
c = container.run( c = container.run(
tty=True, command=["start.sh", "jupyter", "labextension", "check", extension] tty=True,
command=["start.sh", "jupyter", "labextension", "check", extension]
) )
rv = c.wait(timeout=10) rv = c.wait(timeout=10)
logs = c.logs(stdout=True).decode("utf-8") logs = c.logs(stdout=True).decode("utf-8")

View File

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

View File

@@ -50,7 +50,8 @@ class CondaPackageHelper:
"""Start the TrackedContainer and return an instance of a running container""" """Start the TrackedContainer and return an instance of a running container"""
LOGGER.info(f"Starting container {container.image_name} ...") LOGGER.info(f"Starting container {container.image_name} ...")
return container.run( return container.run(
tty=True, command=["start.sh", "bash", "-c", "sleep infinity"] tty=True,
command=["start.sh", "bash", "-c", "sleep infinity"]
) )
@staticmethod @staticmethod