@@ -18,9 +18,9 @@ def test_contents_should_cache(self, git):
1818
1919 tree = self .repo .tree ('master' )
2020
21- child = tree . contents ['grit' ]
22- child .contents
23- child .contents
21+ child = tree ['grit' ]
22+ child .items ()
23+ child .items ()
2424
2525 assert_true (git .called )
2626 assert_equal (2 , git .call_count )
@@ -96,6 +96,55 @@ def test_slash_with_commits(self, git):
9696 assert_true (git .called )
9797 assert_equal (git .call_args , (('ls_tree' , 'master' ), {}))
9898
99+ @patch (Blob , 'size' )
100+ @patch (Git , '_call_process' )
101+ def test_dict (self , blob , git ):
102+ git .return_value = fixture ('ls_tree_a' )
103+ blob .return_value = 1
104+
105+ tree = self .repo .tree ('master' )
106+
107+ assert_equal ('aa06ba24b4e3f463b3c4a85469d0fb9e5b421cf8' , tree ['lib' ].id )
108+ assert_equal ('8b1e02c0fb554eed2ce2ef737a68bb369d7527df' , tree ['README.txt' ].id )
109+
110+ assert_true (git .called )
111+ assert_equal (git .call_args , (('ls_tree' , 'master' ), {}))
112+
113+ @patch (Blob , 'size' )
114+ @patch (Git , '_call_process' )
115+ def test_dict_with_zero_length_file (self , blob , git ):
116+ git .return_value = fixture ('ls_tree_a' )
117+ blob .return_value = 0
118+
119+ tree = self .repo .tree ('master' )
120+
121+ assert_not_none (tree ['README.txt' ])
122+ assert_equal ('8b1e02c0fb554eed2ce2ef737a68bb369d7527df' , tree ['README.txt' ].id )
123+
124+ assert_true (git .called )
125+ assert_equal (git .call_args , (('ls_tree' , 'master' ), {}))
126+
127+ @patch (Git , '_call_process' )
128+ def test_dict_with_commits (self , git ):
129+ git .return_value = fixture ('ls_tree_commit' )
130+
131+ tree = self .repo .tree ('master' )
132+
133+ assert_none (tree .get ('bar' ))
134+ assert_equal ('2afb47bcedf21663580d5e6d2f406f08f3f65f19' , tree ['foo' ].id )
135+ assert_equal ('f623ee576a09ca491c4a27e48c0dfe04be5f4a2e' , tree ['baz' ].id )
136+
137+ assert_true (git .called )
138+ assert_equal (git .call_args , (('ls_tree' , 'master' ), {}))
139+
140+ @patch (Git , '_call_process' )
141+ @raises (KeyError )
142+ def test_dict_with_non_existant_file (self , git ):
143+ git .return_value = fixture ('ls_tree_commit' )
144+
145+ tree = self .repo .tree ('master' )
146+ tree ['bar' ]
147+
99148 def test_repr (self ):
100149 self .tree = Tree (self .repo , ** {'id' : 'abc' })
101150 assert_equal ('<GitPython.Tree "abc">' , repr (self .tree ))
0 commit comments