test_index.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # test_index.py -- Tests for the git index cache
  2. # Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
  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. # or (at your option) any later version 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. from dulwich.index import Index, write_index
  19. import os
  20. from unittest import TestCase
  21. class IndexTestCase(TestCase):
  22. datadir = os.path.join(os.path.dirname(__file__), 'data/indexes')
  23. def get_simple_index(self, name):
  24. return Index(os.path.join(self.datadir, name))
  25. class SimpleIndexTestcase(IndexTestCase):
  26. def test_len(self):
  27. self.assertEquals(1, len(self.get_simple_index("index")))
  28. def test_iter(self):
  29. self.assertEquals([
  30. ('bla', (1230680220, 0), (1230680220, 0), 2050, 3761020, 33188, 1000, 1000, 0, '\xe6\x9d\xe2\x9b\xb2\xd1\xd6CK\x8b)\xaewZ\xd8\xc2\xe4\x8cS\x91', 3)
  31. ],
  32. list(self.get_simple_index("index")))
  33. def test_getitem(self):
  34. self.assertEquals( ('bla', (1230680220, 0), (1230680220, 0), 2050, 3761020, 33188, 1000, 1000, 0, '\xe6\x9d\xe2\x9b\xb2\xd1\xd6CK\x8b)\xaewZ\xd8\xc2\xe4\x8cS\x91', 3)
  35. ,
  36. self.get_simple_index("index")["bla"])
  37. class SimpleIndexWriterTestCase(IndexTestCase):
  38. def test_simple_write(self):
  39. x = open('test-simple-write-index', 'w+')
  40. try:
  41. write_index(x, [('barbla', (1230680220, 0), (1230680220, 0), 2050, 3761020, 33188, 1000, 1000, 0, '\xe6\x9d\xe2\x9b\xb2\xd1\xd6CK\x8b)\xaewZ\xd8\xc2\xe4\x8cS\x91', 3)])
  42. finally:
  43. x.close()