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