63 lines
2.0 KiB
Python
63 lines
2.0 KiB
Python
import unittest
|
|
|
|
import pandas as pd
|
|
|
|
from mycode import main
|
|
|
|
|
|
class PhraseExemptionRulesTest(unittest.TestCase):
|
|
def test_builds_exemption_rules_from_suggestion_phrases(self):
|
|
rules_df = pd.DataFrame([
|
|
{
|
|
'错误表述': '深入贯彻中央八项规定精神',
|
|
'建议修改词语': '深入贯彻中央八项规定精神学习教育',
|
|
'错误分类': '固定表述错误'
|
|
},
|
|
{
|
|
'错误表述': '“两学一做”学习',
|
|
'建议修改词语': '“两学一做”学习教育',
|
|
'错误分类': '固定表述错误'
|
|
},
|
|
])
|
|
|
|
exemption_rules = main.build_phrase_exemption_rules(rules_df)
|
|
|
|
self.assertEqual(
|
|
exemption_rules['深入贯彻中央八项规定精神'],
|
|
['深入贯彻中央八项规定精神学习教育']
|
|
)
|
|
self.assertEqual(
|
|
exemption_rules['“两学一做”学习'],
|
|
['“两学一做”学习教育']
|
|
)
|
|
|
|
def test_skips_short_error_phrase_when_full_correct_phrase_exists(self):
|
|
exemption_rules = {
|
|
'深入贯彻中央八项规定精神': ['深入贯彻中央八项规定精神学习教育']
|
|
}
|
|
|
|
should_skip = main.should_skip_error_phrase(
|
|
'深入贯彻中央八项规定精神',
|
|
'现开展深入贯彻中央八项规定精神学习教育相关工作。',
|
|
exemption_rules
|
|
)
|
|
|
|
self.assertTrue(should_skip)
|
|
|
|
def test_does_not_skip_when_only_short_error_phrase_exists(self):
|
|
exemption_rules = {
|
|
'深入贯彻中央八项规定精神': ['深入贯彻中央八项规定精神学习教育']
|
|
}
|
|
|
|
should_skip = main.should_skip_error_phrase(
|
|
'深入贯彻中央八项规定精神',
|
|
'文章仅写到深入贯彻中央八项规定精神,没有写完整。',
|
|
exemption_rules
|
|
)
|
|
|
|
self.assertFalse(should_skip)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|