44import sys
55import shutil
66import tempfile
7- from os .path import relpath # separate import for backport concerns
87from hashlib import md5
98from textwrap import dedent
109
@@ -32,11 +31,11 @@ def get_hexdigest(filename):
3231 return checksum .hexdigest ()
3332
3433
35- def record_pieces (file ):
36- path = relpath ( file , sys . prefix )
37- digest = get_hexdigest (file )
38- size = os .path .getsize (file )
39- return [ path , digest , size ]
34+ def record_pieces (path ):
35+ path = os . path . join ( * path )
36+ digest = get_hexdigest (path )
37+ size = os .path .getsize (path )
38+ return path , digest , size
4039
4140
4241class FakeDistsMixin :
@@ -141,12 +140,10 @@ def setUp(self):
141140
142141 for path , dirs , files in os .walk (dist_location ):
143142 for f in files :
144- record_writer .writerow (record_pieces (
145- os .path .join (path , f )))
143+ record_writer .writerow (record_pieces ((path , f )))
146144 for file in ('INSTALLER' , 'METADATA' , 'REQUESTED' ):
147- record_writer .writerow (record_pieces (
148- os .path .join (distinfo_dir , file )))
149- record_writer .writerow ([relpath (record_file , sys .prefix )])
145+ record_writer .writerow (record_pieces ((distinfo_dir , file )))
146+ record_writer .writerow ([record_file ])
150147
151148 with open (record_file ) as file :
152149 record_reader = csv .reader (file , lineterminator = '\n ' )
@@ -171,15 +168,17 @@ def test_uses(self):
171168 distinfo_name + '.dist-info' )
172169 true_path = [self .fake_dists_path , distinfo_name ,
173170 'grammar' , 'utils.py' ]
174- true_path = relpath ( os .path .join (* true_path ), sys . prefix )
171+ true_path = os .path .join (* true_path )
175172 false_path = [self .fake_dists_path , 'towel_stuff-0.1' , 'towel_stuff' ,
176173 '__init__.py' ]
177- false_path = relpath ( os .path .join (* false_path ), sys . prefix )
174+ false_path = os .path .join (* false_path )
178175
179176 # Test if the distribution uses the file in question
180177 dist = Distribution (distinfo_dir )
181- self .assertTrue (dist .uses (true_path ))
182- self .assertFalse (dist .uses (false_path ))
178+ self .assertTrue (dist .uses (true_path ), 'dist %r is supposed to use %r' %
179+ (dist , true_path ))
180+ self .assertFalse (dist .uses (false_path ), 'dist %r is not supposed to '
181+ 'use %r' % (dist , true_path ))
183182
184183 def test_get_distinfo_file (self ):
185184 # Test the retrieval of dist-info file objects.
@@ -215,20 +214,23 @@ def test_get_distinfo_file(self):
215214 'MAGICFILE' )
216215
217216 def test_list_distinfo_files (self ):
218- # Test for the iteration of RECORD path entries.
219217 distinfo_name = 'towel_stuff-0.1'
220218 distinfo_dir = os .path .join (self .fake_dists_path ,
221219 distinfo_name + '.dist-info' )
222220 dist = Distribution (distinfo_dir )
223221 # Test for the iteration of the raw path
224- distinfo_record_paths = self .records [distinfo_dir ].keys ()
222+ distinfo_files = [os .path .join (distinfo_dir , filename ) for filename in
223+ os .listdir (distinfo_dir )]
225224 found = dist .list_distinfo_files ()
226- self .assertEqual (sorted (found ), sorted (distinfo_record_paths ))
225+ self .assertEqual (sorted (found ), sorted (distinfo_files ))
227226 # Test for the iteration of local absolute paths
228- distinfo_record_paths = [os .path .join (sys .prefix , path )
229- for path in self .records [distinfo_dir ]]
230- found = dist .list_distinfo_files (local = True )
231- self .assertEqual (sorted (found ), sorted (distinfo_record_paths ))
227+ distinfo_files = [os .path .join (sys .prefix , distinfo_dir , path ) for
228+ path in distinfo_files ]
229+ found = sorted (dist .list_distinfo_files (local = True ))
230+ if os .sep != '/' :
231+ self .assertNotIn ('/' , found [0 ])
232+ self .assertIn (os .sep , found [0 ])
233+ self .assertEqual (found , sorted (distinfo_files ))
232234
233235 def test_get_resources_path (self ):
234236 distinfo_name = 'babar-0.1'
0 commit comments