Skip to content

Commit

Permalink
tests: fix qvm-run test on travis
Browse files Browse the repository at this point in the history
stdout there is not a tty, which change default value of filter_esc.
  • Loading branch information
marmarek committed Jun 25, 2017
1 parent 3cf5840 commit c545c95
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions qubesadmin/tests/tools/qvm_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# with this program; if not, see <http://www.gnu.org/licenses/>.

import io
import os
import unittest.mock

import subprocess
Expand All @@ -34,6 +35,10 @@ def setUp(self):
sys.stderr is not sys.__stderr__:
self.skipTest('qvm-run change behavior on redirected stdout/stderr')
super(TC_00_qvm_run, self).setUp()

def default_filter_esc(self):
return os.isatty(sys.stdout.fileno())

def test_000_run_single(self):
self.app.expected_calls[
('dom0', 'admin.vm.List', None, None)] = \
Expand All @@ -47,7 +52,7 @@ def test_000_run_single(self):
self.assertEqual(ret, 0)
self.assertEqual(self.app.service_calls, [
('test-vm', 'qubes.VMShell', {
'filter_esc': True,
'filter_esc': self.default_filter_esc(),
'localcmd': None,
'stdout': subprocess.DEVNULL,
'stderr': subprocess.DEVNULL,
Expand All @@ -71,15 +76,15 @@ def test_001_run_multiple(self):
self.assertEqual(ret, 0)
self.assertEqual(self.app.service_calls, [
('test-vm', 'qubes.VMShell', {
'filter_esc': True,
'filter_esc': self.default_filter_esc(),
'localcmd': None,
'stdout': subprocess.DEVNULL,
'stderr': subprocess.DEVNULL,
'user': None,
}),
('test-vm', 'qubes.VMShell', b'command; exit\n'),
('test-vm2', 'qubes.VMShell', {
'filter_esc': True,
'filter_esc': self.default_filter_esc(),
'localcmd': None,
'stdout': subprocess.DEVNULL,
'stderr': subprocess.DEVNULL,
Expand All @@ -105,7 +110,7 @@ def test_002_passio(self):
self.assertEqual(ret, 0)
self.assertEqual(self.app.service_calls, [
('test-vm', 'qubes.VMShell', {
'filter_esc': True,
'filter_esc': self.default_filter_esc(),
'localcmd': None,
'stdout': None,
'stderr': None,
Expand All @@ -127,7 +132,8 @@ def test_002_color_output(self):
with unittest.mock.patch('sys.stdin', echo.stdout):
with unittest.mock.patch('sys.stdout', stdout):
ret = qubesadmin.tools.qvm_run.main(
['--no-gui', '--pass-io', 'test-vm', 'command'],
['--no-gui', '--filter-esc', '--pass-io', 'test-vm',
'command'],
app=self.app)

self.assertEqual(ret, 0)
Expand Down Expand Up @@ -164,7 +170,7 @@ def test_003_no_color_output(self):
self.assertEqual(ret, 0)
self.assertEqual(self.app.service_calls, [
('test-vm', 'qubes.VMShell', {
'filter_esc': True,
'filter_esc': self.default_filter_esc(),
'localcmd': None,
'stdout': None,
'stderr': None,
Expand Down Expand Up @@ -221,7 +227,7 @@ def test_005_localcmd(self):
self.assertEqual(ret, 0)
self.assertEqual(self.app.service_calls, [
('test-vm', 'qubes.VMShell', {
'filter_esc': True,
'filter_esc': self.default_filter_esc(),
'localcmd': 'local-command',
'stdout': None,
'stderr': None,
Expand Down Expand Up @@ -253,7 +259,7 @@ def test_006_run_single_with_gui(self):
}),
('test-vm', 'qubes.WaitForSession', b'user'),
('test-vm', 'qubes.VMShell', {
'filter_esc': True,
'filter_esc': self.default_filter_esc(),
'localcmd': None,
'stdout': subprocess.DEVNULL,
'stderr': subprocess.DEVNULL,
Expand Down Expand Up @@ -285,7 +291,7 @@ def test_007_run_service_with_gui(self):
}),
('test-vm', 'qubes.WaitForSession', b'user'),
('test-vm', 'service.name', {
'filter_esc': True,
'filter_esc': self.default_filter_esc(),
'localcmd': None,
'stdout': subprocess.DEVNULL,
'stderr': subprocess.DEVNULL,
Expand Down

0 comments on commit c545c95

Please sign in to comment.