Skip to content

Commit f87abdd

Browse files
Merge pull request #90 from isaacharrisholt/clear-flag
Ignore `!Clear:AutoSwitch` lines
2 parents c7823f1 + cb5addb commit f87abdd

File tree

6 files changed

+90
-84
lines changed

6 files changed

+90
-84
lines changed

poetry.lock

Lines changed: 53 additions & 78 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "quiffen"
3-
version = "2.0.10"
3+
version = "2.0.11"
44
description = "Quiffen"
55
authors = ["Isaac Harris-Holt <isaac@harris-holt.com>"]
66
license = "GPL-3.0-or-later"

quiffen/core/qif.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,20 @@ def parse(
160160
continue
161161

162162
# Allow for comments and blank lines at the top of sections
163+
# Also skip `!Clear:` lines to ignore flags such as `!Clear:AutoSwitch`
163164
for i, line in enumerate(section_lines):
165+
if (
166+
not line.strip()
167+
or line.strip().startswith("!Clear:")
168+
or line[0] == "#"
169+
):
170+
continue
171+
172+
# Found the header line
164173
header_line = line
165-
if line.strip() and line[0] != "#":
166-
line_number += i
167-
section_lines = section_lines[i:]
168-
break
174+
line_number += i
175+
section_lines = section_lines[i:]
176+
break
169177
else:
170178
# Empty section
171179
continue
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
!Clear:AutoSwitch
2+
!Account
3+
NMy Bank Account
4+
D
5+
TBank
6+
^

tests/test_qif.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ def nonexistent_file():
3939
return Path(__file__).parent / "test_files" / "nonexistent.qif"
4040

4141

42+
@pytest.fixture
43+
def qif_file_with_clear_autoswitch():
44+
return Path(__file__).parent / "test_files" / "test_clear_autoswitch.qif"
45+
46+
4247
def test_create_qif():
4348
"""Test creating a Qif instance"""
4449
qif = Qif()
@@ -1101,3 +1106,14 @@ def test_transaction_account_type_qif():
11011106
^
11021107
"""
11031108
)
1109+
1110+
1111+
def test_clear_autoswitch_ignored(qif_file_with_clear_autoswitch):
1112+
"""Tests that `!Clear:AutoSwitch` flag exported by Quicken and GNUCash
1113+
is ignored.
1114+
1115+
Relates to discussion #89.
1116+
"""
1117+
qif = Qif.parse(qif_file_with_clear_autoswitch)
1118+
assert len(qif.accounts) == 1
1119+
assert list(qif.accounts.keys()) == ["My Bank Account"]

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tox]
22
requires =
33
tox>=4
4-
envlist = py{38,39,310,311}, black, ruff, pyright, isort
4+
envlist = py{38,39,310,311,312}, black, ruff, pyright, isort
55
isolated_build = true
66

77
[gh-actions]
@@ -10,6 +10,7 @@ python =
1010
3.9: py39
1111
3.10: py310
1212
3.11: py311
13+
3.12: py312
1314

1415
[testenv]
1516
setenv =

0 commit comments

Comments
 (0)