Skip to content

Commit

Permalink
Merge pull request #90 from isaacharrisholt/clear-flag
Browse files Browse the repository at this point in the history
Ignore `!Clear:AutoSwitch` lines
  • Loading branch information
isaacharrisholt authored May 26, 2024
2 parents c7823f1 + cb5addb commit f87abdd
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 84 deletions.
131 changes: 53 additions & 78 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "quiffen"
version = "2.0.10"
version = "2.0.11"
description = "Quiffen"
authors = ["Isaac Harris-Holt <[email protected]>"]
license = "GPL-3.0-or-later"
Expand Down
16 changes: 12 additions & 4 deletions quiffen/core/qif.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,20 @@ def parse(
continue

# Allow for comments and blank lines at the top of sections
# Also skip `!Clear:` lines to ignore flags such as `!Clear:AutoSwitch`
for i, line in enumerate(section_lines):
if (
not line.strip()
or line.strip().startswith("!Clear:")
or line[0] == "#"
):
continue

# Found the header line
header_line = line
if line.strip() and line[0] != "#":
line_number += i
section_lines = section_lines[i:]
break
line_number += i
section_lines = section_lines[i:]
break
else:
# Empty section
continue
Expand Down
6 changes: 6 additions & 0 deletions tests/test_files/test_clear_autoswitch.qif
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
!Clear:AutoSwitch
!Account
NMy Bank Account
D
TBank
^
16 changes: 16 additions & 0 deletions tests/test_qif.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def nonexistent_file():
return Path(__file__).parent / "test_files" / "nonexistent.qif"


@pytest.fixture
def qif_file_with_clear_autoswitch():
return Path(__file__).parent / "test_files" / "test_clear_autoswitch.qif"


def test_create_qif():
"""Test creating a Qif instance"""
qif = Qif()
Expand Down Expand Up @@ -1101,3 +1106,14 @@ def test_transaction_account_type_qif():
^
"""
)


def test_clear_autoswitch_ignored(qif_file_with_clear_autoswitch):
"""Tests that `!Clear:AutoSwitch` flag exported by Quicken and GNUCash
is ignored.
Relates to discussion #89.
"""
qif = Qif.parse(qif_file_with_clear_autoswitch)
assert len(qif.accounts) == 1
assert list(qif.accounts.keys()) == ["My Bank Account"]
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
requires =
tox>=4
envlist = py{38,39,310,311}, black, ruff, pyright, isort
envlist = py{38,39,310,311,312}, black, ruff, pyright, isort
isolated_build = true

[gh-actions]
Expand All @@ -10,6 +10,7 @@ python =
3.9: py39
3.10: py310
3.11: py311
3.12: py312

[testenv]
setenv =
Expand Down

0 comments on commit f87abdd

Please sign in to comment.