forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scripts: pytest: add Shell helper unit tests
Add unit tests dedicated for Shell helper sample class. Add shell_simulator_script.py script to simulate shell application behavior. Signed-off-by: Piotr Golyzniak <piotr.golyzniak@nordicsemi.no>
- Loading branch information
Showing
7 changed files
with
115 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
scripts/pylib/pytest-twister-harness/tests/helpers/shell_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright (c) 2023 Nordic Semiconductor ASA | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from twister_harness.device.binary_adapter import NativeSimulatorAdapter | ||
from twister_harness.helpers.shell import Shell | ||
|
||
|
||
def test_if_shell_helper_properly_send_command(shell_simulator_adapter: NativeSimulatorAdapter) -> None: | ||
"""Run shell_simulator.py program, send "zen" command via shell helper and verify output.""" | ||
shell = Shell(shell_simulator_adapter) | ||
assert shell.wait_for_prompt(timeout=5.0) | ||
lines = shell.exec_command('zen', timeout=5.0) | ||
assert 'The Zen of Python, by Tim Peters' in lines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
scripts/pylib/pytest-twister-harness/tests/resources/shell_simulator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright (c) 2023 Nordic Semiconductor ASA | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
""" | ||
Simple shell simulator. | ||
""" | ||
import sys | ||
|
||
from zen_of_python import zen_of_python | ||
|
||
PROMPT = 'uart:~$ ' | ||
|
||
|
||
def main() -> int: | ||
print('Start shell simulator', flush=True) | ||
print(PROMPT, end='', flush=True) | ||
for line in sys.stdin: | ||
line = line.strip() | ||
print(line, flush=True) | ||
if line == 'quit': | ||
break | ||
elif line == 'zen': | ||
for zen_line in zen_of_python: | ||
print(zen_line, flush=True) | ||
|
||
print(PROMPT, end='', flush=True) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
29 changes: 29 additions & 0 deletions
29
scripts/pylib/pytest-twister-harness/tests/resources/zen_of_python.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright (c) 2023 Nordic Semiconductor ASA | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from __future__ import annotations | ||
|
||
zen_of_python: list[str] = """ | ||
The Zen of Python, by Tim Peters | ||
Beautiful is better than ugly. | ||
Explicit is better than implicit. | ||
Simple is better than complex. | ||
Complex is better than complicated. | ||
Flat is better than nested. | ||
Sparse is better than dense. | ||
Readability counts. | ||
Special cases aren't special enough to break the rules. | ||
Although practicality beats purity. | ||
Errors should never pass silently. | ||
Unless explicitly silenced. | ||
In the face of ambiguity, refuse the temptation to guess. | ||
There should be one-- and preferably only one --obvious way to do it. | ||
Although that way may not be obvious at first unless you're Dutch. | ||
Now is better than never. | ||
Although never is often better than *right* now. | ||
If the implementation is hard to explain, it's a bad idea. | ||
If the implementation is easy to explain, it may be a good idea. | ||
Namespaces are one honking great idea -- let's do more of those! | ||
""".split('\n') |