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

refactor(tests): separate tests into unit and integration #16

Merged
merged 1 commit into from
Oct 8, 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
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
tests/fixtures/**/input.pdf filter=git-crypt diff=git-crypt
tests/integration/fixtures/**/input.pdf filter=git-crypt diff=git-crypt
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ _ignore*
*.tfvars

# allowed pdf files/fixtures
!tests/fixtures/*/**
!tests/fixtures/*.pdf
!tests/integration/fixtures/*/**
!tests/integration/fixtures/*.pdf
!monopoly/examples/*.pdf

# john files
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@

@pytest.fixture(scope="session")
def citibank():
citibank = Citibank(file_path="tests/fixtures/citibank/input.pdf")
citibank = Citibank(file_path="tests/integration/fixtures/citibank/input.pdf")
yield citibank


@pytest.fixture(scope="session")
def ocbc():
ocbc = Ocbc(file_path="tests/fixtures/ocbc/input.pdf")
ocbc = Ocbc(file_path="tests/integration/fixtures/ocbc/input.pdf")
yield ocbc


@pytest.fixture(scope="session")
def hsbc():
hsbc = Hsbc(file_path="tests/fixtures/hsbc/input.pdf")
hsbc = Hsbc(file_path="tests/integration/fixtures/hsbc/input.pdf")
yield hsbc


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def test_citibank_extract_unprotected_pdf(citibank: Citibank):
raw_df = citibank.extract().df
expected_df = pd.read_csv("tests/fixtures/citibank/expected.csv")
expected_df = pd.read_csv("tests/integration/fixtures/citibank/expected.csv")

assert_frame_equal(raw_df, expected_df)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def test_hsbc_extract_unprotected_pdf(hsbc: Hsbc):
raw_df = hsbc.extract().df
expected_df = pd.read_csv("tests/fixtures/hsbc/expected.csv")
expected_df = pd.read_csv("tests/integration/fixtures/hsbc/expected.csv")

assert_frame_equal(raw_df, expected_df)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def test_ocbc_extract_unprotected_pdf(ocbc: Ocbc):
raw_df = ocbc.extract().df

expected_df = pd.read_csv("tests/fixtures/ocbc/expected.csv")
expected_df = pd.read_csv("tests/integration/fixtures/ocbc/expected.csv")

assert_frame_equal(raw_df, expected_df)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Test for entrypoint used by Cloud Run"""
from unittest.mock import Mock, PropertyMock, patch

import pytest
Expand Down
10 changes: 5 additions & 5 deletions tests/test_parser.py → tests/integration/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@


def test_can_open_protected(parser: PdfParser):
parser.file_path = "tests/fixtures/protected.pdf"
parser.file_path = "tests/integration/fixtures/protected.pdf"
parser.password = "foobar123"

parser.open()


def test_wrong_password_raises_error(parser: PdfParser):
parser.file_path = "tests/fixtures/protected.pdf"
parser.file_path = "tests/integration/fixtures/protected.pdf"
parser.password = "wrong_pw"

with pytest.raises(ValueError, match="document is encrypted"):
parser.open()


def test_get_pages(parser: PdfParser):
parser.file_path = "tests/fixtures/4_pages_blank.pdf"
parser.file_path = "tests/integration/fixtures/4_pages_blank.pdf"
parser.page_range = slice(0, -1)

pages = parser.get_pages()
assert len(pages) == 3


def test_get_pages_invalid_returns_error(parser: PdfParser):
parser.file_path = "tests/fixtures/4_pages_blank.pdf"
parser.file_path = "tests/integration/fixtures/4_pages_blank.pdf"
parser.page_range = slice(99, -99)

with pytest.raises(ValueError, match="bad page number"):
Expand All @@ -36,7 +36,7 @@ def test_get_pages_invalid_returns_error(parser: PdfParser):

def test_pdf_unlock(parser: PdfParser):
password = parser.unlock_pdf(
pdf_file_path="tests/fixtures/protected.pdf",
pdf_file_path="tests/integration/fixtures/protected.pdf",
static_string="foobar",
mask="?d?d?d",
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.