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:
parent
cdacdd79e6
commit
fa9deae489
0
dist/pythonlibs/riotctrl_shell/__init__.py
vendored
Normal file
0
dist/pythonlibs/riotctrl_shell/__init__.py
vendored
Normal file
1
dist/pythonlibs/riotctrl_shell/requirements.txt
vendored
Normal file
1
dist/pythonlibs/riotctrl_shell/requirements.txt
vendored
Normal file
@ -0,0 +1 @@
|
||||
git+ssh://git@github.com/RIOT-OS/riotctrl
|
37
dist/pythonlibs/riotctrl_shell/sys.py
vendored
Normal file
37
dist/pythonlibs/riotctrl_shell/sys.py
vendored
Normal 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_)
|
0
dist/pythonlibs/riotctrl_shell/tests/__init__.py
vendored
Normal file
0
dist/pythonlibs/riotctrl_shell/tests/__init__.py
vendored
Normal file
34
dist/pythonlibs/riotctrl_shell/tests/common.py
vendored
Normal file
34
dist/pythonlibs/riotctrl_shell/tests/common.py
vendored
Normal 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
|
33
dist/pythonlibs/riotctrl_shell/tests/test_sys.py
vendored
Normal file
33
dist/pythonlibs/riotctrl_shell/tests/test_sys.py
vendored
Normal 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
20
dist/pythonlibs/riotctrl_shell/tox.ini
vendored
Normal 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 .
|
Loading…
Reference in New Issue
Block a user