11import ntpath
22import os
3- import subprocess
43import sys
54import unittest
65import warnings
76from ntpath import ALLOW_MISSING
8- from test .support import TestFailed , FakePath
7+ from test .support import TestFailed , FakePath , EnvironmentVarGuard
98from test import support , test_genericpath
109from tempfile import TemporaryFile
1110
@@ -642,7 +641,7 @@ def test_realpath_cwd(self):
642641 ntpath .realpath ("file.txt" , ** kwargs ))
643642
644643 def test_expandvars (self ):
645- with support . EnvironmentVarGuard () as env :
644+ with EnvironmentVarGuard () as env :
646645 env .clear ()
647646 env ["foo" ] = "bar"
648647 env ["{foo" ] = "baz1"
@@ -671,7 +670,7 @@ def test_expandvars(self):
671670 def test_expandvars_nonascii (self ):
672671 def check (value , expected ):
673672 tester ('ntpath.expandvars(%r)' % value , expected )
674- with support . EnvironmentVarGuard () as env :
673+ with EnvironmentVarGuard () as env :
675674 env .clear ()
676675 nonascii = support .FS_NONASCII
677676 env ['spam' ] = nonascii
@@ -687,10 +686,23 @@ def check(value, expected):
687686 check ('%spam%bar' , '%sbar' % nonascii )
688687 check ('%{}%bar' .format (nonascii ), 'ham%sbar' % nonascii )
689688
689+ @support .requires_resource ('cpu' )
690+ def test_expandvars_large (self ):
691+ expandvars = ntpath .expandvars
692+ with EnvironmentVarGuard () as env :
693+ env .clear ()
694+ env ["A" ] = "B"
695+ n = 100_000
696+ self .assertEqual (expandvars ('%A%' * n ), 'B' * n )
697+ self .assertEqual (expandvars ('%A%A' * n ), 'BA' * n )
698+ self .assertEqual (expandvars ("''" * n + '%%' ), "''" * n + '%' )
699+ self .assertEqual (expandvars ("%%" * n ), "%" * n )
700+ self .assertEqual (expandvars ("$$" * n ), "$" * n )
701+
690702 def test_expanduser (self ):
691703 tester ('ntpath.expanduser("test")' , 'test' )
692704
693- with support . EnvironmentVarGuard () as env :
705+ with EnvironmentVarGuard () as env :
694706 env .clear ()
695707 tester ('ntpath.expanduser("~test")' , '~test' )
696708
@@ -908,6 +920,7 @@ def test_nt_helpers(self):
908920 self .assertIsInstance (b_final_path , bytes )
909921 self .assertGreater (len (b_final_path ), 0 )
910922
923+
911924class NtCommonTest (test_genericpath .CommonTest , unittest .TestCase ):
912925 pathmodule = ntpath
913926 attributes = ['relpath' ]
0 commit comments