feat(pre_process_file):解决hxops上传excel行截断的问题,由markdown换为命中更好的key=value的方式;dify同步custom;行间\n\n,数据行单独成块;
This commit is contained in:
1 parent
a18a07ef1a
commit
67d08924a4
25 files changed
+655
-25
No files matched your search
@@ -0,0 +1,70 @@
|
||||
"""Tests for Excel table linearization chunk boundaries."""
|
||||
from __future__ import annotations
|
||||
|
||||
from edkb_system.contracts import Context
|
||||
from edkb_system.skills import table_linearize
|
||||
|
||||
|
||||
def test_condition_action_table_uses_double_newline_between_bullets():
|
||||
tables = [
|
||||
{
|
||||
'sheet': 'Rules',
|
||||
'headers': ['条件', '处理', '责任'],
|
||||
'rows': [
|
||||
['库存不足', '补货', '采购部'],
|
||||
['价格变动', '更新报价', '销售部'],
|
||||
],
|
||||
}
|
||||
]
|
||||
output = table_linearize.run(tables, Context())
|
||||
|
||||
assert '\n\n- 当' in output
|
||||
assert output.count('- 当') == 2
|
||||
assert output.startswith('## Sheet: Rules')
|
||||
|
||||
|
||||
def test_narrow_table_separates_data_rows_with_double_newline():
|
||||
tables = [
|
||||
{
|
||||
'sheet': 'Data',
|
||||
'headers': ['A', 'B', 'C'],
|
||||
'rows': [
|
||||
['1', '2', '3'],
|
||||
['4', '5', '6'],
|
||||
],
|
||||
}
|
||||
]
|
||||
output = table_linearize.run(tables, Context())
|
||||
|
||||
assert '| --- | --- | --- |' in output
|
||||
assert '\n\n|' in output
|
||||
assert '| 1 | 2 | 3 |' in output
|
||||
assert '| 4 | 5 | 6 |' in output
|
||||
assert '【行】' not in output
|
||||
|
||||
|
||||
def test_wide_table_uses_row_text_blocks():
|
||||
headers = [f'列{i}' for i in range(1, 11)]
|
||||
rows = [[str(i * 10 + j) for j in range(10)] for i in range(1, 4)]
|
||||
tables = [{'sheet': 'Wide', 'headers': headers, 'rows': rows}]
|
||||
|
||||
output = table_linearize.run(tables, Context())
|
||||
|
||||
assert '【行】' in output
|
||||
assert '\n\n' in output
|
||||
assert output.count('【行】') == 3
|
||||
assert '列1=10' in output
|
||||
assert '|' not in output.split('## Sheet: Wide')[-1]
|
||||
|
||||
|
||||
def test_multiple_sheets_separated_by_double_newline():
|
||||
tables = [
|
||||
{'sheet': 'S1', 'headers': ['X'], 'rows': [['a']]},
|
||||
{'sheet': 'S2', 'headers': ['Y'], 'rows': [['b']]},
|
||||
]
|
||||
output = table_linearize.run(tables, Context())
|
||||
|
||||
assert '## Sheet: S1' in output
|
||||
assert '## Sheet: S2' in output
|
||||
assert output.index('## Sheet: S2') > output.index('## Sheet: S1')
|
||||
assert '\n\n## Sheet: S2' in output
|
||||
Reference in new issue
Block a user