55import unittest
66import warnings
77from ntpath import ALLOW_MISSING
8+ from test import support
89from test .support import os_helper
9- from test .support import TestFailed
1010from test .support .os_helper import FakePath
1111from test import test_genericpath
1212from tempfile import TemporaryFile
@@ -56,7 +56,7 @@ def tester(fn, wantResult):
5656 fn = fn .replace ("\\ " , "\\ \\ " )
5757 gotResult = eval (fn )
5858 if wantResult != gotResult and _norm (wantResult ) != _norm (gotResult ):
59- raise TestFailed ("%s should return: %s but returned: %s" \
59+ raise support . TestFailed ("%s should return: %s but returned: %s" \
6060 % (str (fn ), str (wantResult ), str (gotResult )))
6161
6262 # then with bytes
@@ -72,7 +72,7 @@ def tester(fn, wantResult):
7272 warnings .simplefilter ("ignore" , DeprecationWarning )
7373 gotResult = eval (fn )
7474 if _norm (wantResult ) != _norm (gotResult ):
75- raise TestFailed ("%s should return: %s but returned: %s" \
75+ raise support . TestFailed ("%s should return: %s but returned: %s" \
7676 % (str (fn ), str (wantResult ), repr (gotResult )))
7777
7878
@@ -689,6 +689,19 @@ def check(value, expected):
689689 check ('%spam%bar' , '%sbar' % nonascii )
690690 check ('%{}%bar' .format (nonascii ), 'ham%sbar' % nonascii )
691691
692+ @support .requires_resource ('cpu' )
693+ def test_expandvars_large (self ):
694+ expandvars = ntpath .expandvars
695+ with os_helper .EnvironmentVarGuard () as env :
696+ env .clear ()
697+ env ["A" ] = "B"
698+ n = 100_000
699+ self .assertEqual (expandvars ('%A%' * n ), 'B' * n )
700+ self .assertEqual (expandvars ('%A%A' * n ), 'BA' * n )
701+ self .assertEqual (expandvars ("''" * n + '%%' ), "''" * n + '%' )
702+ self .assertEqual (expandvars ("%%" * n ), "%" * n )
703+ self .assertEqual (expandvars ("$$" * n ), "$" * n )
704+
692705 def test_expanduser (self ):
693706 tester ('ntpath.expanduser("test")' , 'test' )
694707
@@ -923,6 +936,7 @@ def test_nt_helpers(self):
923936 self .assertIsInstance (b_final_path , bytes )
924937 self .assertGreater (len (b_final_path ), 0 )
925938
939+
926940class NtCommonTest (test_genericpath .CommonTest , unittest .TestCase ):
927941 pathmodule = ntpath
928942 attributes = ['relpath' ]
0 commit comments