From f1c843e786d283edd01821dc4da5e97ec1e56c15 Mon Sep 17 00:00:00 2001 From: Benjamin Dornel Date: Sun, 29 Oct 2023 22:23:00 +0800 Subject: [PATCH] refactor(tests): move bank PDF fixtures to same dir as test files --- .gitattributes | 2 +- .gitignore | 4 ++-- .../{fixtures => banks}/citibank/input.pdf | Bin .../{fixtures => banks}/citibank/raw.csv | 0 .../citibank/transformed.csv | 0 .../{fixtures => banks}/dbs/input.pdf | Bin .../{fixtures => banks}/dbs/raw.csv | 0 .../{fixtures => banks}/dbs/transformed.csv | 0 .../{fixtures => banks}/hsbc/input.pdf | Bin .../{fixtures => banks}/hsbc/raw.csv | 0 .../{fixtures => banks}/hsbc/transformed.csv | 0 .../{fixtures => banks}/ocbc/input.pdf | Bin .../{fixtures => banks}/ocbc/raw.csv | 0 .../{fixtures => banks}/ocbc/transformed.csv | 0 .../standard_chartered/input.pdf | Bin .../standard_chartered/raw.csv | 0 .../standard_chartered/transformed.csv | 0 tests/integration/banks/test_banks.py | 13 ++++++------- tests/integration/test_parser.py | 18 +++++++++++------- 19 files changed, 20 insertions(+), 17 deletions(-) rename tests/integration/{fixtures => banks}/citibank/input.pdf (100%) rename tests/integration/{fixtures => banks}/citibank/raw.csv (100%) rename tests/integration/{fixtures => banks}/citibank/transformed.csv (100%) rename tests/integration/{fixtures => banks}/dbs/input.pdf (100%) rename tests/integration/{fixtures => banks}/dbs/raw.csv (100%) rename tests/integration/{fixtures => banks}/dbs/transformed.csv (100%) rename tests/integration/{fixtures => banks}/hsbc/input.pdf (100%) rename tests/integration/{fixtures => banks}/hsbc/raw.csv (100%) rename tests/integration/{fixtures => banks}/hsbc/transformed.csv (100%) rename tests/integration/{fixtures => banks}/ocbc/input.pdf (100%) rename tests/integration/{fixtures => banks}/ocbc/raw.csv (100%) rename tests/integration/{fixtures => banks}/ocbc/transformed.csv (100%) rename tests/integration/{fixtures => banks}/standard_chartered/input.pdf (100%) rename tests/integration/{fixtures => banks}/standard_chartered/raw.csv (100%) rename tests/integration/{fixtures => banks}/standard_chartered/transformed.csv (100%) diff --git a/.gitattributes b/.gitattributes index 6e5b05df..e5cc0d0c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -tests/integration/fixtures/**/input.pdf filter=git-crypt diff=git-crypt +tests/integration/banks/**/input.pdf filter=git-crypt diff=git-crypt diff --git a/.gitignore b/.gitignore index 14a529a6..a9ec0b18 100644 --- a/.gitignore +++ b/.gitignore @@ -15,8 +15,8 @@ _ignore* *.txt # allowed pdf files/fixtures -!tests/integration/fixtures/*/** -!tests/integration/fixtures/*.pdf +!tests/integration/banks/**/*.csv +!tests/integration/banks/**/*.pdf !monopoly/examples/*.pdf # john files diff --git a/tests/integration/fixtures/citibank/input.pdf b/tests/integration/banks/citibank/input.pdf similarity index 100% rename from tests/integration/fixtures/citibank/input.pdf rename to tests/integration/banks/citibank/input.pdf diff --git a/tests/integration/fixtures/citibank/raw.csv b/tests/integration/banks/citibank/raw.csv similarity index 100% rename from tests/integration/fixtures/citibank/raw.csv rename to tests/integration/banks/citibank/raw.csv diff --git a/tests/integration/fixtures/citibank/transformed.csv b/tests/integration/banks/citibank/transformed.csv similarity index 100% rename from tests/integration/fixtures/citibank/transformed.csv rename to tests/integration/banks/citibank/transformed.csv diff --git a/tests/integration/fixtures/dbs/input.pdf b/tests/integration/banks/dbs/input.pdf similarity index 100% rename from tests/integration/fixtures/dbs/input.pdf rename to tests/integration/banks/dbs/input.pdf diff --git a/tests/integration/fixtures/dbs/raw.csv b/tests/integration/banks/dbs/raw.csv similarity index 100% rename from tests/integration/fixtures/dbs/raw.csv rename to tests/integration/banks/dbs/raw.csv diff --git a/tests/integration/fixtures/dbs/transformed.csv b/tests/integration/banks/dbs/transformed.csv similarity index 100% rename from tests/integration/fixtures/dbs/transformed.csv rename to tests/integration/banks/dbs/transformed.csv diff --git a/tests/integration/fixtures/hsbc/input.pdf b/tests/integration/banks/hsbc/input.pdf similarity index 100% rename from tests/integration/fixtures/hsbc/input.pdf rename to tests/integration/banks/hsbc/input.pdf diff --git a/tests/integration/fixtures/hsbc/raw.csv b/tests/integration/banks/hsbc/raw.csv similarity index 100% rename from tests/integration/fixtures/hsbc/raw.csv rename to tests/integration/banks/hsbc/raw.csv diff --git a/tests/integration/fixtures/hsbc/transformed.csv b/tests/integration/banks/hsbc/transformed.csv similarity index 100% rename from tests/integration/fixtures/hsbc/transformed.csv rename to tests/integration/banks/hsbc/transformed.csv diff --git a/tests/integration/fixtures/ocbc/input.pdf b/tests/integration/banks/ocbc/input.pdf similarity index 100% rename from tests/integration/fixtures/ocbc/input.pdf rename to tests/integration/banks/ocbc/input.pdf diff --git a/tests/integration/fixtures/ocbc/raw.csv b/tests/integration/banks/ocbc/raw.csv similarity index 100% rename from tests/integration/fixtures/ocbc/raw.csv rename to tests/integration/banks/ocbc/raw.csv diff --git a/tests/integration/fixtures/ocbc/transformed.csv b/tests/integration/banks/ocbc/transformed.csv similarity index 100% rename from tests/integration/fixtures/ocbc/transformed.csv rename to tests/integration/banks/ocbc/transformed.csv diff --git a/tests/integration/fixtures/standard_chartered/input.pdf b/tests/integration/banks/standard_chartered/input.pdf similarity index 100% rename from tests/integration/fixtures/standard_chartered/input.pdf rename to tests/integration/banks/standard_chartered/input.pdf diff --git a/tests/integration/fixtures/standard_chartered/raw.csv b/tests/integration/banks/standard_chartered/raw.csv similarity index 100% rename from tests/integration/fixtures/standard_chartered/raw.csv rename to tests/integration/banks/standard_chartered/raw.csv diff --git a/tests/integration/fixtures/standard_chartered/transformed.csv b/tests/integration/banks/standard_chartered/transformed.csv similarity index 100% rename from tests/integration/fixtures/standard_chartered/transformed.csv rename to tests/integration/banks/standard_chartered/transformed.csv diff --git a/tests/integration/banks/test_banks.py b/tests/integration/banks/test_banks.py index 9fdff42b..c0b8cb1f 100644 --- a/tests/integration/banks/test_banks.py +++ b/tests/integration/banks/test_banks.py @@ -1,4 +1,5 @@ from datetime import datetime +from pathlib import Path import pandas as pd import pytest @@ -22,13 +23,11 @@ ) def test_bank_operations(bank_class: BankBase, total_amount, statement_date): bank_name = bank_class.statement_config.bank_name - bank: BankBase = bank_class( - file_path=f"tests/integration/fixtures/{bank_name}/input.pdf" - ) - raw_data = pd.read_csv(f"tests/integration/fixtures/{bank_name}/raw.csv") - transformed_data = pd.read_csv( - f"tests/integration/fixtures/{bank_name}/transformed.csv" - ) + + fixture_directory = Path(__file__).parent / bank_name + bank: BankBase = bank_class(fixture_directory / "input.pdf") + raw_data = pd.read_csv(fixture_directory / "raw.csv") + transformed_data = pd.read_csv(fixture_directory / "transformed.csv") # Check extracted data is correct statement: Statement = bank.extract() diff --git a/tests/integration/test_parser.py b/tests/integration/test_parser.py index 143fe9c0..4f6b3072 100644 --- a/tests/integration/test_parser.py +++ b/tests/integration/test_parser.py @@ -1,12 +1,16 @@ +from pathlib import Path + from pytest import raises from monopoly.banks import Hsbc from monopoly.config import BruteForceConfig from monopoly.pdf import PdfParser +fixture_directory = Path(__file__).parent / "fixtures" + def test_can_open_protected(parser: PdfParser): - parser.file_path = "tests/integration/fixtures/protected.pdf" + parser.file_path = fixture_directory / "protected.pdf" parser.password = "foobar123" parser.open() @@ -14,13 +18,13 @@ def test_can_open_protected(parser: PdfParser): def test_can_brute_force_open_protected(parser: PdfParser): brute_force_config = BruteForceConfig("foobar", "?d?d?d") - parser.file_path = "tests/integration/fixtures/protected.pdf" + parser.file_path = fixture_directory / "protected.pdf" parser.open(brute_force_config) def test_wrong_password_raises_error(parser: PdfParser): - parser.file_path = "tests/integration/fixtures/protected.pdf" + parser.file_path = fixture_directory / "protected.pdf" parser.password = "wrong_pw" with raises(ValueError, match="Wrong password"): @@ -28,7 +32,7 @@ def test_wrong_password_raises_error(parser: PdfParser): def test_get_pages(parser: PdfParser): - parser.file_path = "tests/integration/fixtures/4_pages_blank.pdf" + parser.file_path = fixture_directory / "4_pages_blank.pdf" parser.page_range = slice(0, -1) pages = parser.get_pages() @@ -36,7 +40,7 @@ def test_get_pages(parser: PdfParser): def test_get_pages_invalid_returns_error(parser: PdfParser): - parser.file_path = "tests/integration/fixtures/4_pages_blank.pdf" + parser.file_path = fixture_directory / "4_pages_blank.pdf" parser.page_range = slice(99, -99) with raises(ValueError, match="bad page number"): @@ -44,7 +48,7 @@ def test_get_pages_invalid_returns_error(parser: PdfParser): def test_override_password(hsbc: Hsbc): - hsbc = Hsbc("tests/integration/fixtures/protected.pdf", password="foobar123") + hsbc = Hsbc(fixture_directory / "protected.pdf", password="foobar123") document = hsbc.open() assert not document.is_encrypted @@ -52,5 +56,5 @@ def test_override_password(hsbc: Hsbc): def test_error_raised_if_override_is_wrong(): with raises(ValueError, match="Wrong password"): - hsbc = Hsbc("tests/integration/fixtures/protected.pdf", password="wrongpw") + hsbc = Hsbc(fixture_directory / "protected.pdf", password="wrongpw") hsbc.open()