91 lines
3.0 KiB
Python
91 lines
3.0 KiB
Python
import os
|
|
from agent.rule_loader import RuleLoader, PGM_PATTERN_MAP
|
|
from agent.models import ProgramMeta
|
|
|
|
RULES_DIR = os.path.join(os.path.dirname(__file__), '..', 'rules')
|
|
|
|
|
|
def test_pgm_pattern_map_has_known_patterns():
|
|
assert 'マッチング(1:1)' in PGM_PATTERN_MAP
|
|
assert 'マッチング(1:N)' in PGM_PATTERN_MAP
|
|
assert 'DB更新' in PGM_PATTERN_MAP
|
|
|
|
|
|
def test_load_matching_1_1_rule():
|
|
loader = RuleLoader(RULES_DIR)
|
|
meta = ProgramMeta(
|
|
program_id='TEST', program_name='', system_name='',
|
|
pgm_type='メイン', pgm_pattern='マッチング(1:1)',
|
|
summary_lines=[], prerequisites=[], files=[], keys=[], modules=[],
|
|
process_detail='', output_records='',
|
|
input_type='file', copy_fields={}, db_tables={}
|
|
)
|
|
combined, descriptions, count = loader.load(meta)
|
|
|
|
assert count > 0
|
|
assert len(combined) > 0
|
|
assert 'マッチング(1:1)' in combined
|
|
assert '数据生成' in combined
|
|
|
|
|
|
def test_load_matching_1_n_rule():
|
|
loader = RuleLoader(RULES_DIR)
|
|
meta = ProgramMeta(
|
|
program_id='TEST', program_name='', system_name='',
|
|
pgm_type='メイン', pgm_pattern='マッチング(1:N)',
|
|
summary_lines=[], prerequisites=[], files=[], keys=[], modules=[],
|
|
process_detail='', output_records='',
|
|
input_type='file', copy_fields={}, db_tables={}
|
|
)
|
|
combined, descriptions, count = loader.load(meta)
|
|
|
|
assert count > 0
|
|
assert len(combined) > 0
|
|
assert 'マッチング(1:N)' in combined
|
|
|
|
|
|
def test_load_nonexistent_pattern_raises():
|
|
loader = RuleLoader(RULES_DIR)
|
|
meta = ProgramMeta(
|
|
program_id='TEST', program_name='', system_name='',
|
|
pgm_type='メイン', pgm_pattern='存在しないパターン',
|
|
summary_lines=[], prerequisites=[], files=[], keys=[], modules=[],
|
|
process_detail='', output_records='',
|
|
input_type='file', copy_fields={}, db_tables={}
|
|
)
|
|
try:
|
|
loader.load(meta)
|
|
assert False, 'Should have raised FileNotFoundError'
|
|
except FileNotFoundError:
|
|
pass
|
|
|
|
|
|
def test_detect_conditional_branch():
|
|
process = """
|
|
2-1-2.ロジック分岐判定(EVALUATE)
|
|
2-1-2-1.STATUS='1'の場合
|
|
INSERT処理
|
|
"""
|
|
assert RuleLoader._detect_feature(process, ['場合', 'EVALUATE', 'IF']) is True
|
|
|
|
|
|
def test_no_keyword_match():
|
|
process = "1.初期処理\n2.主処理\n3.終了処理"
|
|
assert RuleLoader._detect_feature(process, ['EVALUATE']) is False
|
|
|
|
|
|
def test_rule_with_conditional_feature():
|
|
loader = RuleLoader(RULES_DIR)
|
|
meta = ProgramMeta(
|
|
program_id='TEST', program_name='', system_name='',
|
|
pgm_type='メイン', pgm_pattern='マッチング(1:1)',
|
|
summary_lines=[], prerequisites=[], files=[], keys=[], modules=[],
|
|
process_detail='2-1-2.EVALUATEで条件分岐する。',
|
|
output_records='',
|
|
input_type='file', copy_fields={}, db_tables={}
|
|
)
|
|
combined, descriptions, count = loader.load(meta)
|
|
|
|
assert count > 0
|
|
assert '条件分支' in combined
|