From b92e47c276fe3379d0006525b324cfac4762fc45 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Thu, 20 May 2010 22:12:44 +0200 Subject: [PATCH] testsuite: mkfs() code cleanup Replace the long if ladder for mkfs special cases with option dictionaries. This makes it easier to extend in the future and the code easier to read. --- tests/run | 45 ++++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/tests/run b/tests/run index f47015d..420d39e 100755 --- a/tests/run +++ b/tests/run @@ -285,39 +285,26 @@ class UDisksTestCase(unittest.TestCase): def mkfs(klass, type, label=None, partition=None): '''Create file system using mkfs.''' - no_stderr = False - if type == 'vfat': - cmd = ['mkfs.vfat', '-F', '32'] - if label: - cmd += ['-n', label] - elif type == 'reiserfs': - cmd = ['mkfs.reiserfs', '-q'] - if label: - cmd += ['-l', label] - no_stderr = True - elif type == 'minix': + if type == 'minix': assert label is None, 'minix does not support labels' - cmd = ['mkfs.minix'] - elif type == 'swap': - cmd = ['mkswap', '-f'] - if label: - cmd += ['-L', label] - else: - cmd = ['mkfs.' + type, '-q'] - if label: - cmd += ['-L', label] - - if type == 'xfs': - # XFS complains if there's an existing FS, so --force - cmd.append('-f') + mkcmd = { 'swap': 'mkswap', + } + label_opt = { 'vfat': '-n', + 'reiserfs': '-l', + } + extra_opt = { 'vfat': [ '-F', '32'], + 'swap': ['-f'], + 'xfs': ['-f'], # XFS complains if there's an existing FS, so --force + } + + cmd = [mkcmd.get(type, 'mkfs.' + type)] + extra_opt.get(type, []) + if label: + cmd += [label_opt.get(type, '-L'), label] cmd.append(klass.devname(partition)) - if no_stderr: - assert subprocess.call(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE) == 0 - else: - assert subprocess.call(cmd, stdout=subprocess.PIPE) == 0 + assert subprocess.call(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) == 0 # kernel/udev generally detect those changes itself, but do not quite # tell us when they are done; so do a little kludge here to know how -- 2.7.4