@@ -46,57 +46,6 @@ def setUp(self):
46
46
def tearDown (self ):
47
47
shutil .rmtree (self .directory )
48
48
49
- def create_long_path (self ):
50
- long_path = os .path .join (self .directory , "long" )
51
-
52
- # Create a long path, 10 directories at a time.
53
- # It will be 100 directories deep, or shorter if the OS limits it.
54
- for i in range (10 ):
55
- longer_path = os .path .join (
56
- long_path , * (f"dir_{ i } _{ j } " for j in range (10 ))
57
- )
58
-
59
- # Check if we can open __pycache__/*.pyc.
60
- # Also, put in the source file that we want to compile
61
- longer_source = os .path .join (longer_path , '_test_long.py' )
62
- longer_cache = importlib .util .cache_from_source (longer_source )
63
- try :
64
- os .makedirs (longer_path )
65
- shutil .copyfile (self .source_path , longer_source )
66
- os .makedirs (os .path .dirname (longer_cache ))
67
- # Make sure we can write to the cache
68
- with open (longer_cache , 'w' ):
69
- pass
70
- except FileNotFoundError :
71
- # On Windows, a FileNotFoundError("The filename or extension
72
- # is too long") is raised for long paths
73
- if sys .platform == "win32" :
74
- break
75
- else :
76
- raise
77
- except OSError as exc :
78
- if exc .errno == errno .ENAMETOOLONG :
79
- break
80
- else :
81
- raise
82
-
83
- # Remove the __pycache__
84
- shutil .rmtree (os .path .dirname (longer_cache ))
85
-
86
- long_path = longer_path
87
- long_source = longer_source
88
- long_cache = longer_cache
89
-
90
- # On Windows, MAX_PATH is 260 characters, our path with the 20
91
- # directories is 160 characters long, leaving something for the
92
- # root (self.directory) as well.
93
- # Tests assume long_path contains at least 10 directories.
94
- if i < 2 :
95
- raise ValueError (f'"Long path" is too short: { long_path } ' )
96
-
97
- self .source_path_long = long_source
98
- self .bc_path_long = long_cache
99
-
100
49
def add_bad_source_file (self ):
101
50
self .bad_source_path = os .path .join (self .directory , '_test_bad.py' )
102
51
with open (self .bad_source_path , 'w' ) as file :
@@ -247,14 +196,21 @@ def test_compile_missing_multiprocessing(self, compile_file_mock):
247
196
self .assertTrue (compile_file_mock .called )
248
197
249
198
def test_compile_dir_maxlevels (self ):
250
- # Test the actual impact of maxlevels attr
251
- self .create_long_path ()
252
- compileall .compile_dir (os .path .join (self .directory , "long" ),
253
- maxlevels = 10 , quiet = True )
254
- self .assertFalse (os .path .isfile (self .bc_path_long ))
255
- compileall .compile_dir (os .path .join (self .directory , "long" ),
256
- quiet = True )
257
- self .assertTrue (os .path .isfile (self .bc_path_long ))
199
+ # Test the actual impact of maxlevels parameter
200
+ depth = 3
201
+ path = self .directory
202
+ for i in range (1 , depth + 1 ):
203
+ path = os .path .join (path , f"dir_{ i } " )
204
+ source = os .path .join (path , 'script.py' )
205
+ os .mkdir (path )
206
+ shutil .copyfile (self .source_path , source )
207
+ pyc_filename = importlib .util .cache_from_source (source )
208
+
209
+ compileall .compile_dir (self .directory , quiet = True , maxlevels = depth - 1 )
210
+ self .assertFalse (os .path .isfile (pyc_filename ))
211
+
212
+ compileall .compile_dir (self .directory , quiet = True , maxlevels = depth )
213
+ self .assertTrue (os .path .isfile (pyc_filename ))
258
214
259
215
def test_strip_only (self ):
260
216
fullpath = ["test" , "build" , "real" , "path" ]
0 commit comments