-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Put actors process into library, so we can mock 'run' inside tests
- Loading branch information
1 parent
200876e
commit 70827ed
Showing
3 changed files
with
13 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
repos/system_upgrade/common/actors/udev/udevadminfo/libraries/udevadminfo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
7 changes: 4 additions & 3 deletions
7
repos/system_upgrade/common/actors/udev/udevadminfo/tests/test_udevadminfo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |