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 import support
11+ from test .support import os_helper , is_emscripten
1212from test .support .os_helper import FakePath
1313from test import test_genericpath
1414from tempfile import TemporaryFile
@@ -58,7 +58,7 @@ def tester(fn, wantResult):
5858 fn = fn .replace ("\\ " , "\\ \\ " )
5959 gotResult = eval (fn )
6060 if wantResult != gotResult and _norm (wantResult ) != _norm (gotResult ):
61- raise TestFailed ("%s should return: %s but returned: %s" \
61+ raise support . TestFailed ("%s should return: %s but returned: %s" \
6262 % (str (fn ), str (wantResult ), str (gotResult )))
6363
6464 # then with bytes
@@ -74,7 +74,7 @@ def tester(fn, wantResult):
7474 warnings .simplefilter ("ignore" , DeprecationWarning )
7575 gotResult = eval (fn )
7676 if _norm (wantResult ) != _norm (gotResult ):
77- raise TestFailed ("%s should return: %s but returned: %s" \
77+ raise support . TestFailed ("%s should return: %s but returned: %s" \
7878 % (str (fn ), str (wantResult ), repr (gotResult )))
7979
8080
@@ -882,6 +882,19 @@ def check(value, expected):
882882 check ('%spam%bar' , '%sbar' % nonascii )
883883 check ('%{}%bar' .format (nonascii ), 'ham%sbar' % nonascii )
884884
885+ @support .requires_resource ('cpu' )
886+ def test_expandvars_large (self ):
887+ expandvars = ntpath .expandvars
888+ with os_helper .EnvironmentVarGuard () as env :
889+ env .clear ()
890+ env ["A" ] = "B"
891+ n = 100_000
892+ self .assertEqual (expandvars ('%A%' * n ), 'B' * n )
893+ self .assertEqual (expandvars ('%A%A' * n ), 'BA' * n )
894+ self .assertEqual (expandvars ("''" * n + '%%' ), "''" * n + '%' )
895+ self .assertEqual (expandvars ("%%" * n ), "%" * n )
896+ self .assertEqual (expandvars ("$$" * n ), "$" * n )
897+
885898 def test_expanduser (self ):
886899 tester ('ntpath.expanduser("test")' , 'test' )
887900
@@ -1207,7 +1220,7 @@ def test_con_device(self):
12071220 self .assertTrue (os .path .exists (r"\\.\CON" ))
12081221
12091222 @unittest .skipIf (sys .platform != 'win32' , "Fast paths are only for win32" )
1210- @cpython_only
1223+ @support . cpython_only
12111224 def test_fast_paths_in_use (self ):
12121225 # There are fast paths of these functions implemented in posixmodule.c.
12131226 # Confirm that they are being used, and not the Python fallbacks in
0 commit comments