77import unittest
88import warnings
99from ntpath import ALLOW_MISSING
10- from test .support import cpython_only , os_helper
11- from test .support import TestFailed , is_emscripten
10+ from test .support import os_helper , is_emscripten
1211from test .support .os_helper import FakePath
1312from test import test_genericpath
1413from tempfile import TemporaryFile
@@ -58,7 +57,7 @@ def tester(fn, wantResult):
5857 fn = fn .replace ("\\ " , "\\ \\ " )
5958 gotResult = eval (fn )
6059 if wantResult != gotResult and _norm (wantResult ) != _norm (gotResult ):
61- raise TestFailed ("%s should return: %s but returned: %s" \
60+ raise support . TestFailed ("%s should return: %s but returned: %s" \
6261 % (str (fn ), str (wantResult ), str (gotResult )))
6362
6463 # then with bytes
@@ -74,7 +73,7 @@ def tester(fn, wantResult):
7473 warnings .simplefilter ("ignore" , DeprecationWarning )
7574 gotResult = eval (fn )
7675 if _norm (wantResult ) != _norm (gotResult ):
77- raise TestFailed ("%s should return: %s but returned: %s" \
76+ raise support . TestFailed ("%s should return: %s but returned: %s" \
7877 % (str (fn ), str (wantResult ), repr (gotResult )))
7978
8079
@@ -882,6 +881,19 @@ def check(value, expected):
882881 check ('%spam%bar' , '%sbar' % nonascii )
883882 check ('%{}%bar' .format (nonascii ), 'ham%sbar' % nonascii )
884883
884+ @support .requires_resource ('cpu' )
885+ def test_expandvars_large (self ):
886+ expandvars = ntpath .expandvars
887+ with os_helper .EnvironmentVarGuard () as env :
888+ env .clear ()
889+ env ["A" ] = "B"
890+ n = 100_000
891+ self .assertEqual (expandvars ('%A%' * n ), 'B' * n )
892+ self .assertEqual (expandvars ('%A%A' * n ), 'BA' * n )
893+ self .assertEqual (expandvars ("''" * n + '%%' ), "''" * n + '%' )
894+ self .assertEqual (expandvars ("%%" * n ), "%" * n )
895+ self .assertEqual (expandvars ("$$" * n ), "$" * n )
896+
885897 def test_expanduser (self ):
886898 tester ('ntpath.expanduser("test")' , 'test' )
887899
@@ -1207,7 +1219,7 @@ def test_con_device(self):
12071219 self .assertTrue (os .path .exists (r"\\.\CON" ))
12081220
12091221 @unittest .skipIf (sys .platform != 'win32' , "Fast paths are only for win32" )
1210- @cpython_only
1222+ @support . cpython_only
12111223 def test_fast_paths_in_use (self ):
12121224 # There are fast paths of these functions implemented in posixmodule.c.
12131225 # Confirm that they are being used, and not the Python fallbacks in
0 commit comments