- Notifications
You must be signed in to change notification settings - Fork68
Expand file tree
/
Copy pathtest_base.py
More file actions
105 lines (89 loc) · 2.77 KB
/
test_base.py
File metadata and controls
105 lines (89 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors
#
# This module is part of GitDB and is released under
# the New BSD License: https://opensource.org/license/bsd-3-clause/
"""Test for object db"""
fromgitdb.test.libimport (
TestBase,
DummyStream,
DeriveTest,
)
fromgitdbimport (
OInfo,
OPackInfo,
ODeltaPackInfo,
OStream,
OPackStream,
ODeltaPackStream,
IStream
)
fromgitdb.utilimport (
NULL_BIN_SHA
)
fromgitdb.typimport (
str_blob_type
)
classTestBaseTypes(TestBase):
deftest_streams(self):
# test info
sha=NULL_BIN_SHA
s=20
blob_id=3
info=OInfo(sha,str_blob_type,s)
assertinfo.binsha==sha
assertinfo.type==str_blob_type
assertinfo.type_id==blob_id
assertinfo.size==s
# test pack info
# provides type_id
pinfo=OPackInfo(0,blob_id,s)
assertpinfo.type==str_blob_type
assertpinfo.type_id==blob_id
assertpinfo.pack_offset==0
dpinfo=ODeltaPackInfo(0,blob_id,s,sha)
assertdpinfo.type==str_blob_type
assertdpinfo.type_id==blob_id
assertdpinfo.delta_info==sha
assertdpinfo.pack_offset==0
# test ostream
stream=DummyStream()
ostream=OStream(*(info+ (stream, )))
assertostream.streamisstream
ostream.read(15)
stream._assert()
assertstream.bytes==15
ostream.read(20)
assertstream.bytes==20
# test packstream
postream=OPackStream(*(pinfo+ (stream, )))
assertpostream.streamisstream
postream.read(10)
stream._assert()
assertstream.bytes==10
# test deltapackstream
dpostream=ODeltaPackStream(*(dpinfo+ (stream, )))
assertdpostream.streamisstream
dpostream.read(5)
stream._assert()
assertstream.bytes==5
# derive with own args
DeriveTest(sha,str_blob_type,s,stream,'mine',myarg=3)._assert()
# test istream
istream=IStream(str_blob_type,s,stream)
assertistream.binsha==None
istream.binsha=sha
assertistream.binsha==sha
assertlen(istream.binsha)==20
assertlen(istream.hexsha)==40
assertistream.size==s
istream.size=s*2
assertistream.size==s*2
assertistream.type==str_blob_type
istream.type="something"
assertistream.type=="something"
assertistream.streamisstream
istream.stream=None
assertistream.streamisNone
assertistream.errorisNone
istream.error=Exception()
assertisinstance(istream.error,Exception)