44import os
55from contextlib import contextmanager
66
7- from twitter .common .contextutil import temporary_dir , temporary_file
7+ from twitter .common .contextutil import temporary_dir
88
99from pex .compatibility import nested
1010from pex .environment import PEXEnvironment
1111from pex .pex_builder import PEXBuilder
1212from pex .pex_info import PexInfo
13- from pex .testing import make_bdist
13+ from pex .testing import make_bdist , temporary_filename
1414
1515
1616@contextmanager
@@ -22,64 +22,65 @@ def yield_pex_builder(zip_safe=True):
2222
2323
2424def test_force_local ():
25- with nested (yield_pex_builder (), temporary_dir (), temporary_file ()) as (pb , pex_root , pex_file ):
25+ with nested (yield_pex_builder (), temporary_dir (), temporary_filename ()) as (
26+ pb , pex_root , pex_file ):
2627 pb .info .pex_root = pex_root
27- pb .build (pex_file . name )
28+ pb .build (pex_file )
2829
29- code_cache = PEXEnvironment .force_local (pex_file . name , pb .info )
30+ code_cache = PEXEnvironment .force_local (pex_file , pb .info )
3031 assert os .path .exists (pb .info .zip_unsafe_cache )
3132 assert len (os .listdir (pb .info .zip_unsafe_cache )) == 1
3233 assert [os .path .basename (code_cache )] == os .listdir (pb .info .zip_unsafe_cache )
3334 assert set (os .listdir (code_cache )) == set ([PexInfo .PATH , '__main__.py' , '__main__.pyc' ])
3435
3536 # idempotence
36- assert PEXEnvironment .force_local (pex_file . name , pb .info ) == code_cache
37+ assert PEXEnvironment .force_local (pex_file , pb .info ) == code_cache
3738
3839
3940def normalize (path ):
40- return os .path .normpath (os .path .realpath (path ))
41+ return os .path .normpath (os .path .realpath (path )). lower ()
4142
4243
4344def test_write_zipped_internal_cache ():
4445 # zip_safe pex will not be written to install cache unless always_write_cache
45- with nested (yield_pex_builder (zip_safe = True ), temporary_dir (), temporary_file ()) as (
46+ with nested (yield_pex_builder (zip_safe = True ), temporary_dir (), temporary_filename ()) as (
4647 pb , pex_root , pex_file ):
4748
4849 pb .info .pex_root = pex_root
49- pb .build (pex_file . name )
50+ pb .build (pex_file )
5051
51- existing , new , zip_safe = PEXEnvironment .write_zipped_internal_cache (pex_file . name , pb .info )
52+ existing , new , zip_safe = PEXEnvironment .write_zipped_internal_cache (pex_file , pb .info )
5253 assert len (zip_safe ) == 1
5354 assert normalize (zip_safe [0 ].location ).startswith (
54- normalize (os .path .join (pex_file . name , pb .info .internal_cache ))), (
55+ normalize (os .path .join (pex_file , pb .info .internal_cache ))), (
5556 'loc: %s, cache: %s' % (
5657 normalize (zip_safe [0 ].location ),
57- normalize (os .path .join (pex_file . name , pb .info .internal_cache ))))
58+ normalize (os .path .join (pex_file , pb .info .internal_cache ))))
5859
5960 pb .info .always_write_cache = True
60- existing , new , zip_safe = PEXEnvironment .write_zipped_internal_cache (pex_file . name , pb .info )
61+ existing , new , zip_safe = PEXEnvironment .write_zipped_internal_cache (pex_file , pb .info )
6162 assert len (new ) == 1
6263 assert normalize (new [0 ].location ).startswith (normalize (pb .info .install_cache ))
6364
6465 # Check that we can read from the cache
65- existing , new , zip_safe = PEXEnvironment .write_zipped_internal_cache (pex_file . name , pb .info )
66+ existing , new , zip_safe = PEXEnvironment .write_zipped_internal_cache (pex_file , pb .info )
6667 assert len (existing ) == 1
6768 assert normalize (existing [0 ].location ).startswith (normalize (pb .info .install_cache ))
6869
6970 # non-zip_safe pex will be written to install cache
70- with nested (yield_pex_builder (zip_safe = False ), temporary_dir (), temporary_file ()) as (
71+ with nested (yield_pex_builder (zip_safe = False ), temporary_dir (), temporary_filename ()) as (
7172 pb , pex_root , pex_file ):
7273
7374 pb .info .pex_root = pex_root
74- pb .build (pex_file . name )
75+ pb .build (pex_file )
7576
76- existing , new , zip_safe = PEXEnvironment .write_zipped_internal_cache (pex_file . name , pb .info )
77+ existing , new , zip_safe = PEXEnvironment .write_zipped_internal_cache (pex_file , pb .info )
7778 assert len (new ) == 1
7879 assert normalize (new [0 ].location ).startswith (normalize (pb .info .install_cache ))
7980 original_location = normalize (new [0 ].location )
8081
8182 # do the second time to validate idempotence of caching
82- existing , new , zip_safe = PEXEnvironment .write_zipped_internal_cache (pex_file . name , pb .info )
83+ existing , new , zip_safe = PEXEnvironment .write_zipped_internal_cache (pex_file , pb .info )
8384 assert len (existing ) == 1
8485 assert normalize (existing [0 ].location ) == original_location
8586
0 commit comments