Incorrect accquiring bugdir command line argument
[be.git] / libbe / storage / base.py
index ad6b291402d3340cd2dc5f971831370ab32a82c5..977179d97c32d1e6d16f62daad5eac48ef3bbee3 100644 (file)
@@ -1,18 +1,20 @@
-# Copyright (C) 2009-2010 W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2009-2012 Chris Ball <cjb@laptop.org>
+#                         W. Trevor King <wking@tremily.us>
 #
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
+# This file is part of Bugs Everywhere.
 #
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
+# Bugs Everywhere is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 2 of the License, or (at your option) any
+# later version.
 #
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# Bugs Everywhere is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Bugs Everywhere.  If not, see <http://www.gnu.org/licenses/>.
 
 """
 Abstract bug repository data storage to easily support multiple backends.
@@ -519,10 +521,8 @@ class VersionedStorage (Storage):
         raise InvalidRevision(i)
 
     def changed(self, revision):
-        """
-        Return a tuple of lists of ids
-          (new, modified, removed)
-        from the specified revision to the current situation.
+        """Return a tuple of lists of ids `(new, modified, removed)` from the
+        specified revision to the current situation.
         """
         new = []
         modified = []
@@ -563,18 +563,20 @@ if TESTING == True:
 
         def fail(self, msg=None):
             """Fail immediately, with the given message."""
-            raise self.failureException, \
-                '(%s) %s' % (self._classname(), msg)
+            raise self.failureException(
+                '({0}) {1}'.format(self._classname(), msg))
 
         def failIf(self, expr, msg=None):
             "Fail the test if the expression is true."
-            if expr: raise self.failureException, \
-                '(%s) %s' % (self._classname(), msg)
+            if expr:
+                raise self.failureException(
+                    '({0}) {1}'.format(self._classname(), msg))
 
         def failUnless(self, expr, msg=None):
             """Fail the test unless the expression is true."""
-            if not expr: raise self.failureException, \
-                '(%s) %s' % (self._classname(), msg)
+            if not expr:
+                raise self.failureException(
+                    '({0}) {1}'.format(self._classname(), msg))
 
         def setUp(self):
             """Set up test fixtures for Storage test case."""
@@ -681,6 +683,24 @@ if TESTING == True:
                 s = sorted(self.s.children('parent'))
                 self.failUnless(s == ids, '\n  %s\n  !=\n  %s' % (s, ids))
 
+        def test_grandchildren(self):
+            """Grandchildren should not be returned as children.
+            """
+            self.s.add('parent', directory=True)
+            ids = []
+            for i in range(5):
+                child = 'parent/%s' % str(i)
+                directory = (i % 2 == 0)
+                ids.append(child)
+                self.s.add(child, 'parent', directory=directory)
+                if directory:
+                    for j in range(3):
+                        grandchild = '%s/%s' % (child, str(j))
+                        directory = (j % 2 == 0)
+                        self.s.add(grandchild, child, directory=directory)
+                s = sorted(self.s.children('parent'))
+                self.failUnless(s == ids, '\n  %s\n  !=\n  %s' % (s, ids))
+
         def test_add_invalid_directory(self):
             """Should not be able to add children to non-directories.
             """
@@ -908,7 +928,7 @@ if TESTING == True:
                 self.s.commit('Added initialization files')
             except EmptyCommit:
                 pass
-                
+
         def test_revision_id_exception(self):
             """Invalid revision id should raise InvalidRevision.
             """
@@ -996,10 +1016,42 @@ if TESTING == True:
             for i in range(10):
                 ret = sorted(self.s.children('parent', revision=revs[i]))
                 self.failUnless(ret == children[i],
-                                "%s.get() returned %s not %s for revision %s"
+                                "%s.children() returned %s not %s for revision %s"
                                 % (vars(self.Class)['name'], ret,
                                    children[i], revs[i]))
 
+        def test_avoid_previous_grandchildren(self):
+            """Previous grandchildren should not be returned as children.
+            """
+            self.s.add('parent', directory=True)
+            revs = []
+            cur_children = []
+            children = []
+            for i in range(5):
+                new_child = 'parent/%s' % str(i)
+                directory = (i % 2 == 0)
+                self.s.add(new_child, 'parent', directory=directory)
+                cur_children.append(new_child)
+                children.append(list(cur_children))
+                if directory:
+                    for j in range(3):
+                        new_grandchild = '%s/%s' % (new_child, str(j))
+                        directory = (j % 2 == 0)
+                        self.s.add(
+                            new_grandchild, new_child, directory=directory)
+                        if not directory:
+                            self.s.set(new_grandchild, self.val)
+                else:
+                    self.s.set(new_child, self.val)
+                revs.append(self.s.commit('%s: %d' % (self.commit_msg, i),
+                                          self.commit_body))
+            for rev,cur_children in zip(revs, children):
+                ret = sorted(self.s.children('parent', revision=rev))
+                self.failUnless(ret == cur_children,
+                                "%s.children() returned %s not %s for revision %s"
+                                % (vars(self.Class)['name'], ret,
+                                   cur_children, rev))
+
     class VersionedStorage_changed_TestCase (VersionedStorageTestCase):
         """Test cases for VersionedStorage.changed() method."""