From 70827ede613fd21933b0b45863aa3bd6925dafb1 Mon Sep 17 00:00:00 2001 From: tomasfratrik Date: Tue, 27 Feb 2024 13:51:43 +0100 Subject: [PATCH] Refactor actor Put actors process into library, so we can mock 'run' inside tests --- .../system_upgrade/common/actors/udev/udevadminfo/actor.py | 5 ++--- .../actors/udev/udevadminfo/libraries/udevadminfo.py | 7 +++++++ .../actors/udev/udevadminfo/tests/test_udevadminfo.py | 7 ++++--- 3 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 repos/system_upgrade/common/actors/udev/udevadminfo/libraries/udevadminfo.py diff --git a/repos/system_upgrade/common/actors/udev/udevadminfo/actor.py b/repos/system_upgrade/common/actors/udev/udevadminfo/actor.py index b674e56c5d..4f3b0117ac 100644 --- a/repos/system_upgrade/common/actors/udev/udevadminfo/actor.py +++ b/repos/system_upgrade/common/actors/udev/udevadminfo/actor.py @@ -1,5 +1,5 @@ from leapp.actors import Actor -from leapp.libraries.stdlib import run +from leapp.libraries.actor import udevadminfo from leapp.models import UdevAdmInfoData from leapp.tags import FactsPhaseTag, IPUWorkflowTag @@ -15,5 +15,4 @@ class UdevAdmInfo(Actor): tags = (IPUWorkflowTag, FactsPhaseTag,) def process(self): - out = run(['udevadm', 'info', '-e'])['stdout'] - self.produce(UdevAdmInfoData(db=out)) + udevadminfo.process() \ No newline at end of file diff --git a/repos/system_upgrade/common/actors/udev/udevadminfo/libraries/udevadminfo.py b/repos/system_upgrade/common/actors/udev/udevadminfo/libraries/udevadminfo.py new file mode 100644 index 0000000000..9df4c846a4 --- /dev/null +++ b/repos/system_upgrade/common/actors/udev/udevadminfo/libraries/udevadminfo.py @@ -0,0 +1,7 @@ +from leapp.models import UdevAdmInfoData +from leapp.libraries.stdlib import run, api + + +def process(): + out = run(['udevadm', 'info', '-e'])['stdout'] + api.produce(UdevAdmInfoData(db=out)) \ No newline at end of file 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 a4c8ec3605..46920f830b 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,19 +1,20 @@ import os from leapp.libraries.actor import udevadminfo -from leapp.libraries.stdlib import api +from leapp.libraries.stdlib import api, run from leapp.libraries.common import testutils from leapp.models import UdevAdmInfoData CUR_DIR = os.path.dirname(os.path.abspath(__file__)) + def test_udevadminfo(monkeypatch): + with open(os.path.join(CUR_DIR, 'files', 'udevadm_database'), 'r') as fp: mocked_data = fp.read() - monkeypatch.setattr(api, 'produce', testutils.produce_mocked()) monkeypatch.setattr(udevadminfo, 'run', lambda *args: {'stdout': mocked_data}) udevadminfo.process() assert api.produce.called == 1 assert isinstance(api.produce.model_instances[0], UdevAdmInfoData) - assert api.produce.model_instances[0].db == UdevAdmInfoData(db=mocked_data).db + assert api.produce.model_instances[0].db == UdevAdmInfoData(db=mocked_data).db \ No newline at end of file