File: test_bareboxdriver.py

package info (click to toggle)
labgrid 25.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,796 kB
  • sloc: python: 21,352; sh: 846; makefile: 35
file content (43 lines) | stat: -rw-r--r-- 1,650 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import pytest

from labgrid import Target
from labgrid.driver import BareboxDriver
from labgrid.driver.fake import FakeConsoleDriver
from labgrid.protocol import CommandProtocol, LinuxBootProtocol
from labgrid.driver import ExecutionError


class TestBareboxDriver:
    def test_create(self):
        t = Target('dummy')
        cp = FakeConsoleDriver(t, "console")
        d = BareboxDriver(t, "barebox")
        assert (isinstance(d, BareboxDriver))
        assert (isinstance(d, CommandProtocol))
        assert (isinstance(d, LinuxBootProtocol))

    def test_barebox_run(self, target_with_fakeconsole, mocker):
        t = target_with_fakeconsole
        d = BareboxDriver(t, "barebox")
        d = t.get_driver(BareboxDriver, activate=False)
        # mock for d._run('echo $global.loglevel')
        d._run = mocker.MagicMock(return_value=(['7'], [], 0))
        t.activate(d)
        d._run = mocker.MagicMock(return_value=(['success'], [], 0))
        res = d.run_check("test")
        assert res == ['success']
        res = d.run("test")
        assert res == (['success'], [], 0)

    def test_barebox_run_error(self, target_with_fakeconsole, mocker):
        t = target_with_fakeconsole
        d = BareboxDriver(t, "barebox")
        d = t.get_driver(BareboxDriver, activate=False)
        # mock for d._run('echo $global.loglevel')
        d._run = mocker.MagicMock(return_value=(['7'], [], 0))
        t.activate(d)
        d._run = mocker.MagicMock(return_value=(['error'], [], 1))
        with pytest.raises(ExecutionError):
            res = d.run_check("test")
        res = d.run("test")
        assert res == (['error'], [], 1)