[Pkg-bazaar-commits] ./bzr/unstable r302: testbzr: new backtick() helper

Martin Pool mbp at sourcefrog.net
Fri Apr 10 07:51:47 UTC 2009


------------------------------------------------------------
revno: 302
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Thu 2005-04-28 19:34:49 +1000
message:
  testbzr: new backtick() helper
modified:
  testbzr
-------------- next part --------------
=== modified file 'testbzr'
--- a/testbzr	2005-04-28 09:26:28 +0000
+++ b/testbzr	2005-04-28 09:34:49 +0000
@@ -39,7 +39,17 @@
     pass
 
 
-def runcmd(cmd, retcode=0, catchstdout=False):
+def formcmd(cmd):
+    if isinstance(cmd, basestring):
+        logfile.write('$ %s\n' % cmd)
+        cmd = cmd.split()
+    else:
+        logfile.write('$ %r\n' % cmd)
+
+    return cmd
+
+
+def runcmd(cmd, retcode=0):
     """Run one command and check the return code.
 
     Returns a tuple of (stdout,stderr) strings.
@@ -47,29 +57,31 @@
     If a single string is based, it is split into words.
     For commands that are not simple space-separated words, please
     pass a list instead."""
-    
-    if isinstance(cmd, basestring):
-        logfile.write('$ %s\n' % cmd)
-        cmd = cmd.split()
-    else:
-        logfile.write('$ %r\n' % cmd)
-    log_linenumber()
-
-    if catchstdout:
-        stdout = PIPE
-    else:
-        stdout = logfile
-        
-    child = Popen(cmd, stdout=stdout, stderr=logfile)
+    cmd = formcmd(cmd)
+    log_linenumber()
+    
+    actual_retcode = call(cmd, stdout=logfile, stderr=logfile)
+    
+    if retcode != actual_retcode:
+        raise CommandFailed("test failed: %r returned %d, expected %d"
+                            % (cmd, actual_retcode, retcode))
+
+
+
+def backtick(cmd, retcode=0):
+    cmd = formcmd(cmd)
+    log_linenumber()
+    child = Popen(cmd, stdout=PIPE, stderr=logfile)
     outd, errd = child.communicate()
-
+    logfile.write(outd)
     actual_retcode = child.wait()
     
     if retcode != actual_retcode:
         raise CommandFailed("test failed: %r returned %d, expected %d"
                             % (cmd, actual_retcode, retcode))
 
-    return outd, errd
+    return outd
+
 
 
 def progress(msg):
@@ -113,7 +125,7 @@
     # this should always identify something, if only "john at localhost"
     runcmd("bzr whoami")
     runcmd("bzr whoami --email")
-    assert runcmd("bzr whoami --email", catchstdout=True)[0].count('@') == 1
+    assert backtick("bzr whoami --email").count('@') == 1
 
     progress("invalid commands")
     runcmd("bzr pants", retcode=1)
@@ -128,7 +140,8 @@
     f.write('hello world!\n')
     f.close()
 
-    
+    unknowns = backtick("bzr unknowns").rstrip('\r\n')
+    assert unknowns == 'test.txt'
 
     cd('..')
 
@@ -136,7 +149,7 @@
 except Exception, e:
     sys.stderr.write('*' * 50 + '\n'
                      + 'testbzr: tests failed\n'
-                     + 'see bzr-test.log for more information\n'
+                     + 'see testbzr.log for more information\n'
                      + '*' * 50 + '\n')
     logfile.write('tests failed!\n')
     traceback.print_exc(None, logfile)



More information about the Pkg-bazaar-commits mailing list