Skip to content

Commit

Permalink
Reintroducing support for Python 3.7 and 3.8 (#70)
Browse files Browse the repository at this point in the history
Merge of commits with the following commit messages:

* Attempted fix of importlib
* Removed walrus operator
* Fix for mypy in 3.7 and 3.8
* Another attempt to fix mypy
* Another attempt to fix mypy number 2

Fixes #69
  • Loading branch information
hbldh authored Apr 29, 2024
1 parent 21a25d2 commit 1be8aab
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.9, '3.10', '3.11', '3.12']
python-version: [3.7, 3.8, 3.9, '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v4

Expand Down
11 changes: 8 additions & 3 deletions bankid/certutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
"""

import os
import sys
import subprocess
from typing import Tuple, Union

import pathlib
import importlib.resources
if sys.version_info < (3, 9):
import importlib_resources as impres
else:
import importlib.resources as impres

from bankid.certs import get_test_cert_p12
from bankid.exceptions import BankIDError
Expand All @@ -19,7 +23,7 @@


def resolve_cert_path(file: str) -> pathlib.Path:
path = importlib.resources.files("bankid.certs").joinpath(file)
path = impres.files("bankid.certs").joinpath(file)
assert isinstance(path, pathlib.Path)
return path

Expand All @@ -37,7 +41,8 @@ def create_bankid_test_server_cert_and_key(destination_path: str = ".") -> Tuple
:rtype: tuple
"""
if test_cert_file := os.getenv("TEST_CERT_FILE"):
test_cert_file = os.getenv("TEST_CERT_FILE")
if test_cert_file is not None:
certificate, key = split_certificate(
test_cert_file, destination_path, password=_TEST_CERT_PASSWORD
)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
httpx
importlib_resources; python_version < "3.9"
11 changes: 9 additions & 2 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from collections import namedtuple
import sys
from typing import Union

import pytest

import bankid

if sys.version_info >= (3, 9):
from builtins import type as Type
else:
# Remove once PyBankID no longer support Python 3.8 or lower
from typing import Type


@pytest.mark.parametrize(
"exception_class,rfa",
Expand All @@ -19,7 +26,7 @@
(bankid.exceptions.BankIDError, None),
],
)
def test_exceptions(exception_class: type[Exception], rfa: Union[int, None]) -> None:
def test_exceptions(exception_class: Type[Exception], rfa: Union[int, None]) -> None:
e = exception_class()
assert isinstance(e, bankid.exceptions.BankIDError)
assert e.rfa == rfa
Expand All @@ -38,7 +45,7 @@ def test_exceptions(exception_class: type[Exception], rfa: Union[int, None]) ->
(bankid.exceptions.BankIDError, "Unknown error code"),
],
)
def test_error_class_factory(exception_class: type[Exception], error_code: str) -> None:
def test_error_class_factory(exception_class: Type[Exception], error_code: str) -> None:
MockResponse = namedtuple("MockResponse", ["json"])
response = MockResponse(json=lambda: {"errorCode": error_code})
# error: Argument 1 to "get_json_error_class" has incompatible type "MockResponse@41"; expected "Response" [arg-type]
Expand Down

0 comments on commit 1be8aab

Please sign in to comment.