Add run_command script in tests (#1931)

* Add run_command script in tests

* Fix

* Add timeout back
This commit is contained in:
Ayaz Salikhov
2023-07-03 00:34:06 +04:00
committed by GitHub
parent 28c5a1bf1d
commit 2343fdba34
9 changed files with 50 additions and 76 deletions

View File

@@ -1,14 +1,10 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import logging
from tests.conftest import TrackedContainer
from tests.package_helper import run_package_manager
LOGGER = logging.getLogger(__name__)
from tests.run_command import run_command
def test_npm_package_manager(container: TrackedContainer) -> None:
"""Test that npm is installed and runs."""
run_package_manager(container, "npm", "--version")
run_command(container, "npm --version")

View File

@@ -1,18 +0,0 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import logging
from tests.conftest import TrackedContainer
LOGGER = logging.getLogger(__name__)
def test_julia(container: TrackedContainer) -> None:
"""Basic julia test"""
LOGGER.info("Test that julia is correctly installed ...")
logs = container.run_and_wait(
timeout=5,
tty=True,
command=["start.sh", "bash", "-c", "julia --version"],
)
LOGGER.debug(logs)

View File

@@ -0,0 +1,8 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
from tests.conftest import TrackedContainer
from tests.run_command import run_command
def test_julia(container: TrackedContainer) -> None:
run_command(container, "julia --version")

View File

@@ -1,27 +1,22 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import logging
import pytest # type: ignore
from tests.conftest import TrackedContainer
from tests.package_helper import run_package_manager
LOGGER = logging.getLogger(__name__)
from tests.run_command import run_command
@pytest.mark.parametrize(
"package_manager, version_arg",
"package_manager_command",
[
("apt", "--version"),
("conda", "--version"),
("mamba", "--version"),
("pip", "--version"),
"apt --version",
"conda --version",
"mamba --version",
"pip --version",
],
)
def test_package_manager(
container: TrackedContainer, package_manager: str, version_arg: str
container: TrackedContainer, package_manager_command: str
) -> None:
"""Test that package managers are installed and run."""
run_package_manager(container, package_manager, version_arg)
run_command(container, package_manager_command)

View File

@@ -0,0 +1,8 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
from tests.conftest import TrackedContainer
from tests.run_command import run_command
def test_julia(container: TrackedContainer) -> None:
run_command(container, "julia --version")

View File

@@ -1,18 +0,0 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import logging
from tests.conftest import TrackedContainer
LOGGER = logging.getLogger(__name__)
def test_julia(container: TrackedContainer) -> None:
"""Basic julia test"""
LOGGER.info("Test that julia is correctly installed ...")
logs = container.run_and_wait(
timeout=5,
tty=True,
command=["start.sh", "bash", "-c", "julia --version"],
)
LOGGER.debug(logs)

View File

@@ -37,21 +37,6 @@ from tests.conftest import TrackedContainer
LOGGER = logging.getLogger(__name__)
def run_package_manager(
container: TrackedContainer, package_manager: str, version_arg: str
) -> None:
"""Runs the given package manager with its version argument."""
LOGGER.info(
f"Test that the package manager {package_manager} is working properly ..."
)
container.run_and_wait(
timeout=5,
tty=True,
command=["start.sh", "bash", "-c", f"{package_manager} {version_arg}"],
)
class CondaPackageHelper:
"""Conda package helper permitting to get information about packages"""

View File

@@ -3,16 +3,12 @@
import logging
from tests.conftest import TrackedContainer
from tests.run_command import run_command
LOGGER = logging.getLogger(__name__)
def test_spark_shell(container: TrackedContainer) -> None:
"""Checking if Spark (spark-shell) is running properly"""
logs = container.run_and_wait(
timeout=60,
tty=True,
command=["start.sh", "bash", "-c", 'spark-shell <<< "1+1"'],
)
logs = run_command(container, 'spark-shell <<< "1+1"', timeout=60)
assert "res0: Int = 2" in logs, "spark-shell does not work"

22
tests/run_command.py Normal file
View File

@@ -0,0 +1,22 @@
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
import logging
from tests.conftest import TrackedContainer
LOGGER = logging.getLogger(__name__)
def run_command(
container: TrackedContainer,
command: str,
timeout: int = 5,
) -> str:
"""Runs the given package manager with its version argument."""
LOGGER.info(f"Test that the command '{command}' is working properly ...")
return container.run_and_wait(
timeout=timeout,
tty=True,
command=["start.sh", "bash", "-c", command],
)