-
-
Notifications
You must be signed in to change notification settings - Fork 621
/
notepadTests.py
155 lines (124 loc) · 4.51 KB
/
notepadTests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2021 NV Access Limited
# This file may be used under the terms of the GNU General Public License, version 2 or later.
# For more details see: https://www.gnu.org/licenses/gpl-2.0.html
"""Logic for reading text using NVDA in the notepad text editor.
"""
# imported methods start with underscore (_) so they don't get imported into robot files as keywords
import typing
from SystemTestSpy import (
_getLib,
)
# Imported for type information
from NotepadLib import NotepadLib as _NotepadLib
from AssertsLib import AssertsLib as _AssertsLib
import NvdaLib as _NvdaLib
from robot.libraries.BuiltIn import BuiltIn
builtIn: BuiltIn = BuiltIn()
_notepad: _NotepadLib = _getLib("NotepadLib")
_asserts: _AssertsLib = _getLib("AssertsLib")
navToNextCharKey = "numpad3"
navToNextWordKey = "numpad6"
navToNextLineKey = "numpad9"
def _pressKeyAndCollectSpeech(key: str, numberOfTimes: int) -> typing.List[str]:
actual = []
for _ in range(numberOfTimes):
spoken = _NvdaLib.getSpeechAfterKey(key)
# collect all output before asserting to show full picture of behavior
actual.append(spoken)
return actual
def test_moveByWord_symbolLevelWord():
spy = _NvdaLib.getSpyLib()
spy.set_configValue(["speech", "symbolLevelWordAll"], True)
# unlike other symbols used, symbols.dic doesn't preserve quote symbols with SYMPRES_ALWAYS
_wordsToExpected = {
'Say': 'Say',
'(quietly)': 'left paren(quietly right paren)',
'"Hello,': 'quote Hello comma,',
'Jim".': 'Jim quote dot.',
'➔': 'right-pointing arrow', # Speech for symbols shouldn't change
'👕': 't dash shirt', # Speech for symbols shouldn't change
}
textStr = ' '.join(_wordsToExpected.keys())
_notepad.prepareNotepad(f"Test: {textStr}")
actual = _pressKeyAndCollectSpeech(navToNextWordKey, numberOfTimes=len(_wordsToExpected))
builtIn.should_be_equal(actual, list(_wordsToExpected.values()))
def test_moveByWord():
spy = _NvdaLib.getSpyLib()
spy.set_configValue(["speech", "symbolLevelWordAll"], False)
_wordsToExpected = {
'Say': 'Say',
'(quietly)': '(quietly)',
'"Hello,': 'Hello,',
'Jim".': 'Jim .',
'➔': 'right-pointing arrow',
'👕': 't shirt',
}
textStr = ' '.join(_wordsToExpected.keys())
_notepad.prepareNotepad(f"Test: {textStr}")
actual = _pressKeyAndCollectSpeech(navToNextWordKey, numberOfTimes=len(_wordsToExpected))
builtIn.should_be_equal(actual, list(_wordsToExpected.values()))
def test_moveByLine():
spy = _NvdaLib.getSpyLib()
spy.set_configValue(["speech", "symbolLevelWordAll"], False)
_wordsToExpected = {
'Say': 'Say',
'(quietly)': '(quietly)',
'"Hello,': 'Hello,',
'Jim".': 'Jim .',
'➔': 'right-pointing arrow',
'👕': 't-shirt',
}
textStr = '\n'.join(_wordsToExpected.keys())
_notepad.prepareNotepad(f"Test:\n{textStr}") # initial new line which isn't spoken
actual = _pressKeyAndCollectSpeech(navToNextLineKey, numberOfTimes=len(_wordsToExpected))
builtIn.should_be_equal(actual, list(_wordsToExpected.values()))
def test_moveByLine_symbolLevelWord():
spy = _NvdaLib.getSpyLib()
spy.set_configValue(["speech", "symbolLevelWordAll"], True)
_wordsToExpected = {
'Say': 'Say',
'(quietly)': '(quietly)',
'"Hello,': 'Hello,',
'Jim".': 'Jim .',
'➔': 'right-pointing arrow',
'👕': 't-shirt',
}
textStr = '\n'.join(_wordsToExpected.keys())
_notepad.prepareNotepad(f"Test:\n{textStr}") # initial new line which isn't spoken
actual = _pressKeyAndCollectSpeech(navToNextLineKey, numberOfTimes=len(_wordsToExpected))
builtIn.should_be_equal(actual, list(_wordsToExpected.values()))
def test_moveByChar():
spy = _NvdaLib.getSpyLib()
spy.set_configValue(["speech", "symbolLevelWordAll"], False)
_text = 'S ()e,➔👕' # to speed up test, reduce superfluous characters
_expected = [
'S',
'space',
'left paren',
'right paren',
'e',
'comma',
'right dash pointing arrow',
't dash shirt',
]
_notepad.prepareNotepad(f" {_text}")
actual = _pressKeyAndCollectSpeech(navToNextCharKey, numberOfTimes=len(_expected))
builtIn.should_be_equal(actual, _expected)
def test_moveByChar_symbolLevelWord():
spy = _NvdaLib.getSpyLib()
spy.set_configValue(["speech", "symbolLevelWordAll"], True)
_text = 'S ()e,➔👕' # to speed up test, reduce superfluous characters
_expected = [
'S',
'space',
'left paren',
'right paren',
'e',
'comma',
'right dash pointing arrow',
't dash shirt',
]
_notepad.prepareNotepad(f" {_text}")
actual = _pressKeyAndCollectSpeech(navToNextCharKey, numberOfTimes=len(_expected))
builtIn.should_be_equal(actual, _expected)