From 3cad37152d739eea49f5114e8a7d269326311296 Mon Sep 17 00:00:00 2001 From: Ross Lagerwall Date: Sun, 21 Jun 2015 09:34:07 +0100 Subject: [PATCH] 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 --- src/tests/integration-test | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/tests/integration-test b/src/tests/integration-test index 337dbf8..68fe92b 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) @@ -1221,7 +1225,7 @@ class Smart(UDisksTestCase): self.assertIn(ata.get_property('smart-selftest-status'), ['success', 'inprogress', 'aborted']) else: - sys.stderr.write('[N/A] ') + self.write_stderr('[N/A] ') # ---------------------------------------------------------------------------- @@ -1238,7 +1242,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 -- 2.4.2