66import unittest
77import warnings
88from ntpath import ALLOW_MISSING
9- from test . support import os_helper
10- from test .support import TestFailed , is_emscripten
9+ from test import support
10+ from test .support import os_helper , is_emscripten
1111from test .support .os_helper import FakePath
1212from test import test_genericpath
1313from tempfile import TemporaryFile
@@ -57,7 +57,7 @@ def tester(fn, wantResult):
5757 fn = fn .replace ("\\ " , "\\ \\ " )
5858 gotResult = eval (fn )
5959 if wantResult != gotResult and _norm (wantResult ) != _norm (gotResult ):
60- raise TestFailed ("%s should return: %s but returned: %s" \
60+ raise support . TestFailed ("%s should return: %s but returned: %s" \
6161 % (str (fn ), str (wantResult ), str (gotResult )))
6262
6363 # then with bytes
@@ -73,7 +73,7 @@ def tester(fn, wantResult):
7373 warnings .simplefilter ("ignore" , DeprecationWarning )
7474 gotResult = eval (fn )
7575 if _norm (wantResult ) != _norm (gotResult ):
76- raise TestFailed ("%s should return: %s but returned: %s" \
76+ raise support . TestFailed ("%s should return: %s but returned: %s" \
7777 % (str (fn ), str (wantResult ), repr (gotResult )))
7878
7979
@@ -820,6 +820,19 @@ def check(value, expected):
820820 check ('%spam%bar' , '%sbar' % nonascii )
821821 check ('%{}%bar' .format (nonascii ), 'ham%sbar' % nonascii )
822822
823+ @support .requires_resource ('cpu' )
824+ def test_expandvars_large (self ):
825+ expandvars = ntpath .expandvars
826+ with os_helper .EnvironmentVarGuard () as env :
827+ env .clear ()
828+ env ["A" ] = "B"
829+ n = 100_000
830+ self .assertEqual (expandvars ('%A%' * n ), 'B' * n )
831+ self .assertEqual (expandvars ('%A%A' * n ), 'BA' * n )
832+ self .assertEqual (expandvars ("''" * n + '%%' ), "''" * n + '%' )
833+ self .assertEqual (expandvars ("%%" * n ), "%" * n )
834+ self .assertEqual (expandvars ("$$" * n ), "$" * n )
835+
823836 def test_expanduser (self ):
824837 tester ('ntpath.expanduser("test")' , 'test' )
825838
@@ -1090,6 +1103,7 @@ def test_nt_helpers(self):
10901103 self .assertIsInstance (b_final_path , bytes )
10911104 self .assertGreater (len (b_final_path ), 0 )
10921105
1106+
10931107class NtCommonTest (test_genericpath .CommonTest , unittest .TestCase ):
10941108 pathmodule = ntpath
10951109 attributes = ['relpath' ]
0 commit comments