def test_apply_replace(self): node = Paragraph(title='第一項', sentence='私はネコです') node_finder = LawNodeFinder([node]) action = parse_action_text('第一項中「ネコ」を「イヌ」に改める') apply_replace(action, node_finder) self.assertEqual('私はイヌです', node.sentence)
def test_apply_delete(self): node = Paragraph(title='第一項', sentence='私はネコです') node_finder = LawNodeFinder([node]) action = parse_action_text('第一項中「私は」及び「です」を削る') apply_delete(action, node_finder) self.assertEqual('ネコ', node.sentence)
def test_apply_add_word_fail(self): node = Paragraph(title='第一項', sentence='私はネコです') node_finder = LawNodeFinder([node]) action = parse_action_text('第一項中「サル」の下に「ザメ」を加える') with self.assertRaises(TextNotFoundError): apply_add_word(action, node_finder)
def test_apply_add_word(self): node = Paragraph(title='第一項', sentence='私はネコです') node_finder = LawNodeFinder([node]) action = parse_action_text('第一項中「ネコ」の下に「ザメ」を加える') apply_add_word(action, node_finder) self.assertEqual('私はネコザメです', node.sentence)
def test_apply_replace_multiple_fail(self): node = Paragraph(title='第一項', sentence='私はネコネコです') node_finder = LawNodeFinder([node]) action = parse_action_text('第一項中「ネコ」を「イヌ」に改める') with self.assertRaises(MultipleTextFoundError): apply_replace(action, node_finder)
def test_add_law_action(self): text = '第二条に次の二項を加え' action = parse_action_text(text) self.assertTrue(isinstance(action, AddLawAction)) self.assertEqual(Query.from_text('第二条'), action.at) self.assertEqual('二項', action.what) self.assertTrue(is_serializable(action))
def test_rename_action(self): text = '一条中第三項を第四項とする' action = parse_action_text(text) self.assertTrue(isinstance(action, RenameAction)) self.assertEqual(Query.from_text('一条中第三項'), action.old) self.assertEqual(Query.from_text('第四項'), action.new) self.assertTrue(is_serializable(action))
def test_apply_delete_fail(self): node = Paragraph(title='第一項', sentence='私はネコです') node_finder = LawNodeFinder([node]) action = parse_action_text('第一項中「私は」及び「でした」を削る') with self.assertRaises(TextNotFoundError): apply_delete(action, node_finder) self.assertEqual('私はネコです', node.sentence) # not changed
def test_replace_action_short(self): text = '「第百二十五条」を「第百二十五条の二」に' action = parse_action_text(text) self.assertTrue(isinstance(action, ReplaceAction)) self.assertEqual(Query.from_text(''), action.at) self.assertEqual('第百二十五条', action.old) self.assertEqual('第百二十五条の二', action.new) self.assertTrue(is_serializable(action))
def test_replace_action(self): text = '第一条中「中「小」」を「大「中」」に改める' action = parse_action_text(text) self.assertTrue(isinstance(action, ReplaceAction)) self.assertEqual(Query.from_text('第一条'), action.at) self.assertEqual('中「小」', action.old) self.assertEqual('大「中」', action.new) self.assertTrue(is_serializable(action))
def test_add_word_action_short(self): text = '「前項」の下に「について」を' action = parse_action_text(text) self.assertTrue(isinstance(action, AddWordAction)) self.assertEqual(Query.from_text(''), action.at) self.assertEqual('前項', action.word) self.assertEqual('について', action.what) self.assertTrue(is_serializable(action))
def test_delete_action_short(self): text = '「その他」及び「前項」を削り' action = parse_action_text(text) self.assertTrue(isinstance(action, DeleteAction)) self.assertEqual(Query.from_text(''), action.at) self.assertEqual(2, len(action.whats)) self.assertEqual('その他', action.whats[0]) self.assertEqual('前項', action.whats[1]) self.assertTrue(is_serializable(action))
def test_invalid_action_fail(self): text = 'ランダムな文' with self.assertRaises(ValueError): parse_action_text(text)