Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/tests #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/build
*.egg-info
__pycache__
.tox
*.eggs/README.txt
/.coverage
2 changes: 2 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest-cov==3.0.0
labgrid
9 changes: 4 additions & 5 deletions labgridhelper/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ def get_systemd_status_raw(command):
services[name]["active"] = next(data)
services[name]["sub"] = next(data)
services[name]["follow"] = next(data)
path_and_id = next(data)
pos = path_and_id.index('"')
services[name]["path"] = path_and_id[:pos]
services[name]["id"] = int(path_and_id[pos+1:-1].strip(" "))
services[name]["type"] = path_and_id[path_and_id.rfind('"'):]
path_and_id = next(data).split('\"')
services[name]["path"] = path_and_id[0]
services[name]["id"] = int(path_and_id[1].strip(" "))
services[name]["type"] = path_and_id[2]
services[name]["objpath"] = next(data)

return services
Expand Down
12 changes: 12 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest

from labgrid.driver.fake import FakeCommandDriver
from labgrid import Target


@pytest.fixture
def command():
t = Target("dummy")
d = FakeCommandDriver(t, "command")
t.activate(d)
return d
36 changes: 36 additions & 0 deletions tests/test_linux.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from labgridhelper import linux
import pytest

def test_get_systemd_version(command, monkeypatch):
systemd_version = 'systemd 249 (249.5-2-arch)\n+PAM +AUDIT -SELINUX\n'

monkeypatch.setattr(command, 'run_check', lambda cmd: [systemd_version])

assert linux.get_systemd_version(command) == 249

@pytest.mark.parametrize("systemd_version", [230, 240])
def test_get_systemd_status(command, monkeypatch, systemd_version):
monkeypatch.setattr(linux, 'get_systemd_version', lambda cmd: systemd_version)

status = {
230: 'a(ssssssouso) 1 "systemd-resolved.service" "Network Name Resolution" "loaded" "active"' + \
' "running" "" "/org/freedesktop/systemd1/unit/systemd_2dresolved_2eservice" 0 "" "/"',
240: '{"type":"a(ssssssouso)","data":[[["systemd-resolved.service",' + \
'"Network Name Resolution","loaded","active","running","",' + \
'"/org/freedesktop/systemd1/unit/systemd_2dresolved_2eservice",0,"","/"]]]}',
}

monkeypatch.setattr(command, 'run_check', lambda cmd: [status[systemd_version]])

status = linux.get_systemd_status(command)

assert len(status.keys()) == 1
assert status['systemd-resolved.service']["description"] == 'Network Name Resolution'
assert status['systemd-resolved.service']["load"] == 'loaded'
assert status['systemd-resolved.service']["active"] == 'active'
assert status['systemd-resolved.service']["sub"] == 'running'
assert status['systemd-resolved.service']["follow"] == ''
assert status['systemd-resolved.service']["path"] == '/org/freedesktop/systemd1/unit/systemd_2dresolved_2eservice'
assert status['systemd-resolved.service']["id"] == 0
assert status['systemd-resolved.service']["type"] == ''
assert status['systemd-resolved.service']["objpath"] == '/'
9 changes: 9 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tox]
envlist = py35, py36, py37

[testenv]
deps = -rdev-requirements.txt
commands =
pytest tests {posargs} \
--cov={envsitepackagesdir}/labgridhelper \
--cov-report=html:htmlcov