tests: more robust check for the default urgency level of dch
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 7 Jan 2014 14:10:03 +0000 (16:10 +0200)
committerGuido Günther <agx@sigxcpu.org>
Thu, 27 Mar 2014 19:33:28 +0000 (20:33 +0100)
The dch tool might not report it's version if it is incorrectly
compiled. Create a dummy changelog and parse it "manually" to determine
the default urgency level.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
tests/testutils.py

index 0b935b7..d04f5fe 100644 (file)
@@ -91,17 +91,22 @@ class MockedChangeLog(ChangeLog):
 
 def get_dch_default_urgency():
     """Determine the default urgency level used by dch"""
+    urgency='medium'
+    tmp_dch_name = '__test_dch'
     try:
-        popen = subprocess.Popen(['dch', '--version'], stdout=subprocess.PIPE)
-        out, _err = popen.communicate()
+        dch_cmd = ['dch', '--create', '--empty', '--changelog', tmp_dch_name,
+                   '--package=foo', '--newversion=1',
+                   '--distribution=UNRELEASED']
+        ret = subprocess.Popen(dch_cmd).wait()
     except OSError:
-        urgency='medium'
+        pass
     else:
-        verstr = out.splitlines()[0].split()[-1]
-        major, minor = verstr.split('.')[0:2]
-        if int(major) <= 2 and int(minor) <= 12:
-            urgency = 'low'
-        else:
-            urgency = 'medium'
+        if ret == 0:
+            with open(tmp_dch_name) as dchfile:
+                header = dchfile.readline().strip()
+                urgency = header.split()[-1].replace('urgency=', '')
+    finally:
+        if os.path.isfile(tmp_dch_name):
+            os.unlink(tmp_dch_name)
     return urgency