]> arthur.barton.de Git - bup.git/commitdiff
Fix use of Python assert() with respect to optimization.
authorRob Browning <rlb@defaultvalue.org>
Sun, 3 Mar 2013 22:51:14 +0000 (16:51 -0600)
committerRob Browning <rlb@defaultvalue.org>
Fri, 8 Mar 2013 00:36:47 +0000 (18:36 -0600)
Fix a number of places where bup's assertions had material
side-effects, or where other code expected to see the AssertionError,
neither of which happen when optimization is enabled.

Reported-by: Jon Dowland <jmtd@debian.org>
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
cmd/midx-cmd.py
lib/bup/client.py
lib/bup/git.py
lib/bup/helpers.py
lib/bup/t/tclient.py

index 1243c8d5e63b6f65531a4beb8ee3b491f6486a62..62011e4a33cf4eb70ed383ca3a57f35d74c5814b 100755 (executable)
@@ -135,7 +135,8 @@ def _do_midx(outdir, outfilename, infilenames, prefixstr):
         print p.idxnames
         assert(len(p) == total)
         for pe, e in p, git.idxmerge(inp, final_progress=False):
-            assert(i == pi.next())
+            pin = pi.next()
+            assert(i == pin)
             assert(p.exists(i))
 
     return total, outfilename
index c2c83e2f0c42dd7ea28d5b41b99d5f4835030872..7f9334b146361d259135067ddbf73784571e5905 100644 (file)
@@ -40,7 +40,8 @@ def parse_remote(remote):
     url_match = re.match(
             '%s(?:%s%s)?%s' % (protocol, host, port, path), remote, re.I)
     if url_match:
-        assert(url_match.group(1) in ('ssh', 'bup', 'file'))
+        if not url_match.group(1) in ('ssh', 'bup', 'file'):
+            raise ClientError, 'unexpected protocol: %s' % url_match.group(1)
         return url_match.group(1,3,4,5)
     else:
         rs = remote.split(':', 1)
index ad4668b2a388a423ad6dcb4ae12c93e3066ef0c5..403b969baf9aa7451e55377a6455e473705fe990 100644 (file)
@@ -962,7 +962,8 @@ class CatPipe:
         if not self.p or self.p.poll() != None:
             self._restart()
         assert(self.p)
-        assert(self.p.poll() == None)
+        poll_result = self.p.poll()
+        assert(poll_result == None)
         if self.inprogress:
             log('_fast_get: opening %r while %r is open\n'
                 % (id, self.inprogress))
@@ -988,7 +989,8 @@ class CatPipe:
             yield type
             for blob in it:
                 yield blob
-            assert(self.p.stdout.readline() == '\n')
+            readline_result = self.p.stdout.readline()
+            assert(readline_result == '\n')
             self.inprogress = None
         except Exception, e:
             it.abort()
index ca9358aae518e14711577b9b0f52ab40657e2896..c136aeb1c08bc0788f063438578184bc0eec5354 100644 (file)
@@ -741,7 +741,8 @@ def path_components(path):
     full_path_to_name).  Path must start with '/'.
     Example:
       '/home/foo' -> [('', '/'), ('home', '/home'), ('foo', '/home/foo')]"""
-    assert(path.startswith('/'))
+    if not path.startswith('/'):
+        raise Exception, 'path must start with "/": %s' % path
     # Since we assume path startswith('/'), we can skip the first element.
     result = [('', '/')]
     norm_path = os.path.abspath(path)
index 85dd8b211eaf18ad9773cd69092f7d7992852e0f..78d845cf28d7e940844cdda1cf7cbe491dc68e7c 100644 (file)
@@ -144,5 +144,5 @@ def test_remote_parsing():
     try:
         client.parse_remote('http://asdf.com/bup')
         WVFAIL()
-    except AssertionError:
+    except client.ClientError:
         WVPASS()