mirror of
https://github.com/scito/extract_otp_secrets.git
synced 2025-12-16 23:30:48 +01:00
use PathLike type instead of str | Path
This commit is contained in:
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@@ -49,5 +49,5 @@ jobs:
|
||||
mypy --install-types --non-interactive *.py
|
||||
mypy --strict *.py
|
||||
if: matrix.python-version == '3.x'
|
||||
- name: Test with pytest
|
||||
run: pytest
|
||||
- name: Test with pytest (with code coverage)
|
||||
run: pytest --cov=test_extract_otp_secret_keys_pytest
|
||||
|
||||
2
Pipfile
2
Pipfile
@@ -12,6 +12,8 @@ opencv-python = "*"
|
||||
|
||||
[dev-packages]
|
||||
pytest = "*"
|
||||
pytest-mock = "*"
|
||||
pytest-cov = "*"
|
||||
wheel = "*"
|
||||
flake8 = "*"
|
||||
pylint = "*"
|
||||
|
||||
@@ -76,10 +76,11 @@ Exception: {e}""")
|
||||
except ImportError:
|
||||
qreader_available = False
|
||||
|
||||
# TODO Workaround for PYTHON < 3.10: Union[int, None] used instead of int | None
|
||||
|
||||
# Types
|
||||
Args = argparse.Namespace
|
||||
OtpUrl = str
|
||||
# Workaround for PYTHON < 3.10: use Union[int, None] instead of int | None
|
||||
Otp = TypedDict('Otp', {'name': str, 'secret': str, 'issuer': str, 'type': str, 'counter': Union[int, None], 'url': OtpUrl})
|
||||
Otps = list[Otp]
|
||||
OtpUrls = list[OtpUrl]
|
||||
|
||||
@@ -3,5 +3,6 @@ pytest
|
||||
flake8
|
||||
pylint
|
||||
pytest-mock
|
||||
pytest-cov
|
||||
mypy
|
||||
types-protobuf
|
||||
|
||||
@@ -238,11 +238,11 @@ eval "$cmd"
|
||||
|
||||
# Test
|
||||
|
||||
cmd="pytest"
|
||||
cmd="pytest --cov=test_extract_otp_secret_keys_pytest"
|
||||
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||
eval "$cmd"
|
||||
|
||||
cmd="$PIPENV run pytest"
|
||||
cmd="$PIPENV run pytest --cov=test_extract_otp_secret_keys_pytest"
|
||||
if $interactive ; then askContinueYn "$cmd"; else echo -e "${cyan}$cmd${reset}";fi
|
||||
eval "$cmd"
|
||||
|
||||
|
||||
13
utils.py
13
utils.py
@@ -22,7 +22,12 @@ import re
|
||||
import shutil
|
||||
import sys
|
||||
import pathlib
|
||||
from typing import BinaryIO, Any
|
||||
from typing import BinaryIO, Any, Union
|
||||
|
||||
|
||||
# Types
|
||||
# PYTHON < 3.10: Workaround for str | pathlib.Path
|
||||
PathLike = Union[str, pathlib.Path]
|
||||
|
||||
|
||||
# Ref. https://stackoverflow.com/a/16571630
|
||||
@@ -50,11 +55,11 @@ with Capturing() as output:
|
||||
sys.stderr = self._stderr
|
||||
|
||||
|
||||
def file_exits(file: str | pathlib.Path) -> bool:
|
||||
def file_exits(file: PathLike) -> bool:
|
||||
return os.path.isfile(file)
|
||||
|
||||
|
||||
def remove_file(file: str | pathlib.Path) -> None:
|
||||
def remove_file(file: PathLike) -> None:
|
||||
if file_exits(file): os.remove(file)
|
||||
|
||||
|
||||
@@ -63,7 +68,7 @@ def remove_files(glob_pattern: str) -> None:
|
||||
os.remove(f)
|
||||
|
||||
|
||||
def remove_dir_with_files(dir: str | pathlib.Path) -> None:
|
||||
def remove_dir_with_files(dir: PathLike) -> None:
|
||||
if os.path.exists(dir): shutil.rmtree(dir)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user