我们从Python开源项目中,提取了以下13个代码示例,用于说明如何使用ntpath.expandvars()。
def test_expandvars(self): with support.EnvironmentVarGuard() as env: env.clear() env["foo"] = "bar" env["{foo"] = "baz1" env["{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") tester('ntpath.expandvars("%foo% bar")', "bar bar") tester('ntpath.expandvars("%foo%bar")', "barbar") tester('ntpath.expandvars("%foo%%foo%")', "barbar") tester('ntpath.expandvars("%%foo%%foo%foo%")', "%foo%foobar") tester('ntpath.expandvars("%?bar%")', "%?bar%") tester('ntpath.expandvars("%foo%%bar")', "bar%bar") tester('ntpath.expandvars("\'%foo%\'%bar")', "\'%foo%\'%bar")
def test_expandvars(self): with test_support.EnvironmentVarGuard() as env: env.clear() env["foo"] = "bar" env["{foo"] = "baz1" env["{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")', "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") tester('ntpath.expandvars("%foo% bar")', "bar bar") tester('ntpath.expandvars("%foo%bar")', "barbar") tester('ntpath.expandvars("%foo%%foo%")', "barbar") tester('ntpath.expandvars("%%foo%%foo%foo%")', "%foo%foobar") tester('ntpath.expandvars("%?bar%")', "%?bar%") tester('ntpath.expandvars("%foo%%bar")', "bar%bar") tester('ntpath.expandvars("\'%foo%\'%bar")', "\'%foo%\'%bar") tester('ntpath.expandvars("bar\'%foo%")', "bar\'%foo%")
def test_expandvars_nonascii(self): encoding = sys.getfilesystemencoding() def check(value, expected): tester0("ntpath.expandvars(%r)" % value, expected) tester0("ntpath.expandvars(%r)" % value.decode(encoding), expected.decode(encoding)) with test_support.EnvironmentVarGuard() as env: env.clear() unonascii = test_support.FS_NONASCII snonascii = unonascii.encode(encoding) env['spam'] = snonascii env[snonascii] = 'ham' + snonascii check('$spam bar', '%s bar' % snonascii) check('$%s bar' % snonascii, '$%s bar' % snonascii) check('${spam}bar', '%sbar' % snonascii) check('${%s}bar' % snonascii, 'ham%sbar' % snonascii) check('$spam}bar', '%s}bar' % snonascii) check('$%s}bar' % snonascii, '$%s}bar' % snonascii) check('%spam% bar', '%s bar' % snonascii) check('%{}% bar'.format(snonascii), 'ham%s bar' % snonascii) check('%spam%bar', '%sbar' % snonascii) check('%{}%bar'.format(snonascii), 'ham%sbar' % snonascii)
def test_expandvars(self): with test_support.EnvironmentVarGuard() as env: env.clear() env["foo"] = "bar" env["{foo"] = "baz1" env["{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")', "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") tester('ntpath.expandvars("%foo% bar")', "bar bar") tester('ntpath.expandvars("%foo%bar")', "barbar") tester('ntpath.expandvars("%foo%%foo%")', "barbar") tester('ntpath.expandvars("%%foo%%foo%foo%")', "%foo%foobar") tester('ntpath.expandvars("%?bar%")', "%?bar%") tester('ntpath.expandvars("%foo%%bar")', "bar%bar") tester('ntpath.expandvars("\'%foo%\'%bar")', "\'%foo%\'%bar")
def test_expandvars(self): with support.EnvironmentVarGuard() as env: env.clear() env["foo"] = "bar" env["{foo"] = "baz1" env["{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")', "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") tester('ntpath.expandvars("%foo% bar")', "bar bar") tester('ntpath.expandvars("%foo%bar")', "barbar") tester('ntpath.expandvars("%foo%%foo%")', "barbar") tester('ntpath.expandvars("%%foo%%foo%foo%")', "%foo%foobar") tester('ntpath.expandvars("%?bar%")', "%?bar%") tester('ntpath.expandvars("%foo%%bar")', "bar%bar") tester('ntpath.expandvars("\'%foo%\'%bar")', "\'%foo%\'%bar") tester('ntpath.expandvars("bar\'%foo%")', "bar\'%foo%")
def test_expandvars_nonascii(self): def check(value, expected): tester('ntpath.expandvars(%r)' % value, expected) with support.EnvironmentVarGuard() as env: env.clear() nonascii = support.FS_NONASCII env['spam'] = nonascii env[nonascii] = 'ham' + nonascii check('$spam bar', '%s bar' % nonascii) check('$%s bar' % nonascii, '$%s bar' % nonascii) check('${spam}bar', '%sbar' % nonascii) check('${%s}bar' % nonascii, 'ham%sbar' % nonascii) check('$spam}bar', '%s}bar' % nonascii) check('$%s}bar' % nonascii, '$%s}bar' % nonascii) check('%spam% bar', '%s bar' % nonascii) check('%{}% bar'.format(nonascii), 'ham%s bar' % nonascii) check('%spam%bar', '%sbar' % nonascii) check('%{}%bar'.format(nonascii), 'ham%sbar' % nonascii)
def test_expandvars(self): with test_support.EnvironmentVarGuard() as env: env.clear() env["foo"] = "bar" env["{foo"] = "baz1" env["{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") tester('ntpath.expandvars("%foo% bar")', "bar bar") tester('ntpath.expandvars("%foo%bar")', "barbar") tester('ntpath.expandvars("%foo%%foo%")', "barbar") tester('ntpath.expandvars("%%foo%%foo%foo%")', "%foo%foobar") tester('ntpath.expandvars("%?bar%")', "%?bar%") tester('ntpath.expandvars("%foo%%bar")', "bar%bar") tester('ntpath.expandvars("\'%foo%\'%bar")', "\'%foo%\'%bar")
def test_expandvars(self): with support.EnvironmentVarGuard() as env: env.clear() env["foo"] = "bar" env["{foo"] = "baz1" env["{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")', "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") tester('ntpath.expandvars("%foo% bar")', "bar bar") tester('ntpath.expandvars("%foo%bar")', "barbar") tester('ntpath.expandvars("%foo%%foo%")', "barbar") tester('ntpath.expandvars("%%foo%%foo%foo%")', "%foo%foobar") tester('ntpath.expandvars("%?bar%")', "%?bar%") tester('ntpath.expandvars("%foo%%bar")', "bar%bar") tester('ntpath.expandvars("\'%foo%\'%bar")', "\'%foo%\'%bar")