tests: improve layout_lines API

This commit is contained in:
matejcik
2019-10-18 13:31:57 +02:00
parent 598e828844
commit c970ad437d
2 changed files with 44 additions and 21 deletions

View File

@@ -14,6 +14,7 @@
# You should have received a copy of the License along with this library.
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
from collections import namedtuple
from copy import deepcopy
from mnemonic import Mnemonic
@@ -25,6 +26,13 @@ from .tools import expect
EXPECTED_RESPONSES_CONTEXT_LINES = 3
LayoutLines = namedtuple("LayoutLines", "lines text")
def layout_lines(lines):
return LayoutLines(lines, " ".join(lines))
class DebugLink:
def __init__(self, transport, auto_interact=True):
self.transport = transport
@@ -46,9 +54,12 @@ class DebugLink:
def state(self):
return self._call(proto.DebugLinkGetState())
def read_layout(self):
return layout_lines(self.state().layout_lines)
def wait_layout(self):
obj = self._call(proto.DebugLinkGetState(wait_layout=True))
return obj.layout_lines
return layout_lines(obj.layout_lines)
def read_pin(self):
state = self.state()
@@ -100,7 +111,7 @@ class DebugLink:
)
ret = self._call(decision, nowait=not wait)
if ret is not None:
return ret.lines
return layout_lines(ret.lines)
def click(self, click, wait=False):
x, y = click