Make tests a module and make imports absolute

This commit is contained in:
Ayaz Salikhov
2022-04-01 01:26:37 +01:00
parent 9d68c7d1d4
commit 0aa95c71ad
28 changed files with 60 additions and 41 deletions

View File

@@ -207,6 +207,6 @@ run-sudo-shell/%: ## run a bash in interactive mode as root in a stack
test/%: ## run tests against a stack test/%: ## run tests against a stack
@echo "::group::test/$(OWNER)/$(notdir $@)" @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::" @echo "::endgroup::"
test-all: $(foreach I, $(ALL_IMAGES), test/$(I)) ## test all stacks test-all: $(foreach I, $(ALL_IMAGES), test/$(I)) ## test all stacks

View File

@@ -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: `DockerRunner` is a helper class to easily run a docker container and execute commands inside this container:
```python ```python
from .docker_runner import DockerRunner from tagging.docker_runner import DockerRunner
with DockerRunner("ubuntu:bionic") as container: with DockerRunner("ubuntu:bionic") as container:
DockerRunner.run_simple_command(container, cmd="env", print_result=True) 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: `GitHelper` methods are run in the current `git` repo and give the information about last commit hash and commit message:
```python ```python
from .git_helper import GitHelper from tagging.git_helper import GitHelper
print("Git hash:", GitHelper.commit_hash()) print("Git hash:", GitHelper.commit_hash())
print("Git message:", GitHelper.commit_message()) 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: `SHATagger` example:
```python ```python
from tagging.git_helper import GitHelper
from tagging.taggers import import TaggerInterface
class SHATagger(TaggerInterface): class SHATagger(TaggerInterface):
@staticmethod @staticmethod
def tag_value(container): def tag_value(container):
@@ -96,6 +99,9 @@ class ManifestInterface:
`AptPackagesManifest` example: `AptPackagesManifest` example:
```python ```python
from tagging.manifests import ManifestInterface, quoted_output
class AptPackagesManifest(ManifestInterface): class AptPackagesManifest(ManifestInterface):
@staticmethod @staticmethod
def markdown_piece(container) -> str: def markdown_piece(container) -> str:

View File

@@ -8,10 +8,10 @@ import os
from docker.models.containers import Container from docker.models.containers import Container
from .docker_runner import DockerRunner from tagging.docker_runner import DockerRunner
from .get_taggers_and_manifests import get_taggers_and_manifests from tagging.get_taggers_and_manifests import get_taggers_and_manifests
from .git_helper import GitHelper from tagging.git_helper import GitHelper
from .manifests import ManifestHeader, ManifestInterface from tagging.manifests import ManifestHeader, ManifestInterface
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)

View File

@@ -2,9 +2,9 @@
# Distributed under the terms of the Modified BSD License. # Distributed under the terms of the Modified BSD License.
from typing import Optional from typing import Optional
from .images_hierarchy import ALL_IMAGES from tagging.images_hierarchy import ALL_IMAGES
from .manifests import ManifestInterface from tagging.manifests import ManifestInterface
from .taggers import TaggerInterface from tagging.taggers import TaggerInterface
def get_taggers_and_manifests( def get_taggers_and_manifests(

View File

@@ -3,7 +3,7 @@
from dataclasses import dataclass, field from dataclasses import dataclass, field
from typing import Optional from typing import Optional
from .manifests import ( from tagging.manifests import (
AptPackagesManifest, AptPackagesManifest,
CondaEnvironmentManifest, CondaEnvironmentManifest,
JuliaPackagesManifest, JuliaPackagesManifest,
@@ -11,7 +11,7 @@ from .manifests import (
RPackagesManifest, RPackagesManifest,
SparkInfoManifest, SparkInfoManifest,
) )
from .taggers import ( from tagging.taggers import (
DateTagger, DateTagger,
HadoopVersionTagger, HadoopVersionTagger,
JavaVersionTagger, JavaVersionTagger,

View File

@@ -3,8 +3,8 @@
import plumbum import plumbum
from docker.models.containers import Container from docker.models.containers import Container
from .docker_runner import DockerRunner from tagging.docker_runner import DockerRunner
from .git_helper import GitHelper from tagging.git_helper import GitHelper
docker = plumbum.local["docker"] docker = plumbum.local["docker"]

View File

@@ -6,9 +6,9 @@ import logging
import plumbum import plumbum
from .docker_runner import DockerRunner from tagging.docker_runner import DockerRunner
from .get_taggers_and_manifests import get_taggers_and_manifests from tagging.get_taggers_and_manifests import get_taggers_and_manifests
from .github_set_env import github_set_env from tagging.github_set_env import github_set_env
docker = plumbum.local["docker"] docker = plumbum.local["docker"]

View File

@@ -4,8 +4,8 @@ from datetime import datetime
from docker.models.containers import Container from docker.models.containers import Container
from .docker_runner import DockerRunner from tagging.docker_runner import DockerRunner
from .git_helper import GitHelper from tagging.git_helper import GitHelper
def _get_program_version(container: Container, program: str) -> str: def _get_program_version(container: Container, program: str) -> str:

0
tests/__init__.py Normal file
View File

View File

@@ -5,7 +5,8 @@ import logging
from pathlib import Path from pathlib import Path
import pytest # type: ignore import pytest # type: ignore
from conftest import TrackedContainer
from tests.conftest import TrackedContainer
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
THIS_DIR = Path(__file__).parent.resolve() THIS_DIR = Path(__file__).parent.resolve()

View File

@@ -6,7 +6,8 @@ import time
import pytest # type: ignore import pytest # type: ignore
import requests import requests
from conftest import TrackedContainer, find_free_port
from tests.conftest import TrackedContainer, find_free_port
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)

View File

@@ -3,7 +3,8 @@
import requests import requests
from conftest import TrackedContainer, find_free_port
from tests.conftest import TrackedContainer, find_free_port
def test_secured_server( def test_secured_server(

View File

@@ -4,8 +4,9 @@
import logging import logging
import pytest # type: ignore 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__) LOGGER = logging.getLogger(__name__)

View File

@@ -4,7 +4,8 @@
import logging import logging
import pytest # type: ignore import pytest # type: ignore
from conftest import TrackedContainer
from tests.conftest import TrackedContainer
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)

View File

@@ -41,8 +41,9 @@ import logging
from typing import Callable, Iterable from typing import Callable, Iterable
import pytest # type: ignore 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__) LOGGER = logging.getLogger(__name__)

View File

@@ -3,7 +3,7 @@
import logging import logging
from conftest import TrackedContainer from tests.conftest import TrackedContainer
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)

View File

@@ -2,9 +2,10 @@
# Distributed under the terms of the Modified BSD License. # Distributed under the terms of the Modified BSD License.
import logging import logging
from conftest import TrackedContainer
from packaging import version # type: ignore from packaging import version # type: ignore
from tests.conftest import TrackedContainer
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)

View File

@@ -7,7 +7,8 @@ from typing import Optional
import pytest # type: ignore import pytest # type: ignore
import requests import requests
from conftest import TrackedContainer, find_free_port
from tests.conftest import TrackedContainer, find_free_port
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)

View File

@@ -3,8 +3,8 @@
import logging import logging
from conftest import TrackedContainer from tests.conftest import TrackedContainer
from images_hierarchy import get_test_dirs from tests.images_hierarchy import get_test_dirs
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)

View File

@@ -2,7 +2,7 @@
# Distributed under the terms of the Modified BSD License. # Distributed under the terms of the Modified BSD License.
import logging import logging
from conftest import TrackedContainer from tests.conftest import TrackedContainer
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)

View File

@@ -3,7 +3,7 @@
import logging import logging
from conftest import TrackedContainer from tests.conftest import TrackedContainer
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)

View File

@@ -5,7 +5,8 @@ import logging
from pathlib import Path from pathlib import Path
import pytest # type: ignore import pytest # type: ignore
from conftest import TrackedContainer
from tests.conftest import TrackedContainer
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
THIS_DIR = Path(__file__).parent.resolve() THIS_DIR = Path(__file__).parent.resolve()

View File

@@ -29,10 +29,11 @@ from collections import defaultdict
from itertools import chain from itertools import chain
from typing import Any, Optional from typing import Any, Optional
from conftest import TrackedContainer
from docker.models.containers import Container from docker.models.containers import Container
from tabulate import tabulate from tabulate import tabulate
from tests.conftest import TrackedContainer
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)

View File

@@ -2,7 +2,7 @@
# Distributed under the terms of the Modified BSD License. # Distributed under the terms of the Modified BSD License.
import logging import logging
from conftest import TrackedContainer from tests.conftest import TrackedContainer
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)

View File

@@ -5,7 +5,8 @@ import argparse
import logging import logging
import plumbum import plumbum
from images_hierarchy import get_test_dirs
from tests.images_hierarchy import get_test_dirs
pytest = plumbum.local["pytest"] pytest = plumbum.local["pytest"]

View File

@@ -3,7 +3,7 @@
from pathlib import Path from pathlib import Path
from conftest import TrackedContainer from tests.conftest import TrackedContainer
THIS_DIR = Path(__file__).parent.resolve() THIS_DIR = Path(__file__).parent.resolve()

View File

@@ -3,7 +3,8 @@
import logging import logging
import pytest # type: ignore import pytest # type: ignore
from conftest import TrackedContainer
from tests.conftest import TrackedContainer
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)

View File

@@ -5,7 +5,8 @@ import logging
from pathlib import Path from pathlib import Path
import pytest # type: ignore import pytest # type: ignore
from conftest import TrackedContainer
from tests.conftest import TrackedContainer
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
THIS_DIR = Path(__file__).parent.resolve() THIS_DIR = Path(__file__).parent.resolve()