tests: Add basic tests for menu plugin

This checks basic features of kas menu, some option selection, yaml
including, rebuilding and target selection.

The UI is operated by mocking smack's GridFormHelp.runOnce and some
result evaluation functions. Injecting keys from the keyboard was not
easily possibly (if at all), thus this approach. The menu rendering is
not shown due to pytest.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
Jan Kiszka 2021-10-08 17:24:46 +02:00
parent da62e0bfbd
commit 95df3720e1
7 changed files with 153 additions and 1 deletions

View File

@ -8,6 +8,8 @@ on:
env: env:
SHELLCHECK_VERSION: v0.7.1 SHELLCHECK_VERSION: v0.7.1
SHELLCHECK_SHA256: 64f17152d96d7ec261ad3086ed42d18232fcb65148b44571b564d688269d36c8 SHELLCHECK_SHA256: 64f17152d96d7ec261ad3086ed42d18232fcb65148b44571b564d688269d36c8
NEWT_VERSION: 0.52.21
NEWT_SHA256: 265eb46b55d7eaeb887fca7a1d51fe115658882dfe148164b6c49fccac5abb31
jobs: jobs:
perform_tests: perform_tests:
@ -38,10 +40,26 @@ jobs:
echo "$SHELLCHECK_SHA256 shellcheck-$SHELLCHECK_VERSION.linux.x86_64.tar.xz" | sha256sum -c echo "$SHELLCHECK_SHA256 shellcheck-$SHELLCHECK_VERSION.linux.x86_64.tar.xz" | sha256sum -c
tar -xJf shellcheck-$SHELLCHECK_VERSION.linux.x86_64.tar.xz tar -xJf shellcheck-$SHELLCHECK_VERSION.linux.x86_64.tar.xz
sudo cp shellcheck-$SHELLCHECK_VERSION/shellcheck /usr/local/bin/ sudo cp shellcheck-$SHELLCHECK_VERSION/shellcheck /usr/local/bin/
- name: Install python-newt
run: |
sudo apt-get update
sudo apt-get install libpopt-dev libslang2-dev
wget -q https://releases.pagure.org/newt/newt-$NEWT_VERSION.tar.gz
echo "$NEWT_SHA256 newt-$NEWT_VERSION.tar.gz" | sha256sum -c
tar -C /tmp -xzf newt-$NEWT_VERSION.tar.gz
cd /tmp/newt-$NEWT_VERSION
autoconf
./configure --with-python=python${{ matrix.python-version }}
make -j $(nproc)
sudo make install
ln -s /usr/local/lib/python${{ matrix.python-version }}/site-packages/_snack.so \
$(python3 -c 'import site; print(site.getsitepackages()[0])')/
ln -s /usr/local/lib/python${{ matrix.python-version }}/site-packages/snack.py \
$(python3 -c 'import site; print(site.getsitepackages()[0])')/
- name: Run tests - name: Run tests
run: | run: |
scripts/checkcode.sh . scripts/checkcode.sh .
pytest TERM=xterm pytest
deploy_containers: deploy_containers:
name: Build and deploy container images name: Build and deploy container images

84
tests/test_menu.py Normal file
View File

@ -0,0 +1,84 @@
# kas - setup tool for bitbake based projects
#
# Copyright (c) Siemens AG, 2021
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import os
import shutil
from kas import kas
INPUTS = iter([' ', None, ' ', None])
ACTIONS = iter([None, 'build', None, 'build'])
SELECTIONS = iter([0, 3])
def mock_runOnce(unused1):
return next(INPUTS)
def mock_buttonPressed(unused1, unused2):
return next(ACTIONS)
def mock_current(unused1):
return next(SELECTIONS)
def file_contains(filename, expected):
with open(filename) as file:
for line in file.readlines():
if line == expected:
return True
return False
def check_bitbake_options(expected):
with open('build/bitbake.options') as file:
return file.readline() == expected
def test_menu(monkeypatch, tmpdir):
tdir = str(tmpdir.mkdir('test_menu'))
shutil.rmtree(tdir, ignore_errors=True)
shutil.copytree('tests/test_menu', tdir)
cwd = os.getcwd()
os.chdir(tdir)
monkeypatch.setattr('snack.GridFormHelp.runOnce', mock_runOnce)
monkeypatch.setattr('snack.ButtonBar.buttonPressed', mock_buttonPressed)
monkeypatch.setattr('snack.Listbox.current', mock_current)
# select opt1 & build
kas.kas(['menu'])
assert file_contains('build/conf/local.conf', 'OPT1 = "1"\n')
assert file_contains('.config.yaml', 'build_system: openembedded\n')
assert check_bitbake_options('-c build target1\n')
# rebuild test
kas.kas(['build'])
assert file_contains('build/conf/local.conf', 'OPT1 = "1"\n')
assert check_bitbake_options('-c build target1\n')
# select alternative target & build
kas.kas(['menu'])
assert file_contains('build/conf/local.conf', 'OPT1 = "1"\n')
assert check_bitbake_options('-c build target2\n')
os.chdir(cwd)

32
tests/test_menu/Kconfig Normal file
View File

@ -0,0 +1,32 @@
config KAS_INCLUDE_MAIN
string
default "test.yaml"
config KAS_BUILD_SYSTEM
string
default "openembedded"
config BOOL_OPT1
bool "ppt1"
config KAS_INCLUDE_OPT1
string
default "opt1.yaml"
depends on BOOL_OPT1
choice
prompt "choice"
default CHOICE1
config CHOICE1
bool "choice1"
config CHOICE2
bool "choice2"
endchoice
config KAS_TARGET_CHOICE
string
default "target1" if CHOICE1
default "target2" if CHOICE2

3
tests/test_menu/bitbake Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
echo "$@" > bitbake.options

View File

@ -0,0 +1,3 @@
#!/bin/sh
export PATH=$(pwd):$PATH

View File

@ -0,0 +1,7 @@
header:
version: 11
local_conf_header:
opt1: |
OPT1 = "1"

View File

@ -0,0 +1,5 @@
header:
version: 11
repos:
this: