Skip to content

Commit

Permalink
Refactor actor
Browse files Browse the repository at this point in the history
Put actors process into library, so we can mock 'run' inside tests
  • Loading branch information
tomasfratrik committed Feb 27, 2024
1 parent 200876e commit 70827ed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 2 additions & 3 deletions repos/system_upgrade/common/actors/udev/udevadminfo/actor.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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()
Original file line number Diff line number Diff line change
@@ -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))
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 70827ed

Please sign in to comment.