test_repository.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # test_repository.py -- tests for repository.py
  2. # Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; version 2
  7. # of the License.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  17. # MA 02110-1301, USA.
  18. import os
  19. import unittest
  20. from git.repository import Repository
  21. class RepositoryTests(unittest.TestCase):
  22. def open_repo(self, name):
  23. return Repository(os.path.join(os.path.dirname(__file__),
  24. 'data/repos', name, '.git'))
  25. def test_simple_props(self):
  26. r = self.open_repo('a')
  27. basedir = os.path.join(os.path.dirname(__file__), 'data/repos/a/.git')
  28. self.assertEqual(r.basedir(), basedir)
  29. self.assertEqual(r.object_dir(), os.path.join(basedir, 'objects'))
  30. def test_ref(self):
  31. r = self.open_repo('a')
  32. self.assertEqual(r.ref('master'),
  33. 'a90fa2d900a17e99b433217e988c4eb4a2e9a097')
  34. def test_head(self):
  35. r = self.open_repo('a')
  36. self.assertEqual(r.head(), 'a90fa2d900a17e99b433217e988c4eb4a2e9a097')
  37. def test_get_object(self):
  38. r = self.open_repo('a')
  39. obj = r.get_object(r.head())
  40. self.assertEqual(obj._type, 'commit')
  41. def test_get_object_non_existant(self):
  42. r = self.open_repo('a')
  43. obj = r.get_object('b91fa4d900g17e99b433218e988c4eb4a3e9a097')
  44. self.assertEqual(obj, None)