Changeset - 5f9f4ece4b52
[Not reviewed]
beta
0 2 0
Marcin Kuzminski - 13 years ago 2013-04-05 19:42:07
marcin@python-works.com
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
2 files changed with 17 insertions and 0 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/vcs/backends/base.py
Show inline comments
 
@@ -77,12 +77,16 @@ class BaseRepository(object):
 
    def __repr__(self):
 
        return self.__str__()
 

	
 
    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():
 
            if v.split('.')[-1] == str(self.__class__.__name__):
 
                return k
 

	
rhodecode/tests/vcs/test_repository.py
Show inline comments
 
@@ -28,12 +28,25 @@ class RepositoryBaseTest(BackendTestMixi
 
            'Foo Bar')
 

	
 
    def test_get_user_email(self):
 
        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):
 

	
 
    @classmethod
 
    def _get_commits(cls):
0 comments (0 inline, 0 general)