Mercurial > kallithea
changeset 3692:5f9f4ece4b52 beta
added __eq__ operation on vcs Repository objects
- eq compare if objects are same class and have the same path
- fixes some issues introduced after @LazyProperty was removed from scm_instance
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 05 Apr 2013 19:42:07 +0200 |
parents | 9b18950fa229 |
children | 6843cabe9925 |
files | rhodecode/lib/vcs/backends/base.py rhodecode/tests/vcs/test_repository.py |
diffstat | 2 files changed, 17 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/lib/vcs/backends/base.py Fri Apr 05 19:21:52 2013 +0200 +++ b/rhodecode/lib/vcs/backends/base.py Fri Apr 05 19:42:07 2013 +0200 @@ -80,6 +80,10 @@ def __len__(self): return self.count() + def __eq__(self, other): + same_instance = isinstance(other, self.__class__) + return same_instance and getattr(other, 'path', None) == self.path + @LazyProperty def alias(self): for k, v in settings.BACKENDS.items():
--- a/rhodecode/tests/vcs/test_repository.py Fri Apr 05 19:21:52 2013 +0200 +++ b/rhodecode/tests/vcs/test_repository.py Fri Apr 05 19:42:07 2013 +0200 @@ -31,6 +31,19 @@ self.assertEqual(self.repo.get_user_email(TEST_USER_CONFIG_FILE), 'foo.bar@example.com') + def test_repo_equality(self): + self.assertTrue(self.repo == self.repo) + + def test_repo_equality_broken_object(self): + import copy + _repo = copy.copy(self.repo) + delattr(_repo, 'path') + self.assertTrue(self.repo != _repo) + + def test_repo_equality_other_object(self): + class dummy(object): + path = self.repo.path + self.assertTrue(self.repo != dummy()) class RepositoryGetDiffTest(BackendTestMixin):