예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
    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)
예제 #6
0
    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))
예제 #7
0
    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))
예제 #8
0
    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
예제 #9
0
    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))
예제 #10
0
    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))
예제 #11
0
    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))
예제 #12
0
    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))
예제 #13
0
 def test_invalid_action_fail(self):
     text = 'ランダムな文'
     with self.assertRaises(ValueError):
         parse_action_text(text)