From ed5473d6c6c3fe32be703bdddaa79c7c1f2ccac8 Mon Sep 17 00:00:00 2001 From: tomasfratrik Date: Tue, 12 Mar 2024 10:33:06 +0100 Subject: [PATCH] Add test to check if failed run correctly raised StopActorExecutionError --- .../udev/udevadminfo/libraries/udevadminfo.py | 2 +- .../udevadminfo/tests/test_udevadminfo.py | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/repos/system_upgrade/common/actors/udev/udevadminfo/libraries/udevadminfo.py b/repos/system_upgrade/common/actors/udev/udevadminfo/libraries/udevadminfo.py index 4be678e11c..8f36075b5d 100644 --- a/repos/system_upgrade/common/actors/udev/udevadminfo/libraries/udevadminfo.py +++ b/repos/system_upgrade/common/actors/udev/udevadminfo/libraries/udevadminfo.py @@ -14,6 +14,6 @@ def process(): details={ 'details': 'Failed to execute `udevadm info -e` command.', 'error': str(err) - } + } ) api.produce(UdevAdmInfoData(db=out)) diff --git a/repos/system_upgrade/common/actors/udev/udevadminfo/tests/test_udevadminfo.py b/repos/system_upgrade/common/actors/udev/udevadminfo/tests/test_udevadminfo.py index 8c7cea8a66..f465d6f6aa 100644 --- a/repos/system_upgrade/common/actors/udev/udevadminfo/tests/test_udevadminfo.py +++ b/repos/system_upgrade/common/actors/udev/udevadminfo/tests/test_udevadminfo.py @@ -1,13 +1,32 @@ import os +import pytest + +from leapp.exceptions import StopActorExecutionError from leapp.libraries.actor import udevadminfo from leapp.libraries.common import testutils -from leapp.libraries.stdlib import api, run +from leapp.libraries.stdlib import api, CalledProcessError from leapp.models import UdevAdmInfoData CUR_DIR = os.path.dirname(os.path.abspath(__file__)) +def _raise_call_error(*args): + raise CalledProcessError( + message='A Leapp Command Error occurred.', + command=args, + result={'signal': None, 'exit_code': 1, 'pid': 0, 'stdout': 'fake', 'stderr': 'fake'} + ) + + +def test_failed_run(monkeypatch): + monkeypatch.setattr(api, 'produce', testutils.produce_mocked()) + monkeypatch.setattr(udevadminfo, 'run', _raise_call_error) + + with pytest.raises(StopActorExecutionError): + udevadminfo.process() + + def test_udevadminfo(monkeypatch): with open(os.path.join(CUR_DIR, 'files', 'udevadm_database'), 'r') as fp: