コード例 #1
0
ファイル: test_scripts.py プロジェクト: eromoe/cjktools
    def test_fetch_scripts(self):
        """
        Test fetching of hiragana and katakana, and converting between them.
        """
        hiragana = u'ぁあぃいぅうぇえぉおかがきぎくぐけげこごさざしじすずせぜそぞただちぢっつづてでとどなにぬねのはばぱひびぴふぶぷへべぺほぼぽまみむめもゃやゅゆょよらりるれろゎわゐゑをんゔゕゖ'  # nopep8
        self.assertEqual(scripts.get_script(Script.Hiragana), hiragana)
        katakana = u'ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタダチヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミムメモャヤュユョヨラリルレロヮワヰヱヲンヴヵヶ'  # nopep8
        self.assertEqual(scripts.get_script(Script.Katakana), katakana)

        self.assertEqual(scripts.to_hiragana(katakana), hiragana)
        self.assertEqual(scripts.to_katakana(hiragana), katakana)

        return
コード例 #2
0
 def __init__(self, name: str):
     self.name = name
     try:
         self.script = scripts.get_script(name)
     except Exception:
         # TODO better handling here
         logger.error(f"Error while fetching script {name}.")
         self.script = None
コード例 #3
0
def test_get_script_unauthorized():
    # unauthorized function
    func = "my_fancy_function"
    try:
        _ = get_script(func)
        assert False
    except NameError:
        pass
コード例 #4
0
def test_get_script_logic():
    # logical function
    func = 'if_valid(strip, "Hello")'

    row_input = ""
    assert get_script(func)(row_input) == ""

    row_input = "holà"
    assert get_script(func)(row_input) == "Hello"

    row_input = "NaN"
    assert get_script(func)(row_input) == ""

    func = "if_valid(strip, 'Hello')"
    row_input = "holà"
    assert get_script(func)(row_input) == "Hello"

    func = 'if_valid(strip, "7")'
    row_input = "holà"
    assert get_script(func)(row_input) == "7"

    func = 'if_valid(strip, "9.2")'
    row_input = "holà"
    assert get_script(func)(row_input) == "9.2"

    func = "if_valid(strip, make_title)"

    row_input = ""
    assert get_script(func)(row_input) == ""

    row_input = "  holà"
    assert get_script(func)(row_input) == "Holà"

    # Un authorized param
    func = "if_valid(strip, my_fancy_function)"
    try:
        _ = get_script(func)
        assert False
    except ValueError:
        pass
コード例 #5
0
ファイル: alternations.py プロジェクト: eromoe/cjktools
def _create_voicing_map():
    """
    Constructs map from kana to their voiced alternatives.
    """
    table = kana_table.KanaTable.get_cached().get_table()
    voiced_line = table[u'か'] + table[u'さ'] + table[u'た']
    double_voiced_line = table[u'は']

    voicing_map = {}
    for kana in scripts.get_script(scripts.Script.Hiragana):
        ord_kana = ord(kana)

        if kana in voiced_line:
            voicing_map[kana] = [unichr(ord_kana+1)]
        elif kana in double_voiced_line:
            voicing_map[kana] = [unichr(ord_kana+1), unichr(ord_kana+2)]
        else:
            voicing_map[kana] = []

    return voicing_map
コード例 #6
0
 def __init__(self, name: str):
     self.name = name
     self.script = scripts.get_script(name)
コード例 #7
0
def test_get_script_utils():
    # utility function
    row_input = " my text  "
    func = "make_title"
    assert get_script(func)(row_input) == "My Text"
コード例 #8
0
def test_get_script_custom():
    # custom function
    row_input = "20191103"
    func = "clean_date"
    assert get_script(func)(row_input) == "2019-11-03"