diff --git a/dist/pythonlibs/riotctrl_shell/__init__.py b/dist/pythonlibs/riotctrl_shell/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/dist/pythonlibs/riotctrl_shell/requirements.txt b/dist/pythonlibs/riotctrl_shell/requirements.txt new file mode 100644 index 0000000000..44feee93b7 --- /dev/null +++ b/dist/pythonlibs/riotctrl_shell/requirements.txt @@ -0,0 +1 @@ +git+ssh://git@github.com/RIOT-OS/riotctrl diff --git a/dist/pythonlibs/riotctrl_shell/sys.py b/dist/pythonlibs/riotctrl_shell/sys.py new file mode 100644 index 0000000000..e6f563c921 --- /dev/null +++ b/dist/pythonlibs/riotctrl_shell/sys.py @@ -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_) diff --git a/dist/pythonlibs/riotctrl_shell/tests/__init__.py b/dist/pythonlibs/riotctrl_shell/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/dist/pythonlibs/riotctrl_shell/tests/common.py b/dist/pythonlibs/riotctrl_shell/tests/common.py new file mode 100644 index 0000000000..3b50354b68 --- /dev/null +++ b/dist/pythonlibs/riotctrl_shell/tests/common.py @@ -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 diff --git a/dist/pythonlibs/riotctrl_shell/tests/test_sys.py b/dist/pythonlibs/riotctrl_shell/tests/test_sys.py new file mode 100644 index 0000000000..df71fc60b2 --- /dev/null +++ b/dist/pythonlibs/riotctrl_shell/tests/test_sys.py @@ -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" diff --git a/dist/pythonlibs/riotctrl_shell/tox.ini b/dist/pythonlibs/riotctrl_shell/tox.ini new file mode 100644 index 0000000000..c4a0d92396 --- /dev/null +++ b/dist/pythonlibs/riotctrl_shell/tox.ini @@ -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 .