Skip to content

Commit

Permalink
feat(tests): skip tests if git crypt is locked
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-awd committed Nov 25, 2023
1 parent 5caec9e commit 6457971
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/integration/banks/test_banks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
from monopoly.constants import StatementFields
from monopoly.examples import MonopolyBank
from monopoly.statement import Statement
from tests.utils import skip_if_encrypted


@skip_if_encrypted
@pytest.mark.parametrize(
"bank_class, total_amount, statement_date",
[
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/test_auto_detect_bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from monopoly.banks import auto_detect_bank
from monopoly.banks.base import BankBase
from monopoly.constants import EncryptionIdentifier, MetadataIdentifier
from tests.utils import skip_if_encrypted


class MockBankOne(BankBase):
Expand Down Expand Up @@ -30,6 +31,7 @@ class MockBankTwo(BankBase):
encrypted_file_path = "tests/integration/fixtures/protected.pdf"


@skip_if_encrypted
def test_auto_detect_unencrypted_bank_identified(
monkeypatch, file_path: str = unencrypted_file_path
):
Expand All @@ -52,6 +54,7 @@ def test_auto_detect_encrypted_bank_identified(
assert isinstance(bank_instance, MockBankOne)


@skip_if_encrypted
def test_auto_detect_bank_not_identified(
monkeypatch, file_path: str = unencrypted_file_path
):
Expand Down
3 changes: 3 additions & 0 deletions tests/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .skip import skip_if_encrypted

__all__ = ["skip_if_encrypted"]
27 changes: 27 additions & 0 deletions tests/utils/skip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import logging
from functools import wraps

import pytest

logger = logging.getLogger(__name__)


def skip_if_encrypted(func=None):
"""Helper function to skip tests if files are not unlocked with `git-crypt`"""

@wraps(func)
def wrapper(*args, **kwargs):
try:
with open("tests/integration/banks/.gc_check") as f:
contents = f.read()
if contents != "unlocked":
raise UnicodeDecodeError("Invalid contents")
except UnicodeDecodeError as err:
logger.warning(err)
pytest.skip(
"Test requires decrypted files. "
"Please run 'git-crypt unlock <KEYFILE>'"
)
return func(*args, **kwargs)

return wrapper if func else skip_if_encrypted

0 comments on commit 6457971

Please sign in to comment.