|
@@ -6,7 +6,7 @@ import unittest
|
|
|
from unittest.mock import patch
|
|
from unittest.mock import patch
|
|
|
from pathlib import Path
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
-from src.step1_knowledge_prepare.prepare import ROOT, collect, normalize, run, verify_output
|
|
|
|
|
|
|
+from src.step1_knowledge_prepare.prepare import ROOT, collect, main, normalize, run, verify_output
|
|
|
|
|
|
|
|
|
|
|
|
|
class PreparationTests(unittest.TestCase):
|
|
class PreparationTests(unittest.TestCase):
|
|
@@ -21,6 +21,27 @@ class PreparationTests(unittest.TestCase):
|
|
|
def write_json(self, name, rows):
|
|
def write_json(self, name, rows):
|
|
|
(self.source / name).write_text(json.dumps(rows, ensure_ascii=False), encoding="utf-8")
|
|
(self.source / name).write_text(json.dumps(rows, ensure_ascii=False), encoding="utf-8")
|
|
|
|
|
|
|
|
|
|
+ def test_default_source_isolates_agent_and_preserves_logical_identity(self):
|
|
|
|
|
+ rows = [{"question": "合成问题", "answer": "合成答案"}]
|
|
|
|
|
+ self.write_json('qa.json', rows)
|
|
|
|
|
+ expected, expected_files = collect(self.source)
|
|
|
|
|
+ agent_source = self.source / '营商助手'
|
|
|
|
|
+ agent_source.mkdir()
|
|
|
|
|
+ (self.source / 'qa.json').rename(agent_source / 'qa.json')
|
|
|
|
|
+ other = self.source / '另一个助手'
|
|
|
|
|
+ other.mkdir()
|
|
|
|
|
+ (other / 'qa.json').write_text(json.dumps([
|
|
|
|
|
+ {"question": "其他助手的问题", "answer": "不可混入"}]), encoding='utf-8')
|
|
|
|
|
+ (self.source / 'unassigned.json').write_text('not valid JSON', encoding='utf-8')
|
|
|
|
|
+ with patch('src.step1_knowledge_prepare.prepare.ROOT', self.root), patch('sys.stdout', new_callable=io.StringIO):
|
|
|
|
|
+ self.assertEqual(main(['--output', str(self.output)]), 0)
|
|
|
|
|
+ self.assertEqual(main(['--output', str(self.output), '--verify']), 0)
|
|
|
|
|
+ actual = [json.loads(line) for line in (self.output / 'qa.jsonl').read_text(encoding='utf-8').splitlines()]
|
|
|
|
|
+ self.assertEqual(actual, expected)
|
|
|
|
|
+ report = json.loads((self.output / 'report.json').read_text(encoding='utf-8'))
|
|
|
|
|
+ self.assertEqual(report['files'], expected_files)
|
|
|
|
|
+ self.assertEqual(report['records'], 1)
|
|
|
|
|
+
|
|
|
def test_policy_keeps_original_and_suggested_conditions_separate(self):
|
|
def test_policy_keeps_original_and_suggested_conditions_separate(self):
|
|
|
raw = {"政策名称": "合成政策", "申报条件": "['条件甲', '条件乙']",
|
|
raw = {"政策名称": "合成政策", "申报条件": "['条件甲', '条件乙']",
|
|
|
"metadata": {"梳理后建议申报条件": ["建议丙"]}, "结束时间": "未标明"}
|
|
"metadata": {"梳理后建议申报条件": ["建议丙"]}, "结束时间": "未标明"}
|