1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 04:52:59 +01:00

riotctrl_shell: initial import of shell interaction riotctrl wrapper

This commit is contained in:
Martine Lenders 2019-04-16 17:38:40 +02:00 committed by Martine S. Lenders
parent cdacdd79e6
commit fa9deae489
No known key found for this signature in database
GPG Key ID: CCD317364F63286F
7 changed files with 125 additions and 0 deletions

View File

View File

@ -0,0 +1 @@
git+ssh://git@github.com/RIOT-OS/riotctrl

37
dist/pythonlibs/riotctrl_shell/sys.py vendored Normal file
View File

@ -0,0 +1,37 @@
# Copyright (C) 20 Freie Universität Berlin
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
"""
sys-related shell interactions
Defines sys-related shell command interactions
"""
from riotctrl.shell import ShellInteraction
class Help(ShellInteraction):
"""Help ShellInteraction"""
@ShellInteraction.check_term
def help(self, timeout=-1, async_=False):
"""Sends the reboot command via the terminal"""
return self.cmd("help", timeout, async_)
class Reboot(ShellInteraction):
"""Reboot ShellInteraction"""
@ShellInteraction.check_term
def reboot(self, timeout=-1, async_=False):
"""Sends the reboot command via the terminal"""
return self.cmd("reboot", timeout, async_)
class Version(ShellInteraction):
"""Version ShellInteraction"""
@ShellInteraction.check_term
def version(self, timeout=-1, async_=False):
"""Sends the reboot command via the terminal"""
return self.cmd("version", timeout, async_)

View File

View File

@ -0,0 +1,34 @@
# Copyright (C) 2020 Freie Universität Berlin
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
class MockSpawn():
def __init__(self, *args, **kwargs):
# set some expected attributes
self.before = None
self.echo = False
def sendline(self, line, *args, **kwargs):
# just echo last input for before (what replwrap is assembling output
# from)
self.before = line
def expect_exact(self, *args, **kwargs):
# always match on prompt with replwrap
return 0
class MockRIOTCtrl():
"""
Mock RIOT ctrl
"""
def __init__(self, *args, **kwargs):
self.term = MockSpawn()
def init_ctrl():
rc = MockRIOTCtrl("foobar", env={"BOARD": "native"})
return rc

View File

@ -0,0 +1,33 @@
# Copyright (C) 2020 Freie Universität Berlin
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
import riotctrl_shell.sys
from .common import init_ctrl
def test_help():
rc = init_ctrl()
si = riotctrl_shell.sys.Help(rc)
res = si.help()
# mock just returns last input
assert res == "help"
def test_reboot():
rc = init_ctrl()
si = riotctrl_shell.sys.Reboot(rc)
res = si.reboot()
# mock just returns last input
assert res == "reboot"
def test_version():
rc = init_ctrl()
si = riotctrl_shell.sys.Version(rc)
res = si.version()
# mock just returns last input
assert res == "version"

20
dist/pythonlibs/riotctrl_shell/tox.ini vendored Normal file
View File

@ -0,0 +1,20 @@
[tox]
envlist = test,flake8
skipsdist = True
[testenv]
commands =
test: {[testenv:test]commands}
flake8: {[testenv:flake8]commands}
[testenv:test]
deps =
pytest
-rrequirements.txt
commands =
pytest -v
[testenv:flake8]
deps = flake8
commands =
flake8 .