-# 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 file is part of Bugs Everywhere.
#
-# 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.
+# 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.
#
# 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.
+# 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/>.
+# 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.
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."""
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.
"""
self.s.commit('Added initialization files')
except EmptyCommit:
pass
-
+
def test_revision_id_exception(self):
"""Invalid revision id should raise InvalidRevision.
"""
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."""