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

106 行
2.8KB

  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. """Test for object db"""
  6. from gitdb.test.lib import (
  7. TestBase,
  8. DummyStream,
  9. DeriveTest,
  10. )
  11. from gitdb import (
  12. OInfo,
  13. OPackInfo,
  14. ODeltaPackInfo,
  15. OStream,
  16. OPackStream,
  17. ODeltaPackStream,
  18. IStream
  19. )
  20. from gitdb.util import (
  21. NULL_BIN_SHA
  22. )
  23. from gitdb.typ import (
  24. str_blob_type
  25. )
  26. class TestBaseTypes(TestBase):
  27. def test_streams(self):
  28. # test info
  29. sha = NULL_BIN_SHA
  30. s = 20
  31. blob_id = 3
  32. info = OInfo(sha, str_blob_type, s)
  33. assert info.binsha == sha
  34. assert info.type == str_blob_type
  35. assert info.type_id == blob_id
  36. assert info.size == s
  37. # test pack info
  38. # provides type_id
  39. pinfo = OPackInfo(0, blob_id, s)
  40. assert pinfo.type == str_blob_type
  41. assert pinfo.type_id == blob_id
  42. assert pinfo.pack_offset == 0
  43. dpinfo = ODeltaPackInfo(0, blob_id, s, sha)
  44. assert dpinfo.type == str_blob_type
  45. assert dpinfo.type_id == blob_id
  46. assert dpinfo.delta_info == sha
  47. assert dpinfo.pack_offset == 0
  48. # test ostream
  49. stream = DummyStream()
  50. ostream = OStream(*(info + (stream, )))
  51. assert ostream.stream is stream
  52. ostream.read(15)
  53. stream._assert()
  54. assert stream.bytes == 15
  55. ostream.read(20)
  56. assert stream.bytes == 20
  57. # test packstream
  58. postream = OPackStream(*(pinfo + (stream, )))
  59. assert postream.stream is stream
  60. postream.read(10)
  61. stream._assert()
  62. assert stream.bytes == 10
  63. # test deltapackstream
  64. dpostream = ODeltaPackStream(*(dpinfo + (stream, )))
  65. dpostream.stream is stream
  66. dpostream.read(5)
  67. stream._assert()
  68. assert stream.bytes == 5
  69. # derive with own args
  70. DeriveTest(sha, str_blob_type, s, stream, 'mine', myarg=3)._assert()
  71. # test istream
  72. istream = IStream(str_blob_type, s, stream)
  73. assert istream.binsha == None
  74. istream.binsha = sha
  75. assert istream.binsha == sha
  76. assert len(istream.binsha) == 20
  77. assert len(istream.hexsha) == 40
  78. assert istream.size == s
  79. istream.size = s * 2
  80. istream.size == s * 2
  81. assert istream.type == str_blob_type
  82. istream.type = "something"
  83. assert istream.type == "something"
  84. assert istream.stream is stream
  85. istream.stream = None
  86. assert istream.stream is None
  87. assert istream.error is None
  88. istream.error = Exception()
  89. assert isinstance(istream.error, Exception)