summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoss Lagerwall <rosslagerwall@gmail.com>2015-06-21 09:34:07 +0100
committerMartin Pitt <martin.pitt@ubuntu.com>2015-06-29 16:29:41 +0200
commit2705225f0f66eda01e93b226d12e3749b1ece64b (patch)
treef090fbc05c5e9e1378a546f6c125512635dcd388
parent2207efd82b01296277da6f460d87c0d34ac6e0ee (diff)
integration-tests: Add a wrapper to write and flush stderr
sys.stderr is line-buffered by default which means that the status updates (e.g. '[wait for data]') do not show up until after the test has finished. Introduce a wrapper which writes to and flushes stderr. https://bugs.freedesktop.org/show_bug.cgi?id=91043
-rwxr-xr-xsrc/tests/integration-test30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/tests/integration-test b/src/tests/integration-test
index 59fdeb0..d675cb4 100755
--- a/src/tests/integration-test
+++ b/src/tests/integration-test
@@ -193,7 +193,7 @@ class UDisksTestCase(unittest.TestCase):
time.sleep(0.1)
timeout -= 1
if timeout <= 0:
- sys.stderr.write('[wait timeout!] ')
+ self.write_stderr('[wait timeout!] ')
@classmethod
def zero_device(klass):
@@ -324,7 +324,7 @@ class UDisksTestCase(unittest.TestCase):
except GLib.GError as e:
if 'UDisks2.Error.DeviceBusy' not in e.message:
raise
- sys.stderr.write('[busy] ')
+ self.write_stderr('[busy] ')
time.sleep(0.3)
timeout -= 1
@@ -487,6 +487,11 @@ class UDisksTestCase(unittest.TestCase):
self.assertEventually(lambda: obj.get_property(name), value)
+ def write_stderr(self, msg):
+ '''Write to stderr without buffering'''
+ sys.stderr.write(msg)
+ sys.stderr.flush()
+
# ----------------------------------------------------------------------------
@@ -602,7 +607,7 @@ class FS(UDisksTestCase):
def tearDown(self):
if subprocess.call(['umount', self.device], stderr=subprocess.PIPE) == 0:
- sys.stderr.write('[cleanup unmount] ')
+ self.write_stderr('[cleanup unmount] ')
shutil.rmtree(self.workdir)
def test_zero(self):
@@ -802,7 +807,7 @@ class FS(UDisksTestCase):
if type != 'swap' and subprocess.call(['which', mkfs],
stdout=subprocess.PIPE) != 0:
- sys.stderr.write('[no %s, skip] ' % mkfs)
+ self.write_stderr('[no %s, skip] ' % mkfs)
# check correct D-Bus exception
try:
@@ -813,8 +818,7 @@ class FS(UDisksTestCase):
return
# do checks with command line tools (mkfs/mount/umount)
- sys.stderr.write('[cli] ')
- sys.stderr.flush()
+ self.write_stderr('[cli] ')
self._do_cli_check(type)
if type != 'minix':
@@ -829,7 +833,7 @@ class FS(UDisksTestCase):
self.mkfs('ext3')
# do checks with udisks operations
- sys.stderr.write('[ud] ')
+ self.write_stderr('[ud] ')
self._do_udisks_check(type)
if type != 'minix':
self._do_udisks_check(type, 'test%stst' % type)
@@ -883,7 +887,7 @@ class FS(UDisksTestCase):
ret = subprocess.call([mount_prog, self.device, mount_a])
if ret == 32:
# missing fs driver
- sys.stderr.write('[missing kernel driver, skip] ')
+ self.write_stderr('[missing kernel driver, skip] ')
return
self.assertEqual(ret, 0)
@@ -1191,7 +1195,7 @@ class Smart(UDisksTestCase):
hd = '/dev/sda'
if not os.path.exists(hd):
- sys.stderr.write('[skip] ')
+ self.write_stderr('[skip] ')
return
has_smart = subprocess.call(['skdump', '--can-smart', hd],
@@ -1205,13 +1209,13 @@ class Smart(UDisksTestCase):
self.assertEqual(ata is not None, has_smart)
if has_smart:
- sys.stderr.write('[avail] ')
+ self.write_stderr('[avail] ')
self.assertEqual(ata.get_property('smart-supported'), True)
self.assertEqual(ata.get_property('smart-enabled'), True)
# wait for SMART data to be read
while ata.get_property('smart-updated') == 0:
- sys.stderr.write('[wait for data] ')
+ self.write_stderr('[wait for data] ')
self.client.settle()
time.sleep(0.5)
@@ -1222,7 +1226,7 @@ class Smart(UDisksTestCase):
['success', 'inprogress', 'aborted',
'interrupted'])
else:
- sys.stderr.write('[N/A] ')
+ self.write_stderr('[N/A] ')
# ----------------------------------------------------------------------------
@@ -1239,7 +1243,7 @@ class Luks(UDisksTestCase):
if encrypted:
try:
encrypted.call_lock_sync(no_options, None)
- sys.stderr.write('[cleanup lock] ')
+ self.write_stderr('[cleanup lock] ')
except GLib.GError:
pass