96 lines
3.7 KiB
Python
96 lines
3.7 KiB
Python
"""附件类章节识别与单图/单表类型选择。"""
|
||
import unittest
|
||
|
||
from utils import attachment_section as att
|
||
|
||
|
||
class TestIsAttachment(unittest.TestCase):
|
||
def test_positive(self):
|
||
r = att.load_attachment_rules()
|
||
self.assertTrue(att.is_attachment_only_section('附件一:施工平面布置', r))
|
||
self.assertTrue(att.is_attachment_only_section('附图 组织机构', r))
|
||
self.assertTrue(att.is_attachment_only_section('附表 人员一览', r))
|
||
|
||
def test_negative(self):
|
||
r = att.load_attachment_rules()
|
||
self.assertFalse(att.is_attachment_only_section('施工组织设计', r))
|
||
self.assertFalse(att.is_attachment_only_section('', r))
|
||
|
||
|
||
class TestPickKind(unittest.TestCase):
|
||
def test_only_figure_switch(self):
|
||
r = att.DEFAULT_ATTACHMENT_RULES
|
||
self.assertEqual(
|
||
att.pick_single_figure_or_table('附件一:xxx', True, False, r),
|
||
'figure',
|
||
)
|
||
|
||
def test_only_table_switch(self):
|
||
r = att.DEFAULT_ATTACHMENT_RULES
|
||
self.assertEqual(
|
||
att.pick_single_figure_or_table('附件一:xxx', False, True, r),
|
||
'table',
|
||
)
|
||
|
||
def test_both_off(self):
|
||
self.assertIsNone(
|
||
att.pick_single_figure_or_table('附件一', False, False, None),
|
||
)
|
||
|
||
def test_table_hint(self):
|
||
r = att.DEFAULT_ATTACHMENT_RULES
|
||
k = att.pick_single_figure_or_table('附件三 工程量一览表', True, True, r)
|
||
self.assertEqual(k, 'table')
|
||
|
||
def test_figure_hint(self):
|
||
r = att.DEFAULT_ATTACHMENT_RULES
|
||
k = att.pick_single_figure_or_table('附图 施工平面示意图', True, True, r)
|
||
self.assertEqual(k, 'figure')
|
||
|
||
def test_default_ambiguous(self):
|
||
r = dict(att.DEFAULT_ATTACHMENT_RULES)
|
||
r['default_kind_when_ambiguous'] = 'table'
|
||
k = att.pick_single_figure_or_table('附件五 其他资料', True, True, r)
|
||
self.assertEqual(k, 'table')
|
||
|
||
|
||
class TestAttachmentBodyMode(unittest.TestCase):
|
||
def test_default_stack_charts_only(self):
|
||
r = att.DEFAULT_ATTACHMENT_RULES
|
||
self.assertEqual(att.attachment_leaf_body_mode(r), 'stack_charts_only')
|
||
self.assertTrue(att.use_attachment_stack_charts_body(r))
|
||
self.assertFalse(att.use_attachment_single_chart_only_body(r))
|
||
self.assertFalse(att.use_attachment_full_body(r))
|
||
|
||
def test_full_mode(self):
|
||
r = dict(att.DEFAULT_ATTACHMENT_RULES)
|
||
r['attachment_leaf_body_mode'] = 'full'
|
||
self.assertEqual(att.attachment_leaf_body_mode(r), 'full')
|
||
self.assertTrue(att.use_attachment_full_body(r))
|
||
self.assertFalse(att.use_attachment_stack_charts_body(r))
|
||
|
||
def test_single_chart_only(self):
|
||
r = dict(att.DEFAULT_ATTACHMENT_RULES)
|
||
r['attachment_leaf_body_mode'] = 'single_chart_only'
|
||
self.assertTrue(att.use_attachment_single_chart_only_body(r))
|
||
self.assertTrue(att.use_attachment_stack_charts_body(r))
|
||
|
||
|
||
class TestExpandOutlineSkip(unittest.TestCase):
|
||
def test_should_skip_attachment(self):
|
||
self.assertTrue(att.should_skip_expand_subchapters('附件一:平面图'))
|
||
self.assertTrue(att.should_skip_expand_subchapters('附图 示意'))
|
||
|
||
def test_should_skip_normal_chapter(self):
|
||
self.assertFalse(att.should_skip_expand_subchapters('施工组织设计'))
|
||
self.assertFalse(att.should_skip_expand_subchapters('质量管理体系与措施'))
|
||
|
||
def test_parse_attachment_label(self):
|
||
self.assertEqual(att.parse_attachment_label('附件一:平面图'), '一')
|
||
self.assertEqual(att.parse_attachment_label('附件2 承诺书'), '2')
|
||
self.assertEqual(att.parse_attachment_label('附图 总平面'), '附图')
|
||
|
||
|
||
if __name__ == '__main__':
|
||
unittest.main()
|