mirror of
https://github.com/python/cpython.git
synced 2025-11-02 19:12:55 +00:00
Fixed ntpath.expandvars to not replace references to non-existing
variables with nothing. Also added tests. This fixes bug #494589.
This commit is contained in:
parent
fa3d08b4a9
commit
33a0a06d31
4 changed files with 32 additions and 2 deletions
|
|
@ -115,6 +115,28 @@ tester("ntpath.normpath('K:../.././..')", r'K:..\..\..')
|
|||
tester("ntpath.normpath('C:////a/b')", r'C:\a\b')
|
||||
tester("ntpath.normpath('//machine/share//a/b')", r'\\machine\share\a\b')
|
||||
|
||||
oldenv = os.environ.copy()
|
||||
try:
|
||||
os.environ.clear()
|
||||
os.environ["foo"] = "bar"
|
||||
os.environ["{foo"] = "baz1"
|
||||
os.environ["{foo}"] = "baz2"
|
||||
tester('ntpath.expandvars("foo")', "foo")
|
||||
tester('ntpath.expandvars("$foo bar")', "bar bar")
|
||||
tester('ntpath.expandvars("${foo}bar")', "barbar")
|
||||
tester('ntpath.expandvars("$[foo]bar")', "$[foo]bar")
|
||||
tester('ntpath.expandvars("$bar bar")', "$bar bar")
|
||||
tester('ntpath.expandvars("$?bar")', "$?bar")
|
||||
tester('ntpath.expandvars("${foo}bar")', "barbar")
|
||||
tester('ntpath.expandvars("$foo}bar")', "bar}bar")
|
||||
tester('ntpath.expandvars("${foo")', "${foo")
|
||||
tester('ntpath.expandvars("${{foo}}")', "baz1}")
|
||||
tester('ntpath.expandvars("$foo$foo")', "barbar")
|
||||
tester('ntpath.expandvars("$bar$bar")', "$bar$bar")
|
||||
finally:
|
||||
os.environ.clear()
|
||||
os.environ.update(oldenv)
|
||||
|
||||
# ntpath.abspath() can only be used on a system with the "nt" module
|
||||
# (reasonably), so we protect this test with "import nt". This allows
|
||||
# the rest of the tests for the ntpath module to be run to completion
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue