2828import pytest
2929
3030import pygit2
31+ from pygit2 import Object , Repository , Tree
3132from pygit2 .enums import FileMode , ObjectType
3233
3334from . import utils
3637SUBTREE_SHA = '614fd9a3094bf618ea938fffc00e7d1a54f89ad0'
3738
3839
39- def assertTreeEntryEqual (entry , sha , name , filemode ) :
40+ def assertTreeEntryEqual (entry : Object , sha : str , name : str , filemode : int ) -> None :
4041 assert entry .id == sha
4142 assert entry .name == name
4243 assert entry .filemode == filemode
4344 assert entry .raw_name == name .encode ('utf-8' )
4445
4546
46- def test_read_tree (barerepo ) :
47+ def test_read_tree (barerepo : Repository ) -> None :
4748 tree = barerepo [TREE_SHA ]
49+ assert isinstance (tree , Tree )
4850 with pytest .raises (TypeError ):
49- tree [()]
51+ tree [()] # type: ignore
5052 with pytest .raises (TypeError ):
51- tree / 123
53+ tree / 123 # type: ignore
5254 utils .assertRaisesWithArg (KeyError , 'abcd' , lambda : tree ['abcd' ])
5355 utils .assertRaisesWithArg (IndexError , - 4 , lambda : tree [- 4 ])
5456 utils .assertRaisesWithArg (IndexError , 3 , lambda : tree [3 ])
@@ -72,45 +74,50 @@ def test_read_tree(barerepo):
7274 sha = '297efb891a47de80be0cfe9c639e4b8c9b450989'
7375 assertTreeEntryEqual (tree ['c/d' ], sha , 'd' , 0o0100644 )
7476 assertTreeEntryEqual (tree / 'c/d' , sha , 'd' , 0o0100644 )
75- assertTreeEntryEqual (tree / 'c' / 'd' , sha , 'd' , 0o0100644 )
76- assertTreeEntryEqual (tree ['c' ]['d' ], sha , 'd' , 0o0100644 )
77- assertTreeEntryEqual ((tree / 'c' )['d' ], sha , 'd' , 0o0100644 )
77+ assertTreeEntryEqual (tree / 'c' / 'd' , sha , 'd' , 0o0100644 ) # type: ignore[operator]
78+ assertTreeEntryEqual (tree ['c' ]['d' ], sha , 'd' , 0o0100644 ) # type: ignore[index]
79+ assertTreeEntryEqual ((tree / 'c' )['d' ], sha , 'd' , 0o0100644 ) # type: ignore[index]
7880 utils .assertRaisesWithArg (KeyError , 'ab/cd' , lambda : tree ['ab/cd' ])
7981 utils .assertRaisesWithArg (KeyError , 'ab/cd' , lambda : tree / 'ab/cd' )
80- utils .assertRaisesWithArg (KeyError , 'ab' , lambda : tree / 'c' / 'ab' )
82+ utils .assertRaisesWithArg (KeyError , 'ab' , lambda : tree / 'c' / 'ab' ) # type: ignore[operator]
8183 with pytest .raises (TypeError ):
82- tree / 'a' / 'cd'
84+ tree / 'a' / 'cd' # type: ignore
8385
8486
85- def test_equality (barerepo ) :
87+ def test_equality (barerepo : Repository ) -> None :
8688 tree_a = barerepo ['18e2d2e9db075f9eb43bcb2daa65a2867d29a15e' ]
8789 tree_b = barerepo ['2ad1d3456c5c4a1c9e40aeeddb9cd20b409623c8' ]
90+ assert isinstance (tree_a , Tree )
91+ assert isinstance (tree_b , Tree )
8892
8993 assert tree_a ['a' ] != tree_b ['a' ]
9094 assert tree_a ['a' ] != tree_b ['b' ]
9195 assert tree_a ['b' ] == tree_b ['b' ]
9296
9397
94- def test_sorting (barerepo ) :
98+ def test_sorting (barerepo : Repository ) -> None :
9599 tree_a = barerepo ['18e2d2e9db075f9eb43bcb2daa65a2867d29a15e' ]
100+ assert isinstance (tree_a , Tree )
96101 assert list (tree_a ) == sorted (reversed (list (tree_a )), key = pygit2 .tree_entry_key )
97- assert list (tree_a ) != reversed (list (tree_a ))
102+ assert list (tree_a ) != reversed (list (tree_a )) # type: ignore[comparison-overlap]
98103
99104
100- def test_read_subtree (barerepo ) :
105+ def test_read_subtree (barerepo : Repository ) -> None :
101106 tree = barerepo [TREE_SHA ]
107+ assert isinstance (tree , Tree )
102108
103109 subtree_entry = tree ['c' ]
104110 assertTreeEntryEqual (subtree_entry , SUBTREE_SHA , 'c' , 0o0040000 )
105- assert subtree_entry .type == ObjectType .TREE
111+ assert subtree_entry .type == int ( ObjectType .TREE )
106112 assert subtree_entry .type_str == 'tree'
107113
108114 subtree_entry = tree / 'c'
109115 assertTreeEntryEqual (subtree_entry , SUBTREE_SHA , 'c' , 0o0040000 )
110- assert subtree_entry .type == ObjectType .TREE
116+ assert subtree_entry .type == int ( ObjectType .TREE )
111117 assert subtree_entry .type_str == 'tree'
112118
113119 subtree = barerepo [subtree_entry .id ]
120+ assert isinstance (subtree , Tree )
114121 assert 1 == len (subtree )
115122 sha = '297efb891a47de80be0cfe9c639e4b8c9b450989'
116123 assertTreeEntryEqual (subtree [0 ], sha , 'd' , 0o0100644 )
@@ -119,7 +126,7 @@ def test_read_subtree(barerepo):
119126 assert subtree_entry == barerepo [subtree_entry .id ]
120127
121128
122- def test_new_tree (barerepo ) :
129+ def test_new_tree (barerepo : Repository ) -> None :
123130 repo = barerepo
124131 b0 = repo .create_blob ('1' )
125132 b1 = repo .create_blob ('2' )
@@ -138,8 +145,8 @@ def test_new_tree(barerepo):
138145 ('y' , b1 , pygit2 .Blob , FileMode .BLOB_EXECUTABLE , ObjectType .BLOB , 'blob' ),
139146 ('z' , subtree .id , pygit2 .Tree , FileMode .TREE , ObjectType .TREE , 'tree' ),
140147 ]:
141- assert name in tree
142- obj = tree [name ]
148+ assert name in tree # type: ignore[operator]
149+ obj = tree [name ] # type: ignore[index]
143150 assert isinstance (obj , cls )
144151 assert obj .name == name
145152 assert obj .filemode == filemode
@@ -148,7 +155,7 @@ def test_new_tree(barerepo):
148155 assert repo [obj .id ].id == oid
149156 assert obj == repo [obj .id ]
150157
151- obj = tree / name
158+ obj = tree / name # type: ignore[operator]
152159 assert isinstance (obj , cls )
153160 assert obj .name == name
154161 assert obj .filemode == filemode
@@ -158,44 +165,49 @@ def test_new_tree(barerepo):
158165 assert obj == repo [obj .id ]
159166
160167
161- def test_modify_tree (barerepo ) :
168+ def test_modify_tree (barerepo : Repository ) -> None :
162169 tree = barerepo [TREE_SHA ]
163170 with pytest .raises (TypeError ):
164- operator .setitem ('c' , tree ['a' ])
171+ operator .setitem ('c' , tree ['a' ]) # type: ignore
165172 with pytest .raises (TypeError ):
166- operator .delitem ('c' )
173+ operator .delitem ('c' ) # type: ignore
167174
168175
169- def test_iterate_tree (barerepo ) :
176+ def test_iterate_tree (barerepo : Repository ) -> None :
170177 """
171178 Testing that we're able to iterate of a Tree object and that the
172179 resulting sha strings are consistent with the sha strings we could
173180 get with other Tree access methods.
174181 """
175182 tree = barerepo [TREE_SHA ]
183+ assert isinstance (tree , Tree )
176184 for tree_entry in tree :
185+ assert tree_entry .name is not None
177186 assert tree_entry == tree [tree_entry .name ]
178187
179188
180- def test_iterate_tree_nested (barerepo ) :
189+ def test_iterate_tree_nested (barerepo : Repository ) -> None :
181190 """
182191 Testing that we're able to iterate of a Tree object and then iterate
183192 trees we receive as a result.
184193 """
185194 tree = barerepo [TREE_SHA ]
195+ assert isinstance (tree , Tree )
186196 for tree_entry in tree :
187197 if isinstance (tree_entry , pygit2 .Tree ):
188198 for tree_entry2 in tree_entry :
189199 pass
190200
191201
192- def test_deep_contains (barerepo ) :
202+ def test_deep_contains (barerepo : Repository ) -> None :
193203 tree = barerepo [TREE_SHA ]
204+ assert isinstance (tree , Tree )
194205 assert 'a' in tree
195206 assert 'c' in tree
196207 assert 'c/d' in tree
197208 assert 'c/e' not in tree
198209 assert 'd' not in tree
199210
211+ assert isinstance (tree ['c' ], Tree )
200212 assert 'd' in tree ['c' ]
201213 assert 'e' not in tree ['c' ]
0 commit comments