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

Skip tests if git crypt is locked #59

Merged
merged 2 commits into from
Nov 25, 2023
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
tests/integration/banks/**/input.pdf filter=git-crypt diff=git-crypt
tests/integration/banks/.gc_check filter=git-crypt diff=git-crypt
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ repository = "https://github.com/benjamin-awd/monopoly"
authors = ["benjamin-awd <[email protected]>"]
packages = [
{ include = "monopoly", from = "src" },
{ include = "test_utils", from = "tests" }
]
license = "MIT"
readme = "README.md"
Expand Down
Binary file added tests/integration/banks/.gc_check
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/integration/banks/test_banks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pandas as pd
import pytest
from pandas.testing import assert_frame_equal
from test_utils.skip import skip_if_encrypted

from monopoly.banks import Citibank, Dbs, Hsbc, Ocbc, StandardChartered
from monopoly.banks.base import BankBase
Expand All @@ -12,6 +13,7 @@
from monopoly.statement import Statement


@skip_if_encrypted
@pytest.mark.parametrize(
"bank_class, total_amount, statement_date",
[
Expand Down
3 changes: 3 additions & 0 deletions tests/test_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/test_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 ValueError("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
3 changes: 3 additions & 0 deletions tests/unit/test_auto_detect_bank.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pytest import raises
from test_utils.skip import skip_if_encrypted

from monopoly.banks import auto_detect_bank
from monopoly.banks.base import 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