Skip to content

Commit e2be764

Browse files
alexph-devclaude
andcommitted
fix: resolve sonarcloud reliability issues
- Replace float == comparisons with pytest.approx() in tests - Use falsy check instead of == 0.0 for amounts in GL tree rendering - Rename shadowed parameter in _locked_refresh to avoid S1226 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 63c7725 commit e2be764

4 files changed

Lines changed: 12 additions & 12 deletions

File tree

‎qbo_cli/cli.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,11 @@ def _locked_refresh(self, tokens: dict) -> str:
355355
fcntl.flock(lock_file, fcntl.LOCK_EX)
356356
try:
357357
# Re-read — another process may have refreshed
358-
tokens = self.load()
359-
if time.time() < tokens["expires_at"] - REFRESH_MARGIN_SEC:
360-
return tokens["access_token"]
358+
current = self.load()
359+
if time.time() < current["expires_at"] - REFRESH_MARGIN_SEC:
360+
return current["access_token"]
361361

362-
new_tokens = self._do_refresh(tokens)
362+
new_tokens = self._do_refresh(current)
363363
self.save(new_tokens)
364364
return new_tokens["access_token"]
365365
finally:
@@ -1003,13 +1003,13 @@ def _build_report_lines(
10031003
section = _find_gl_section(section_idx, node["name"], node.get("id", ""))
10041004
amt = section.total_amount if section else 0.0
10051005
cnt = section.total_count if section else 0
1006-
if cnt == 0 and amt == 0.0:
1006+
if cnt == 0 and not amt:
10071007
return lines
10081008
lines.append(_pad_line(f"{node['name']} ({cnt})", _format_amount(amt, currency), prefix))
10091009
if expanded and section:
10101010
_append_txn_lines(section.all_transactions, currency, indent + 1, lines)
10111011
else:
1012-
if subtotal_cnt == 0 and subtotal_amt == 0.0:
1012+
if subtotal_cnt == 0 and not subtotal_amt:
10131013
return lines
10141014

10151015
section = _find_gl_section(section_idx, node["name"], node.get("id", ""))

‎tests/test_live_sandbox_crud.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,6 @@ def test_invoice_create_void_verify_delete():
319319

320320
# Verify voided state — Balance should be 0
321321
fetched = qbo_json("get", "Invoice", inv_id)
322-
assert float(fetched["Invoice"]["Balance"]) == 0.0
322+
assert float(fetched["Invoice"]["Balance"]) == pytest.approx(0.0)
323323
finally:
324324
qbo("delete", "Invoice", inv_id)

‎tests/test_parsing.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_valid_7col_row(self):
3434
assert txn.date == "2025-01-15"
3535
assert txn.txn_type == "Invoice"
3636
assert txn.txn_id == "5001"
37-
assert txn.amount == 5000.0
37+
assert txn.amount == pytest.approx(5000.0)
3838

3939
def test_beginning_balance_skip(self):
4040
cols = [{"value": "Beginning Balance"}]
@@ -177,7 +177,7 @@ def test_empty_tree(self):
177177
idx = {}
178178
node = {"name": "Missing", "id": "999", "children": []}
179179
amt, cnt = _compute_subtotal(idx, node)
180-
assert amt == 0.0
180+
assert amt == pytest.approx(0.0)
181181
assert cnt == 0
182182

183183

@@ -188,15 +188,15 @@ class TestGLSectionCachedProperty:
188188
def test_total_amount_leaf(self):
189189
s = GLSection("Test", "1")
190190
s.direct_amount = 100.0
191-
assert s.total_amount == 100.0
191+
assert s.total_amount == pytest.approx(100.0)
192192

193193
def test_total_amount_with_children(self):
194194
parent = GLSection("Parent", "1")
195195
parent.direct_amount = 50.0
196196
child = GLSection("Child", "2")
197197
child.direct_amount = 30.0
198198
parent.children = [child]
199-
assert parent.total_amount == 80.0
199+
assert parent.total_amount == pytest.approx(80.0)
200200

201201
def test_total_count(self):
202202
parent = GLSection("Parent", "1")

‎tests/test_pure.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def test_empty_fields(self):
213213
txn = GLTransaction(amount=0.0)
214214
d = _txn_to_dict(txn)
215215
assert d["date"] == ""
216-
assert d["amount"] == 0.0
216+
assert d["amount"] == pytest.approx(0.0)
217217

218218

219219
# ─── _collapse_tree ───────────────────────────────────────────────────────────

0 commit comments

Comments
 (0)