Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve check and test targets in Makefile #114

Merged
merged 2 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@ PACKAGE_NAME=nethsm
VENV=venv
PYTHON3=python3
PYTHON3_VENV=venv/bin/python3
FLAKE8_DIRS=$(PACKAGE_NAME)/
CHECK_DIRS=$(PACKAGE_NAME)/ tests/

all: init

init: update-venv

# code checks
check-format:
$(PYTHON3_VENV) -m black --check $(PACKAGE_NAME)/
$(PYTHON3_VENV) -m black --check $(CHECK_DIRS)

check-import-sorting:
$(PYTHON3_VENV) -m isort --check-only $(PACKAGE_NAME)/
$(PYTHON3_VENV) -m isort --check-only $(CHECK_DIRS)

check-style:
$(PYTHON3_VENV) -m flake8 $(FLAKE8_DIRS)
$(PYTHON3_VENV) -m flake8 $(CHECK_DIRS)

check-typing:
@echo "Note: run semi-clean target in case this fails without any proper reason"
$(PYTHON3_VENV) -m mypy $(PACKAGE_NAME)/ tests/
$(PYTHON3_VENV) -m mypy $(CHECK_DIRS)

check: check-format check-import-sorting check-style check-typing test

Expand All @@ -34,8 +33,8 @@ clean: semi-clean

# automatic code fixes
fix:
$(PYTHON3_VENV) -m black $(BLACK_FLAGS) $(PACKAGE_NAME)/ tests/
$(PYTHON3_VENV) -m isort $(ISORT_FLAGS) $(PACKAGE_NAME)/ tests/
$(PYTHON3_VENV) -m black $(BLACK_FLAGS) $(CHECK_DIRS)
$(PYTHON3_VENV) -m isort $(ISORT_FLAGS) $(CHECK_DIRS)

$(VENV):
$(PYTHON3) -m venv $(VENV)
Expand Down Expand Up @@ -67,4 +66,4 @@ nethsm-client: nethsm-api.yaml

.PHONY: test
test:
$(PYTHON3_VENV) -m pytest --cov nethsm --cov-report=xml
$(PYTHON3_VENV) -m pytest --cov nethsm --cov-report=xml $(PYTEST_FLAGS)
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass
from os import environ
from typing import TYPE_CHECKING, Iterator, Literal
from typing import TYPE_CHECKING, Iterator

import pytest

Expand Down
2 changes: 1 addition & 1 deletion tests/test_enums.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Callable, Protocol, Type
from typing import Any, Protocol, Type

import pytest

Expand Down
1 change: 0 additions & 1 deletion tests/test_nethsm_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import datetime
from io import BytesIO

import pytest
from conftest import Constants as C
Expand Down
1 change: 0 additions & 1 deletion tests/test_nethsm_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
KeyMechanism,
KeyType,
NetHSM,
RsaPrivateKey,
RsaPublicKey,
SignMode,
)
Expand Down
1 change: 0 additions & 1 deletion tests/test_nethsm_other.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Iterator

import docker # type: ignore
import pytest
from conftest import Constants as C
from utilities import Container, add_user, connect, lock, provision, unlock
Expand Down
7 changes: 4 additions & 3 deletions tests/test_nethsm_system.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import datetime
import os

import pytest
from conftest import Constants as C
from test_nethsm_keys import generate_key
from utilities import (
Expand All @@ -15,7 +14,7 @@
)

from nethsm import Base64, NetHSM, NetHSMError
from nethsm.backup import Backup, EncryptedBackup
from nethsm.backup import EncryptedBackup

"""######################### Preparation for the Tests #########################

Expand Down Expand Up @@ -147,7 +146,9 @@ def test_state_provision_update(container: Container, nethsm: NetHSM) -> None:
update(nethsm)


def test_state_provision_update_cancel_update(container: Container, nethsm: NetHSM) -> None:
def test_state_provision_update_cancel_update(
container: Container, nethsm: NetHSM
) -> None:
"""Cancel a queued update on a NetHSM instance.

This command requires authentication as a user with the Administrator
Expand Down
10 changes: 6 additions & 4 deletions tests/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import docker # type: ignore
import podman # type: ignore
import pytest
import urllib3
from conftest import Constants as C
from conftest import UserData
Expand All @@ -20,7 +19,6 @@
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives.serialization import Encoding
from cryptography.x509.oid import NameOID

import nethsm as nethsm_module
from nethsm import Authentication, Base64, NetHSM, RsaPrivateKey
Expand Down Expand Up @@ -56,7 +54,9 @@ def kill(self) -> None:


class DockerContainer(Container):
def __init__(self, client: docker.client.DockerClient, image: docker.models.images.Image) -> None:
def __init__(
self, client: docker.client.DockerClient, image: docker.models.images.Image
) -> None:
self.client = client
self.image = image
self.container = None
Expand All @@ -80,7 +80,9 @@ def kill(self) -> None:


class PodmanContainer(Container):
def __init__(self, client: podman.client.PodmanClient, image: podman.domain.images.Image) -> None:
def __init__(
self, client: podman.client.PodmanClient, image: podman.domain.images.Image
) -> None:
self.client = client
self.image = image
self.container = None
Expand Down
Loading