def test_instance(self):
        data = [
            # (name, fullname, age, birth, sex, job, calling, info,
            #   exp_name, exp_age, exp_birth, exp_sex, exp_job, exp_calling, exp_info,
            #   exp_firstname, exp_lastname, exp_fullname, exp_exfullname)
            (True, 'Taro', '', 17, (5, 5), 'male', 'student', 'me:俺', 'a man',
             'Taro', 17, (5, 5), 'male', 'student', {
                 'me': '俺',
                 'S': 'Taro',
                 'M': '俺'
             }, 'a man', 'Taro', 'Taro', 'Taro', 'Taro'),
        ]

        def checker(name, fullname, age, birth, sex, job, calling, info,
                    exp_name, exp_age, exp_birth, exp_sex, exp_job,
                    exp_calling, exp_info, exp_fn, exp_ln, exp_full,
                    exp_exfull):
            tmp = psn.Person(name, fullname, age, birth, sex, job, calling,
                             info)
            self.assertIsInstance(tmp, psn.Person)
            self.assertEqual(tmp.name, exp_name)
            self.assertEqual(tmp.age, exp_age)
            self.assertEqual(tmp.birth, exp_birth)
            self.assertEqual(tmp.sex, exp_sex)
            self.assertEqual(tmp.job, exp_job)
            self.assertEqual(tmp.calling, exp_calling)
            self.assertEqual(tmp.info, exp_info)
            self.assertEqual(tmp.firstname, exp_fn)
            self.assertEqual(tmp.lastname, exp_ln)
            self.assertEqual(tmp.fullname, exp_full)
            self.assertEqual(tmp.exfullname, exp_exfull)

        validate_with_fail(self, 'class instance', checker, data)
示例#2
0
    def test_instance(self):
        taro = SObject('taro')
        data = [
            # (src, act, args, exp_src, exp_cmd, exp_args)
            (True, taro, 'be', ('a', ), taro, SCmd.BE, ('a', )),
            (True, taro, 'come', ('a', ), taro, SCmd.COME, ('a', )),
            (True, taro, 'do', ('a', ), taro, SCmd.DO, ('a', )),
            (True, taro, 'explain', ('a', ), taro, SCmd.EXPLAIN, ('a', )),
            (True, taro, 'go', ('a', ), taro, SCmd.GO, ('a', )),
            (True, taro, 'hear', ('a', ), taro, SCmd.HEAR, ('a', )),
            (True, taro, 'look', ('a', ), taro, SCmd.LOOK, ('a', )),
            (True, taro, 'talk', ('a', ), taro, SCmd.TALK, ('a', )),
            (True, taro, 'think', ('a', ), taro, SCmd.THINK, ('a', )),
            (True, taro, 'voice', ('a', ), taro, SCmd.VOICE, ('a', )),
            (True, taro, 'wear', ('a', ), taro, SCmd.WEAR, ('a', )),
        ]

        def checker(src, act, args, exp_src, exp_cmd, exp_args):
            tmp = Writer(src)
            self.assertIsInstance(tmp, Writer)
            tmp2 = getattr(tmp, act)(*args)
            self.assertIsInstance(tmp2, SCode)
            self.assertEqual(tmp2.src, exp_src)
            self.assertEqual(tmp2.cmd, exp_cmd)
            self.assertEqual(tmp2.script, exp_args)

        validate_with_fail(self, 'class instance', checker, data)
示例#3
0
    def test_execute_internal(self):
        data = [
            # (src, priority, expect, exp_val)
            (True, Chapter('test', Episode('a'), Episode('b'),
                           Episode('c')), 5, True, 3),
            (True,
             Chapter('test', Episode('a'),
                     Episode('b').set_priority(2), Episode('c')), 5, True, 2),
            (True, Chapter('test', Episode('a'), Episode('b'),
                           Episode('c')), 5, True, 3),
            (True, SCode(None, SCmd.BE, (),
                         '').set_priority(2), 5, True, None),
        ]

        def checker(src, pri, expect, exp_val):
            tmp = ft.Filter()._exec_internal(src, pri)
            self.assertEqual(tmp[1], expect)
            if hasattr(tmp[0], 'children'):
                self.assertEqual(len(tmp[0].children), exp_val)
            elif isinstance(tmp[0], (list, tuple)):
                self.assertEqual(len(tmp[0], exp_val))
            elif tmp[0]:
                self.assertIsInstance(tmp[0], SCode)
            else:
                self.assertEqual(tmp[0], exp_val)

        validate_with_fail(self, 'execute_internal', checker, data)
示例#4
0
    def test_instance(self):
        data = [
            # (chars, t_lines, t_papers, lines, papers, chaps, epis, scenes, scodes,
            #   exp_chars, exp_tlines, exp_tpapers, exp_lines, exp_papers, exp_chaps, exp_epis, exp_scenes, exp_scodes)
            (True, 9, 9, 9, 1, 10, 100, 5, 5, 5, 5, 9, 9, 9, 1, 10, 100, 5, 5,
             5, 5),
        ]

        def checker(total, t_lines, t_papers, chars, lines, papers, chapters,
                    episodes, scenes, scodes, exp_total, exp_tlines,
                    exp_tpapers, exp_chars, exp_lines, exp_papers, exp_chaps,
                    exp_epis, exp_scenes, exp_scodes):
            tmp = hd.HeaderInfo(total, t_lines, t_papers, chars, lines, papers,
                                chapters, episodes, scenes, scodes)
            self.assertIsInstance(tmp, hd.HeaderInfo)
            self.assertEqual(tmp.total_chars, exp_total)
            self.assertEqual(tmp.total_lines, exp_tlines)
            self.assertEqual(tmp.total_papers, exp_tpapers)
            self.assertEqual(tmp.desc_chars, exp_chars)
            self.assertEqual(tmp.lines, exp_lines)
            self.assertEqual(tmp.papers, exp_papers)
            self.assertEqual(tmp.chapters, exp_chaps)
            self.assertEqual(tmp.episodes, exp_epis)
            self.assertEqual(tmp.scenes, exp_scenes)
            self.assertEqual(tmp.scodes, exp_scodes)

        validate_with_fail(self, 'class instance', checker, data)
 def test_end_of(self):
     data = [
         # (src, expect)
         (True, Chapter('test', ), SCmd.END_CHAPTER),
     ]
     validate_with_fail(
         self, 'end_of', lambda src, expect: self.assertEqual(
             hd.HeaderUpdater()._end_of(src).cmd, expect), data)
示例#6
0
 def test_to_description(self):
     data = [
         # (src, expect)
         (True, ['太郎は、', '天才だ'], '太郎は、天才だ。'),
     ]
     validate_with_fail(
         self, 'to_description', lambda src, expect: self.assertEqual(
             cnv.Converter().to_description(src), expect), data)
示例#7
0
 def test_to_dialogue(self):
     data = [
         # (src, expect)
         (True, ['お前は、', 'どういうつもりだ?'], '「お前は、どういうつもりだ?」'),
     ]
     validate_with_fail(
         self, 'to_dialogue', lambda src, expect: self.assertEqual(
             cnv.Converter().to_dialogue(src), expect), data)
 def test_is_dict(self):
     data = [
             # (val, expect)
             (True, {"test": "1"}, {"test": "1"},),
             (False, ["test", "1"], ["test", "1"],),
             ]
     validate_with_fail(self, "is_dict",
         lambda v,expect: self.assertEqual(assertion.is_dict(v), expect), data)
 def test_is_int(self):
     data = [
             # (val, expect)
             (True, 1, 1,),
             (False, "1", "1",),
             ]
     validate_with_fail(self, "is_int",
         lambda v,expect: self.assertEqual(assertion.is_int(v), expect), data)
