Beispiel #1
0
    def test_on(self, target, mocker):
        pty = mocker.patch('pty.openpty')
        mocker.patch('fcntl.fcntl')
        fdopen = mocker.patch('os.fdopen')
        close = mocker.patch('os.close')
        popen = mocker.patch('subprocess.Popen')
        fd_mock = mocker.MagicMock()
        instance_mock = mocker.MagicMock()
        popen.return_value = instance_mock
        fdopen.return_value = fd_mock
        pty.return_value = (instance_mock, 2)
        fd_mock.read.return_value = b'Done\nDone'
        instance_mock.returncode = 0

        d = ExternalPowerDriver(target,
                                'power',
                                cmd_on='set -1 foo-board',
                                cmd_off='set -0 foo-board')
        target.activate(d)
        d.on()

        popen.assert_called_once_with(['set', '-1', 'foo-board'],
                                      bufsize=0,
                                      stderr=2,
                                      stdout=2)
Beispiel #2
0
    def test_on(self, target, mocker):
        m = mocker.patch('subprocess.check_call')

        d = ExternalPowerDriver(target,
                                cmd_on='set -1 foo-board',
                                cmd_off='set -0 foo-board')
        d.on()

        m.assert_called_once_with('set -1 foo-board')