您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

44 行
1.3KB

  1. # Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors
  2. #
  3. # This module is part of GitDB and is released under
  4. # the New BSD License: http://www.opensource.org/licenses/bsd-license.php
  5. """Module with examples from the tutorial section of the docs"""
  6. import os
  7. from gitdb.test.lib import TestBase
  8. from gitdb import IStream
  9. from gitdb.db import LooseObjectDB
  10. from io import BytesIO
  11. class TestExamples(TestBase):
  12. def test_base(self):
  13. ldb = LooseObjectDB(os.path.join(self.gitrepopath, 'objects'))
  14. for sha1 in ldb.sha_iter():
  15. oinfo = ldb.info(sha1)
  16. ostream = ldb.stream(sha1)
  17. assert oinfo[:3] == ostream[:3]
  18. assert len(ostream.read()) == ostream.size
  19. assert ldb.has_object(oinfo.binsha)
  20. # END for each sha in database
  21. # assure we close all files
  22. try:
  23. del(ostream)
  24. del(oinfo)
  25. except UnboundLocalError:
  26. pass
  27. # END ignore exception if there are no loose objects
  28. data = "my data".encode("ascii")
  29. istream = IStream("blob", len(data), BytesIO(data))
  30. # the object does not yet have a sha
  31. assert istream.binsha is None
  32. ldb.store(istream)
  33. # now the sha is set
  34. assert len(istream.binsha) == 20
  35. assert ldb.has_object(istream.binsha)