Skip to content

"Vibe-Trading: Your Personal Trading Agent"

style(grounding): apply minimal formatting to matrix parser tests

zeus2291f40af58de7c
diff --git a/agent/src/agent/grounding/figures.py b/agent/src/agent/grounding/figures.py
index 6652e7070..95eda7b4a 100644
--- a/agent/src/agent/grounding/figures.py
+++ b/agent/src/agent/grounding/figures.py
@@ -808,8 +808,10 @@ def table_rows(content: str) -> list[TableRow]:
body = [cells for cells in body if cells and not _is_separator_row(cells)]
row_axis = [
re.sub(r"^(?:\*\*|__)(.*?)(?:\*\*|__)$", r"\1", cells[0][0])
- .strip().upper()
- for cells in body if len(cells) == len(headers)
+ .strip()
+ .upper()
+ for cells in body
+ if len(cells) == len(headers)
]
if (
len(body) == len(axis) == len(row_axis)
@@ -825,7 +827,15 @@ def table_rows(content: str) -> list[TableRow]:
if not cells or _is_separator_row(cells):
continue
rows.append(
- TableRow(line_index, tuple(cells), columns, date_column, symbol_column, table, tuple(headers))
+ TableRow(
+ line_index,
+ tuple(cells),
+ columns,
+ date_column,
+ symbol_column,
+ table,
+ tuple(headers),
+ )
)
table += 1
return rows
@@ -1124,7 +1134,9 @@ def scan_figures(content: str, block: FiguresBlock) -> list[Figure]:
if row.symbol_column is not None and row.symbol_column < len(row.cells):
symbol_value = row.cells[row.symbol_column][0] or None
if symbol_value:
- symbol_value = re.sub(r"^(?:\*\*|__)(.*?)(?:\*\*|__)$", r"\1", symbol_value).strip()
+ symbol_value = re.sub(
+ r"^(?:\*\*|__)(.*?)(?:\*\*|__)$", r"\1", symbol_value
+ ).strip()
mark_end = _currency_suffix_end(text, magnitude_suffix(text, unit_end)[1])
figures.append(
Figure(
diff --git a/agent/tests/test_grounding_blank_corner_matrix.py b/agent/tests/test_grounding_blank_corner_matrix.py
index 7ac98473c..78ef8eba0 100644
--- a/agent/tests/test_grounding_blank_corner_matrix.py
+++ b/agent/tests/test_grounding_blank_corner_matrix.py
@@ -2,29 +2,43 @@
Synthetic tickers only; no external market data or provider dependencies.
"""
+
from __future__ import annotations
from src.agent.grounding.figures import parse_figures_block, scan_figures, table_rows
def _matrix(header: tuple[str, ...], rows: tuple[str, ...]) -> str:
- return "\n".join([
- "| | " + " | ".join(header) + " |",
- "| --- | " + " | ".join("---:" for _ in header) + " |",
- *[
- "| **" + symbol + "** | "
- + " | ".join("1.0000" if symbol == target else "0.2500" for target in header)
- + " |"
- for symbol in rows
- ],
- ]) + "\n"
+ return (
+ "\n".join(
+ [
+ "| | " + " | ".join(header) + " |",
+ "| --- | " + " | ".join("---:" for _ in header) + " |",
+ *[
+ "| **"
+ + symbol
+ + "** | "
+ + " | ".join(
+ "1.0000" if symbol == target else "0.2500" for target in header
+ )
+ + " |"
+ for symbol in rows
+ ],
+ ]
+ )
+ + "\n"
+ )
def test_complete_13_by_13_matrix_binds_both_axes() -> None:
names = tuple(f"STK{i}" for i in range(1, 14))
source = _matrix(names, names)
assert all(row.symbol_column == 0 for row in table_rows(source))
- figures = [f for f in scan_figures(source, parse_figures_block(source)) if f.shape == "measured"]
+ figures = [
+ f
+ for f in scan_figures(source, parse_figures_block(source))
+ if f.shape == "measured"
+ ]
assert len(figures) == 169
assert {(f.symbol, f.table_column_label) for f in figures} == {
(row, column.lower()) for row in names for column in names
@@ -40,11 +54,19 @@ def test_incomplete_duplicate_and_mismatched_axes_stay_unscoped() -> None:
):
source = _matrix(names, rows)
assert all(row.symbol_column is None for row in table_rows(source))
- figs = [f for f in scan_figures(source, parse_figures_block(source)) if f.shape == "measured"]
+ figs = [
+ f
+ for f in scan_figures(source, parse_figures_block(source))
+ if f.shape == "measured"
+ ]
assert all(f.symbol is None for f in figs)
def test_explicit_symbol_header_still_works() -> None:
source = "| Symbol | STK1 | STK2 |\n| --- | ---: | ---: |\n| STK1 | 1.0 | 0.2 |\n"
- figures = [f for f in scan_figures(source, parse_figures_block(source)) if f.shape == "measured"]
+ figures = [
+ f
+ for f in scan_figures(source, parse_figures_block(source))
+ if f.shape == "measured"
+ ]
assert all(f.symbol == "STK1" for f in figures)