示例#10
0
 def test_has_rubi_exclusions(self):
     data = [
             # (src, exwords, expect)
             (True, '太郎', ['太郎',], True),
             ]
     validate_with_fail(self, 'has_rubi_exclusions',
             lambda src, exwords, expect: self.assertEqual(
                 ck.Checker().has_rubi_exclusions(src, exwords), expect),
             data)
示例#11
0
 def test_has_then(self):
     data = [
             # (src, expect[bool])
             (True, SCode(None, SCmd.THEN, (),""), True),
             ]
     validate_with_fail(self, 'has_then',
             lambda src, expect: self.assertEqual(
                 ck.Checker().has_then(src), expect),
             data)
示例#12
0
 def test_add_rubi(self):
     data = [
         # (src, key, rubi, num, expect)
         (True, '山田太郎', '太郎', '太郎《たろう》', 1, '山田太郎《たろう》'),
     ]
     validate_with_fail(
         self, 'add_rubi',
         lambda src, key, rubi, num, expect: self.assertEqual(
             cnv.Converter().add_rubi(src, key, rubi, num), expect), data)
示例#13
0
 def test_is_empty_script(self):
     data = [
             # (src, expect[bool])
             (True, SCode(None, SCmd.BE, ('&',), ""), True),
             ]
     validate_with_fail(self, 'is_empty_script',
             lambda src, expect: self.assertEqual(
                 ck.Checker().is_empty_script(src), expect),
             data)
示例#14
0
 def test_is_breakline(self):
     data = [
             # (src, expect[bool])
             (True, '\n', True),
             ]
     validate_with_fail(self, 'is_breakline',
             lambda src, expect: self.assertEqual(
                 ck.Checker().is_breakline(src), expect),
             data)
 def test_is_bool(self):
     data = [
             # (val, expect)
             (True, True, True,),
             (True, False, False,),
             (False, ["test"], True,),
             ]
     validate_with_fail(self, "is_bool",
         lambda v,expect: self.assertEqual(assertion.is_bool(v), expect), data)
示例#16
0
 def test_has_tag_comment(self):
     data = [
             # (src, expect[bool])
             (True, '<!--comment-->', True),
             ]
     validate_with_fail(self, 'has_tag_comment',
             lambda src, expect: self.assertEqual(
                 ck.Checker().has_tag_comment(src), expect),
             data)
示例#17
0
 def test_has_tag_top(self):
     data = [
             # (src, expect[bool])
             (True, '# head', True),
             ]
     validate_with_fail(self, 'has_tag_top',
             lambda src, expect: self.assertEqual(
                 ck.Checker().has_tag_top(src), expect),
             data)
示例#18
0
 def test_has_rubi_key_converted(self):
     data = [
             # (src, key, expect[bool])
             (True, '|太郎', '太郎', True),
             ]
     validate_with_fail(self, 'has_rubi_key_converted',
             lambda src,key,expect: self.assertEqual(
                 ck.Checker().has_rubi_key_converted(src, key), expect),
             data)
 def test_instance(self):
     data = [
             # (title, expect)
             (True, 'test', 'test'),
             ]
     def checker(title, expect):
         tmp = sc.StoryConfig(title)
         self.assertIsInstance(tmp, sc.StoryConfig)
         self.assertEqual(tmp.title, expect)
     validate_with_fail(self, 'class instance', checker, data)
