From 0aa95c71adcc756b32d66469121803629aa23ff3 Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Fri, 1 Apr 2022 01:26:37 +0100 Subject: [PATCH 1/2] Make tests a module and make imports absolute --- Makefile | 2 +- tagging/README.md | 10 ++++++++-- tagging/create_manifests.py | 8 ++++---- tagging/get_taggers_and_manifests.py | 6 +++--- tagging/images_hierarchy.py | 4 ++-- tagging/manifests.py | 4 ++-- tagging/tag_image.py | 6 +++--- tagging/taggers.py | 4 ++-- tests/__init__.py | 0 tests/all-spark-notebook/test_spark_notebooks.py | 3 ++- tests/base-notebook/test_container_options.py | 3 ++- tests/base-notebook/test_notebook.py | 3 ++- tests/base-notebook/test_outdated.py | 5 +++-- tests/base-notebook/test_package_managers.py | 3 ++- tests/base-notebook/test_packages.py | 5 +++-- tests/base-notebook/test_pandoc.py | 2 +- tests/base-notebook/test_python.py | 3 ++- tests/base-notebook/test_start_container.py | 3 ++- tests/base-notebook/test_units.py | 4 ++-- tests/datascience-notebook/test_julia.py | 2 +- tests/minimal-notebook/test_inkscape.py | 2 +- tests/minimal-notebook/test_nbconvert.py | 3 ++- tests/package_helper.py | 3 ++- tests/pyspark-notebook/test_spark.py | 2 +- tests/run_tests.py | 3 ++- tests/scipy-notebook/test_cython.py | 2 +- tests/scipy-notebook/test_extensions.py | 3 ++- tests/scipy-notebook/test_matplotlib.py | 3 ++- 28 files changed, 60 insertions(+), 41 deletions(-) create mode 100644 tests/__init__.py diff --git a/Makefile b/Makefile index b8155da7..7db7c236 100644 --- a/Makefile +++ b/Makefile @@ -207,6 +207,6 @@ run-sudo-shell/%: ## run a bash in interactive mode as root in a stack test/%: ## run tests against a stack @echo "::group::test/$(OWNER)/$(notdir $@)" - tests/run_tests.py --short-image-name "$(notdir $@)" --owner "$(OWNER)" + python3 -m tests.run_tests --short-image-name "$(notdir $@)" --owner "$(OWNER)" @echo "::endgroup::" test-all: $(foreach I, $(ALL_IMAGES), test/$(I)) ## test all stacks diff --git a/tagging/README.md b/tagging/README.md index 3ba12333..ee6a798b 100644 --- a/tagging/README.md +++ b/tagging/README.md @@ -27,7 +27,7 @@ In this section we will briefly describe source code in this folder and give exa `DockerRunner` is a helper class to easily run a docker container and execute commands inside this container: ```python -from .docker_runner import DockerRunner +from tagging.docker_runner import DockerRunner with DockerRunner("ubuntu:bionic") as container: DockerRunner.run_simple_command(container, cmd="env", print_result=True) @@ -38,7 +38,7 @@ with DockerRunner("ubuntu:bionic") as container: `GitHelper` methods are run in the current `git` repo and give the information about last commit hash and commit message: ```python -from .git_helper import GitHelper +from tagging.git_helper import GitHelper print("Git hash:", GitHelper.commit_hash()) print("Git message:", GitHelper.commit_message()) @@ -66,6 +66,9 @@ So, `tag_value(container)` method gets a docker container as an input and return `SHATagger` example: ```python +from tagging.git_helper import GitHelper +from tagging.taggers import import TaggerInterface + class SHATagger(TaggerInterface): @staticmethod def tag_value(container): @@ -96,6 +99,9 @@ class ManifestInterface: `AptPackagesManifest` example: ```python +from tagging.manifests import ManifestInterface, quoted_output + + class AptPackagesManifest(ManifestInterface): @staticmethod def markdown_piece(container) -> str: diff --git a/tagging/create_manifests.py b/tagging/create_manifests.py index c784bdf5..3771db1e 100755 --- a/tagging/create_manifests.py +++ b/tagging/create_manifests.py @@ -8,10 +8,10 @@ import os from docker.models.containers import Container -from .docker_runner import DockerRunner -from .get_taggers_and_manifests import get_taggers_and_manifests -from .git_helper import GitHelper -from .manifests import ManifestHeader, ManifestInterface +from tagging.docker_runner import DockerRunner +from tagging.get_taggers_and_manifests import get_taggers_and_manifests +from tagging.git_helper import GitHelper +from tagging.manifests import ManifestHeader, ManifestInterface LOGGER = logging.getLogger(__name__) diff --git a/tagging/get_taggers_and_manifests.py b/tagging/get_taggers_and_manifests.py index 2a882c1b..d41d7a86 100644 --- a/tagging/get_taggers_and_manifests.py +++ b/tagging/get_taggers_and_manifests.py @@ -2,9 +2,9 @@ # Distributed under the terms of the Modified BSD License. from typing import Optional -from .images_hierarchy import ALL_IMAGES -from .manifests import ManifestInterface -from .taggers import TaggerInterface +from tagging.images_hierarchy import ALL_IMAGES +from tagging.manifests import ManifestInterface +from tagging.taggers import TaggerInterface def get_taggers_and_manifests( diff --git a/tagging/images_hierarchy.py b/tagging/images_hierarchy.py index 9a68f97e..68f837fd 100644 --- a/tagging/images_hierarchy.py +++ b/tagging/images_hierarchy.py @@ -3,7 +3,7 @@ from dataclasses import dataclass, field from typing import Optional -from .manifests import ( +from tagging.manifests import ( AptPackagesManifest, CondaEnvironmentManifest, JuliaPackagesManifest, @@ -11,7 +11,7 @@ from .manifests import ( RPackagesManifest, SparkInfoManifest, ) -from .taggers import ( +from tagging.taggers import ( DateTagger, HadoopVersionTagger, JavaVersionTagger, diff --git a/tagging/manifests.py b/tagging/manifests.py index 5a475a38..7111cea8 100644 --- a/tagging/manifests.py +++ b/tagging/manifests.py @@ -3,8 +3,8 @@ import plumbum from docker.models.containers import Container -from .docker_runner import DockerRunner -from .git_helper import GitHelper +from tagging.docker_runner import DockerRunner +from tagging.git_helper import GitHelper docker = plumbum.local["docker"] diff --git a/tagging/tag_image.py b/tagging/tag_image.py index 4b020a74..55c614f2 100755 --- a/tagging/tag_image.py +++ b/tagging/tag_image.py @@ -6,9 +6,9 @@ import logging import plumbum -from .docker_runner import DockerRunner -from .get_taggers_and_manifests import get_taggers_and_manifests -from .github_set_env import github_set_env +from tagging.docker_runner import DockerRunner +from tagging.get_taggers_and_manifests import get_taggers_and_manifests +from tagging.github_set_env import github_set_env docker = plumbum.local["docker"] diff --git a/tagging/taggers.py b/tagging/taggers.py index a39334f5..de896f5f 100644 --- a/tagging/taggers.py +++ b/tagging/taggers.py @@ -4,8 +4,8 @@ from datetime import datetime from docker.models.containers import Container -from .docker_runner import DockerRunner -from .git_helper import GitHelper +from tagging.docker_runner import DockerRunner +from tagging.git_helper import GitHelper def _get_program_version(container: Container, program: str) -> str: diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/all-spark-notebook/test_spark_notebooks.py b/tests/all-spark-notebook/test_spark_notebooks.py index ee64dfb2..fb4a6cbc 100644 --- a/tests/all-spark-notebook/test_spark_notebooks.py +++ b/tests/all-spark-notebook/test_spark_notebooks.py @@ -5,7 +5,8 @@ import logging from pathlib import Path import pytest # type: ignore -from conftest import TrackedContainer + +from tests.conftest import TrackedContainer LOGGER = logging.getLogger(__name__) THIS_DIR = Path(__file__).parent.resolve() diff --git a/tests/base-notebook/test_container_options.py b/tests/base-notebook/test_container_options.py index 32c4658f..d60cc8bc 100644 --- a/tests/base-notebook/test_container_options.py +++ b/tests/base-notebook/test_container_options.py @@ -6,7 +6,8 @@ import time import pytest # type: ignore import requests -from conftest import TrackedContainer, find_free_port + +from tests.conftest import TrackedContainer, find_free_port LOGGER = logging.getLogger(__name__) diff --git a/tests/base-notebook/test_notebook.py b/tests/base-notebook/test_notebook.py index 3dd0cf66..c8288997 100644 --- a/tests/base-notebook/test_notebook.py +++ b/tests/base-notebook/test_notebook.py @@ -3,7 +3,8 @@ import requests -from conftest import TrackedContainer, find_free_port + +from tests.conftest import TrackedContainer, find_free_port def test_secured_server( diff --git a/tests/base-notebook/test_outdated.py b/tests/base-notebook/test_outdated.py index 26416545..72f6b3d0 100644 --- a/tests/base-notebook/test_outdated.py +++ b/tests/base-notebook/test_outdated.py @@ -4,8 +4,9 @@ import logging import pytest # type: ignore -from conftest import TrackedContainer -from package_helper import CondaPackageHelper + +from tests.conftest import TrackedContainer +from tests.package_helper import CondaPackageHelper LOGGER = logging.getLogger(__name__) diff --git a/tests/base-notebook/test_package_managers.py b/tests/base-notebook/test_package_managers.py index d613bf3c..d831b1e6 100644 --- a/tests/base-notebook/test_package_managers.py +++ b/tests/base-notebook/test_package_managers.py @@ -4,7 +4,8 @@ import logging import pytest # type: ignore -from conftest import TrackedContainer + +from tests.conftest import TrackedContainer LOGGER = logging.getLogger(__name__) diff --git a/tests/base-notebook/test_packages.py b/tests/base-notebook/test_packages.py index dea67b80..b31e927b 100644 --- a/tests/base-notebook/test_packages.py +++ b/tests/base-notebook/test_packages.py @@ -41,8 +41,9 @@ import logging from typing import Callable, Iterable import pytest # type: ignore -from conftest import TrackedContainer -from package_helper import CondaPackageHelper + +from tests.conftest import TrackedContainer +from tests.package_helper import CondaPackageHelper LOGGER = logging.getLogger(__name__) diff --git a/tests/base-notebook/test_pandoc.py b/tests/base-notebook/test_pandoc.py index e0909289..fa4fac9c 100644 --- a/tests/base-notebook/test_pandoc.py +++ b/tests/base-notebook/test_pandoc.py @@ -3,7 +3,7 @@ import logging -from conftest import TrackedContainer +from tests.conftest import TrackedContainer LOGGER = logging.getLogger(__name__) diff --git a/tests/base-notebook/test_python.py b/tests/base-notebook/test_python.py index 75db24ff..2561b164 100644 --- a/tests/base-notebook/test_python.py +++ b/tests/base-notebook/test_python.py @@ -2,9 +2,10 @@ # Distributed under the terms of the Modified BSD License. import logging -from conftest import TrackedContainer from packaging import version # type: ignore +from tests.conftest import TrackedContainer + LOGGER = logging.getLogger(__name__) diff --git a/tests/base-notebook/test_start_container.py b/tests/base-notebook/test_start_container.py index fffdf68f..97ba3191 100644 --- a/tests/base-notebook/test_start_container.py +++ b/tests/base-notebook/test_start_container.py @@ -7,7 +7,8 @@ from typing import Optional import pytest # type: ignore import requests -from conftest import TrackedContainer, find_free_port + +from tests.conftest import TrackedContainer, find_free_port LOGGER = logging.getLogger(__name__) diff --git a/tests/base-notebook/test_units.py b/tests/base-notebook/test_units.py index fcb7a503..e709fc0c 100644 --- a/tests/base-notebook/test_units.py +++ b/tests/base-notebook/test_units.py @@ -3,8 +3,8 @@ import logging -from conftest import TrackedContainer -from images_hierarchy import get_test_dirs +from tests.conftest import TrackedContainer +from tests.images_hierarchy import get_test_dirs LOGGER = logging.getLogger(__name__) diff --git a/tests/datascience-notebook/test_julia.py b/tests/datascience-notebook/test_julia.py index cb9411e0..d7526ea2 100644 --- a/tests/datascience-notebook/test_julia.py +++ b/tests/datascience-notebook/test_julia.py @@ -2,7 +2,7 @@ # Distributed under the terms of the Modified BSD License. import logging -from conftest import TrackedContainer +from tests.conftest import TrackedContainer LOGGER = logging.getLogger(__name__) diff --git a/tests/minimal-notebook/test_inkscape.py b/tests/minimal-notebook/test_inkscape.py index f3d7a6d8..7cdcf277 100644 --- a/tests/minimal-notebook/test_inkscape.py +++ b/tests/minimal-notebook/test_inkscape.py @@ -3,7 +3,7 @@ import logging -from conftest import TrackedContainer +from tests.conftest import TrackedContainer LOGGER = logging.getLogger(__name__) diff --git a/tests/minimal-notebook/test_nbconvert.py b/tests/minimal-notebook/test_nbconvert.py index 3c70794b..dabeba4d 100644 --- a/tests/minimal-notebook/test_nbconvert.py +++ b/tests/minimal-notebook/test_nbconvert.py @@ -5,7 +5,8 @@ import logging from pathlib import Path import pytest # type: ignore -from conftest import TrackedContainer + +from tests.conftest import TrackedContainer LOGGER = logging.getLogger(__name__) THIS_DIR = Path(__file__).parent.resolve() diff --git a/tests/package_helper.py b/tests/package_helper.py index 88738ba5..7524fe0a 100644 --- a/tests/package_helper.py +++ b/tests/package_helper.py @@ -29,10 +29,11 @@ from collections import defaultdict from itertools import chain from typing import Any, Optional -from conftest import TrackedContainer from docker.models.containers import Container from tabulate import tabulate +from tests.conftest import TrackedContainer + LOGGER = logging.getLogger(__name__) diff --git a/tests/pyspark-notebook/test_spark.py b/tests/pyspark-notebook/test_spark.py index 416fb099..da47e19f 100644 --- a/tests/pyspark-notebook/test_spark.py +++ b/tests/pyspark-notebook/test_spark.py @@ -2,7 +2,7 @@ # Distributed under the terms of the Modified BSD License. import logging -from conftest import TrackedContainer +from tests.conftest import TrackedContainer LOGGER = logging.getLogger(__name__) diff --git a/tests/run_tests.py b/tests/run_tests.py index f4594931..f464e17e 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -5,7 +5,8 @@ import argparse import logging import plumbum -from images_hierarchy import get_test_dirs + +from tests.images_hierarchy import get_test_dirs pytest = plumbum.local["pytest"] diff --git a/tests/scipy-notebook/test_cython.py b/tests/scipy-notebook/test_cython.py index e5e4e8ea..bf1c0ab5 100644 --- a/tests/scipy-notebook/test_cython.py +++ b/tests/scipy-notebook/test_cython.py @@ -3,7 +3,7 @@ from pathlib import Path -from conftest import TrackedContainer +from tests.conftest import TrackedContainer THIS_DIR = Path(__file__).parent.resolve() diff --git a/tests/scipy-notebook/test_extensions.py b/tests/scipy-notebook/test_extensions.py index ca2a5f4e..b77dc89f 100644 --- a/tests/scipy-notebook/test_extensions.py +++ b/tests/scipy-notebook/test_extensions.py @@ -3,7 +3,8 @@ import logging import pytest # type: ignore -from conftest import TrackedContainer + +from tests.conftest import TrackedContainer LOGGER = logging.getLogger(__name__) diff --git a/tests/scipy-notebook/test_matplotlib.py b/tests/scipy-notebook/test_matplotlib.py index 725f8a9e..b8807f8f 100644 --- a/tests/scipy-notebook/test_matplotlib.py +++ b/tests/scipy-notebook/test_matplotlib.py @@ -5,7 +5,8 @@ import logging from pathlib import Path import pytest # type: ignore -from conftest import TrackedContainer + +from tests.conftest import TrackedContainer LOGGER = logging.getLogger(__name__) THIS_DIR = Path(__file__).parent.resolve() From 96e111bb473780b4b40ef999b791aefae780016a Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Thu, 28 Apr 2022 16:45:07 +0100 Subject: [PATCH 2/2] Fix typo --- tagging/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tagging/README.md b/tagging/README.md index ee6a798b..34d7bcd7 100644 --- a/tagging/README.md +++ b/tagging/README.md @@ -67,7 +67,8 @@ So, `tag_value(container)` method gets a docker container as an input and return ```python from tagging.git_helper import GitHelper -from tagging.taggers import import TaggerInterface +from tagging.taggers import TaggerInterface + class SHATagger(TaggerInterface): @staticmethod