<s> import sys <EOL> import tempfile <EOL> import os <EOL> import zipfile <EOL> import datetime <EOL> import time <EOL> import subprocess <EOL> import pkg_resources <EOL> try : <EOL> unicode <EOL> except NameError : <EOL> unicode = str <EOL> def timestamp ( dt ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return dt . timestamp ( ) <EOL> except AttributeError : <EOL> return time . mktime ( dt . timetuple ( ) ) <EOL> class EggRemover ( unicode ) : <EOL> def __call__ ( self ) : <EOL> if self in sys . path : <EOL> sys . path . remove ( self ) <EOL> if os . path . exists ( self ) : <EOL> os . remove ( self ) <EOL> class TestZipProvider ( object ) : <EOL> finalizers = [ ] <EOL> ref_time = datetime . datetime ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> ) <EOL> "<STR_LIT>" <EOL> @ classmethod <EOL> def setup_class ( cls ) : <EOL> "<STR_LIT>" <EOL> egg = tempfile . NamedTemporaryFile ( suffix = '<STR_LIT>' , delete = False ) <EOL> zip_egg = zipfile . ZipFile ( egg , '<STR_LIT:w>' ) <EOL> zip_info = zipfile . ZipInfo ( ) <EOL> zip_info . filename = '<STR_LIT>' <EOL> zip_info . date_time = cls . ref_time . timetuple ( ) <EOL> zip_egg . writestr ( zip_info , '<STR_LIT>' ) <EOL> zip_info = zipfile . ZipInfo ( ) <EOL> zip_info . filename = '<STR_LIT>' <EOL> zip_info . date_time = cls . ref_time . timetuple ( ) <EOL> zip_egg . writestr ( zip_info , '<STR_LIT>' ) <EOL> zip_egg . close ( ) <EOL> egg . close ( ) <EOL> sys . path . append ( egg . name ) <EOL> cls . finalizers . append ( EggRemover ( egg . name ) ) <EOL> @ classmethod <EOL> def teardown_class ( cls ) : <EOL> for finalizer in cls . finalizers : <EOL> finalizer ( ) <EOL> def test_resource_filename_rewrites_on_change ( self ) : <EOL> """<STR_LIT>""" <EOL> import mod <EOL> manager = pkg_resources . ResourceManager ( ) <EOL> zp = pkg_resources . ZipProvider ( mod ) <EOL> filename = zp . get_resource_filename ( manager , '<STR_LIT>' ) <EOL> actual = datetime . datetime . fromtimestamp ( os . stat ( filename ) . st_mtime ) <EOL> assert actual == self . ref_time <EOL> f = open ( filename , '<STR_LIT:w>' ) <EOL> f . write ( '<STR_LIT>' ) <EOL> f . close ( ) <EOL> ts = timestamp ( self . ref_time ) <EOL> os . utime ( filename , ( ts , ts ) ) <EOL> filename = zp . get_resource_filename ( manager , '<STR_LIT>' ) <EOL> f = open ( filename ) <EOL> assert f . read ( ) == '<STR_LIT>' <EOL> manager . cleanup_resources ( ) <EOL> class TestResourceManager ( object ) : <EOL> def test_get_cache_path ( self ) : <EOL> mgr = pkg_resources . ResourceManager ( ) <EOL> path = mgr . get_cache_path ( '<STR_LIT:foo>' ) <EOL> type_ = str ( type ( path ) ) <EOL> message = "<STR_LIT>" + type_ <EOL> assert isinstance ( path , ( unicode , str ) ) , message <EOL> class TestIndependence : <EOL> """<STR_LIT>""" <EOL> def test_setuptools_not_imported ( self ) : <EOL> """<STR_LIT>""" <EOL> lines = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> ) <EOL> cmd = [ sys . executable , '<STR_LIT:-c>' , '<STR_LIT>' . join ( lines ) ] <EOL> subprocess . check_call ( cmd ) </s>
