Skip to content

Commit

Permalink
problem with spokenforms accented characters partly solved. In Dutch …
Browse files Browse the repository at this point in the history
…probably a Dragon error.
  • Loading branch information
quintijn committed Oct 30, 2023
1 parent cfeee37 commit 84e0170
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/unimacro/natlinkutilsbj.py
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,7 @@ def showInifile(self, body=None, grammarLists=None, ini=None,
#print 'writing to and open:\n\t"%s"'% whatFile
t = '\n'.join(L)
rwfile = readwritefile.ReadWriteFile()
rwfile.writeAnything(whatFile, t)
rwfile.writeAnything(whatFile, t, encoding='utf-8')

self.openFileDefault(whatFile, mode="edit")

Expand Down
16 changes: 16 additions & 0 deletions tests/test_grammar_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

thisDir = Path(__file__).parent

def do_nothing(*args, **kwargs):
return None


def test_getLineRelativeTo():
"""test the relative to (modulo 100 or modulo 10) trick for getting line numbers
"""
Expand Down Expand Up @@ -45,6 +49,18 @@ def test_getLineRelativeTo():
result = _lines.getLineRelativeTo(relative, currentLine=current, modulo=modulo)
assert result == expect

# def test_get_accented_numbers_info(unimacro_setup,monkeypatch):
# """problem with the numbers spoken forms of accented characters
# """
#
# thisGrammar = _lines.ThisGrammar()
# monkeypatch.setattr(thisGrammar, 'switchOnOrOff', do_nothing)
# thisGrammar.startInifile() #modName = '_lines')
# thisGrammar.initialize()
# thisGrammar.showInifile()
# the showInifile did not show accented characters, seems ok now.
# pass


if __name__ == "__main__":
pytest.main(['test_grammar_lines.py'])
Expand Down
20 changes: 10 additions & 10 deletions tests/test_spokenforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,15 @@ def test_make_mixed_list(unimacro_setup):
numbers = spokenforms.SpokenForms('test')

L = [1, 2, 4, 5, 6]
got = numbers.getMixedList(L)
# got = numbers.getMixedList(L)
expected = ['on\xe9', 'two', 'too', 'four', 'for', 'five', 'six']
assert expected == numbers.getMixedList(L)

# non existing language:
print('\nexpect messages from spokenforms.ini, as language is unknown')
m = spokenforms.SpokenForms('othertest')

got = numbers.getMixedList(L)
# got = numbers.getMixedList(L)
expected = ['1', '2', '4', '5', '6']
assert expected == m.getMixedList(L)

Expand All @@ -331,8 +331,8 @@ def test_get_number_back_from_spoken_form(unimacro_setup):
numbers = spokenforms.SpokenForms('test')

expected = 1
input = 'on\xe9'
assert expected == numbers.getNumberFromSpoken(input)
Input = 'on\xe9'
assert expected == numbers.getNumberFromSpoken(Input)

expected = 5
assert expected == numbers.getNumberFromSpoken(5)
Expand Down Expand Up @@ -361,12 +361,12 @@ def test_get_number_back_from_spoken_form(unimacro_setup):
# originalList ints:
originalList = [0,1,2]
expected = None
input = 'four'
assert expected == numbers.getNumberFromSpoken(input, originalList)
Input = 'four'
assert expected == numbers.getNumberFromSpoken(Input, originalList)
expected = 1

input = 'on\xe9'
assert expected == numbers.getNumberFromSpoken(input, originalList)
Input = 'on\xe9'
assert expected == numbers.getNumberFromSpoken(Input, originalList)
expected = 1
assert expected == numbers.getNumberFromSpoken(1, originalList)
expected = None
Expand Down Expand Up @@ -487,10 +487,10 @@ def test_get_list_of_spoken_forms_sorted_by_number_values(unimacro_setup):


def test_format_spoken_forms_from_numbers_dict(unimacro_setup):
"""
"""test spoken forms
"""
func = inivars.formatReverseNumbersDict
assert func({1: ['on\xe9'], 2: ['two'], 3: ['three']}) == 'on\xe9 ... three'
assert func({1: ['oné'], 2: ['two'], 3: ['three']}) == 'oné ... three'

def test_get_punctuation_list(unimacro_setup):
"""test the punctuation from the punctuationreverse section
Expand Down

0 comments on commit 84e0170

Please sign in to comment.