示例#20
0
 def test_has_tag_symbol(self):
     data = [
             # (src, symbol, expect)
             (True, '$taroはね', '$', True),
             (True, '俺は$taroだ', '$', True),
             ]
     validate_with_fail(self, 'has_tag_symbol',
             lambda src, symbol, expect: self.assertEqual(
                 ck.Checker().has_tag_symbol(src, symbol), expect),
             data)
 def test_is_list(self):
     data = [
             # (val, expect)
             (True, [1,2,3], [1,2,3],),
             (False, 1, 1),
             (False, (1,2), (1,2)),
             ]
     validate_with_fail(self, "is_list",
         lambda v,expect: self.assertEqual(assertion.is_list(v), expect),
             data)
 def test_conv_to_novel(self):
     data = [
         # (src, is_cmt, expect)
         (True, CodeList(*[SCode(None, SCmd.BE, ('太郎', ), '')]), False,
          (FormatTag.DESCRIPTION_HEAD, ' 太郎。', '\n')),
     ]
     validate_with_fail(
         self, 'conv_to_novel',
         lambda src, is_cmt, expect: self.assertEqual(
             cp.Compiler()._conv_to_novel(src, is_cmt).data, expect), data)
 def test_is_between(self):
     data = [
             # (val, max, min, expect)
             (True, 10, 100, 1, 10,),
             (False, -1, 100, 1, 10,),
             (False, 100, 50, 1, 100,),
             ]
     validate_with_fail(self, "is_between",
         lambda v,mx,mn,expect: self.assertEqual(assertion.is_between(v, mx, mn), expect),
             data)
示例#24
0
 def test_manupaper_numbers_of(self):
     data = [
         # (lines, rows, expect[float])
         (True, 40, 20, 2),
         (True, 50, 20, 2.5),
         (True, 50, 0, 0),
     ]
     validate_with_fail(
         self, 'manupaper_numbers_of',
         lambda lines, rows, expect: self.assertEqual(
             cnt.Counter().manupaper_numbers_of(lines, rows), expect), data)
示例#25
0
 def test_conv_to_mode(self):
     data = [
         # (mode, expect)
         (True, 'w', fm.FormatMode.WEB),
         (True, 's', fm.FormatMode.SMARTPHONE),
         (True, 'p', fm.FormatMode.PLAIN),
         (True, 'n', fm.FormatMode.DEFAULT),
     ]
     validate_with_fail(
         self, 'conv_to_mode', lambda mode, expect: self.assertEqual(
             fm.FormatMode.conv_to_mode(mode), expect), data)
示例#26
0
 def test_script_relieved_symbols(self):
     data = [
         # (src, expect)
         (True, ['a', '&'], [
             'a',
         ]),
     ]
     validate_with_fail(
         self, 'script_relieved_symbols',
         lambda src, expect: self.assertEqual(
             cnv.Converter().script_relieved_symbols(src), expect), data)
 def test_is_various_types(self):
     data = [
             # (val, types, expect)
             (True, 1, (int, str), 1),
             (True, "1", (int, str), "1"),
             (False, [1,2], (int, str), [1,2]),
             ]
     validate_with_fail(self, "is_various_types",
             lambda v,types,expect: self.assertEqual(
                 assertion.is_various_types(v,types), expect),
                 data)
 def test_novel_serialized(self):
     scode0 = SCode(None, SCmd.BE, (), '')
     scode1 = SCode(None, SCmd.INFO_DATA, (), '')
     data = [
         # (src, expect)
         (True, Chapter('a', Episode('b', Scene('c', scode0))), 1),
         (True, Chapter('a', scode1, Episode('b', Scene('c', scode0))), 2),
     ]
     validate_with_fail(
         self, 'novel_serialized', lambda src, expect: self.assertEqual(
             len(sl.Serializer()._novel_serialized(src)), expect), data)
    def test_instance(self):
        data = [
            # (title, expect)
            (True, 'test', 'test'),
        ]

        def checker(title, expect):
            tmp = wd.World(title)
            self.assertIsInstance(tmp, wd.World)
            self.assertEqual(tmp.config.title, expect)

        validate_with_fail(self, 'class instance', checker, data)
示例#30
0
 def test_scenes_of(self):
     data = [
         # (src, expect[int])
         (True, Story('a', Chapter('b', Episode('c', Scene('d', )))), 1),
         (True, Chapter('a', Episode('b', Scene('c', ))), 1),
         (True, Episode('a', Scene('b', )), 1),
         (True, Scene('a', ), 1),
         (True, SCode(None, SCmd.BE, (), ''), 0),
     ]
     validate_with_fail(
         self, 'scenes_of', lambda src, expect: self.assertEqual(
             cnt.Counter().scenes_of(src), expect), data)