refactor menu test to ease extending it
This patch refactors the menu test by moving the monkey patching out into a fixture. When changing the cwd, we now use the monkeypatch tooling. By that, the following tests are not affected by a failure in a previous one, which leads to a cleaner test report. Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com> Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
parent
a1f38f9979
commit
ea0baa06d0
@ -20,26 +20,31 @@
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import snack
|
||||
import pytest
|
||||
from kas import kas
|
||||
|
||||
INPUTS = iter([' ', None, ' ', None])
|
||||
ACTIONS = iter([None, 'build', None, 'build'])
|
||||
SELECTIONS = iter([0, 3])
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def patch_kas(monkeypatch):
|
||||
INPUTS = iter([' ', None, ' ', None])
|
||||
ACTIONS = iter([None, 'build', None, 'build'])
|
||||
SELECTIONS = iter([0, 3])
|
||||
|
||||
def mock_runOnce(unused1):
|
||||
def mock_runOnce(unused1):
|
||||
return next(INPUTS)
|
||||
|
||||
|
||||
def mock_buttonPressed(unused1, unused2):
|
||||
def mock_buttonPressed(unused1, unused2):
|
||||
return next(ACTIONS)
|
||||
|
||||
|
||||
def mock_current(unused1):
|
||||
def mock_current(unused1):
|
||||
return next(SELECTIONS)
|
||||
|
||||
monkeypatch.setattr(snack.GridFormHelp, 'runOnce', mock_runOnce)
|
||||
monkeypatch.setattr(snack.ButtonBar, 'buttonPressed', mock_buttonPressed)
|
||||
monkeypatch.setattr(snack.Listbox, 'current', mock_current)
|
||||
|
||||
|
||||
def file_contains(filename, expected):
|
||||
with open(filename) as file:
|
||||
@ -57,12 +62,7 @@ def check_bitbake_options(expected):
|
||||
def test_menu(monkeypatch, tmpdir):
|
||||
tdir = str(tmpdir / 'test_menu')
|
||||
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)
|
||||
monkeypatch.chdir(tdir)
|
||||
|
||||
# select opt1 & build
|
||||
kas.kas(['menu'])
|
||||
@ -79,5 +79,3 @@ def test_menu(monkeypatch, tmpdir):
|
||||
kas.kas(['menu'])
|
||||
assert file_contains('build/conf/local.conf', 'OPT1 = "1"\n')
|
||||
assert check_bitbake_options('-c build target2\n')
|
||||
|
||||
os.chdir(cwd)
|
||||
|
Loading…
Reference in New Issue
Block a user