Skip to content

Commit

Permalink
test(RHTAPWATCH-643): Adding python tests to CI
Browse files Browse the repository at this point in the history
Signed-off-by: Yftach Herzog <[email protected]>
  • Loading branch information
yftacherzog committed Dec 6, 2023
1 parent 233875f commit 3ea577b
Show file tree
Hide file tree
Showing 11 changed files with 285 additions and 2 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: tests

on:
pull_request:
branches: [ main ]
jobs:
test:
permissions:
checks: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.11
- name: Install pipenv
run: pip install pipenv==2023.7.23
- name: Create virtualenv
run: pipenv sync
- name: Run tests
run: |
pipenv run pytest tests
18 changes: 18 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
pytest = "*"
black = "*"
mypy = "*"
pylint = "*"
isort = "*"

[dev-packages]

[requires]
python_version = "3.11"

[scripts]
198 changes: 198 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions compose_generator/compose_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ComposeGenerator:
:param requestor: an object to request a new composed
:param fetcher: an object to fetch a compose once it's ready
"""

configurations_generator: ComposeConfigurationsGenerator
requestor: ComposeRequester
fetcher: ComposeFetcher
Expand Down
4 changes: 2 additions & 2 deletions compose_generator/odcs_compose_generator.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3

from .compose_generator import ComposeGenerator
from .odcs_configurations_generator import ODCSConfigurationsGenerator
from .odcs_fetcher import ODCSFetcher
from .odcs_requester import ODCSRequester
from .odcs_configurations_generator import ODCSConfigurationsGenerator
from .compose_generator import ComposeGenerator


def main():
Expand Down
1 change: 1 addition & 0 deletions compose_generator/odcs_configurations_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ODCSConfigurationsGenerator(ComposeConfigurationsGenerator):
:param container_data: data loaded from container.yaml
:param content_sets_data: data loaded from content_sets.yaml
"""

container_data: dict
content_sets_data: dict

Expand Down
2 changes: 2 additions & 0 deletions compose_generator/odcs_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ODCSResultReference(ComposeReference):
"""
Reference to a locally-stored compose result
"""

compose_path: Path


Expand All @@ -17,5 +18,6 @@ class ODCSFetcher(ComposeFetcher):
"""
Fetch ODCS compose based on a remote compose-reference and store it locally
"""

def __call__(self, request_reference: ComposeReference) -> ODCSResultReference:
raise NotImplementedError()
2 changes: 2 additions & 0 deletions compose_generator/odcs_requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ODCSRequestReference(ComposeReference):
"""
Reference to a remotely-stored compose data
"""

compose_url: str


Expand All @@ -17,5 +18,6 @@ class ODCSRequester(ComposeRequester):
Request a new ODCS compose based on compose configurations and return a reference
to the remote compose location.
"""

def __call__(self, configs: ComposeConfigurations) -> ODCSRequestReference:
raise NotImplementedError()
2 changes: 2 additions & 0 deletions compose_generator/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ComposeConfigurationsGenerator(Protocol):
"""
Generate compose configurations
"""

def __call__(self) -> ComposeConfigurations:
pass

Expand All @@ -25,6 +26,7 @@ class ComposeRequester(Protocol):
"""
Given compose configurations, return a remote compose reference
"""

def __call__(self, configs: ComposeConfigurations) -> ComposeReference:
pass

Expand Down
11 changes: 11 additions & 0 deletions format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash -ex

main() {
local pkgs=("tests" "compose_generator")
pipenv run isort --profile black "${pkgs[@]}"
pipenv run black "${pkgs[@]}"
}

if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
main "$@"
fi
25 changes: 25 additions & 0 deletions tests/test_static_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Static checks"""
from subprocess import run
from typing import Final

PKGS: Final[list[str]] = ["tests"]


def test_mypy() -> None:
"""Static Type check"""
run(["mypy"] + PKGS, check=True)


def test_isort() -> None:
"""Imports formatting check"""
run(["isort", "--check", "--profile", "black"] + PKGS, check=True)


def test_black() -> None:
"""Formatting check"""
run(["black", "--check"] + PKGS, check=True)


def test_pylint() -> None:
"""Lint check"""
run(["pylint"] + PKGS, check=True)

0 comments on commit 3ea577b

Please sign in to comment.