本文整理汇总了Python中os.environment方法的典型用法代码示例。如果您正苦于以下问题:Python os.environment方法的具体用法?Python os.environment怎么用?Python os.environment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.environment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _testCmds
# 需要导入模块: import os [as 别名]
# 或者: from os import environment [as 别名]
def _testCmds( self, _shellEnv, testCmds, whichEnv ):
"""test commands (key) and compare output to expected output (value).
this actually executes all the commands twice, testing the return
code by calling system(), and testing some of the output by calling
execute()
"""
for cmd, pattern in testCmds:
dprint( "\nExecuting '%s' with %s environment" % (cmd, whichEnv))
p = javashell.shellexecute(cmd)
line = FileUtil.wrap(p.getInputStream()).readlines()[0]
assert re.match( pattern, line ), \
"expected match for %s, got %s" % ( pattern, line )
dprint( "waiting for", cmd, "to complete")
assert not p.waitFor(), \
"%s failed with %s environment" % (cmd, whichEnv)
示例2: testSystem
# 需要导入模块: import os [as 别名]
# 或者: from os import environment [as 别名]
def testSystem( self ):
"""test system and environment functionality"""
org = os.environ
self._testCmds( javashell._shellEnv, testCmds, "default" )
# trigger initialization of environment
os.environ[ key ] = value
assert org.get( key, None ) == value, \
"expected stub to have %s set" % key
assert os.environ.get( key, None ) == value, \
"expected real os.environment to have %s set" % key
# if environment is initialized and jython gets ARGS=-i, it thinks
# it is running in interactive mode, and fails to exit until
# process.getOutputStream().close()
try:
del os.environ[ "ARGS" ]
except KeyError:
pass
# test system using the non-default environment
self._testCmds( javashell._shellEnv, testCmds, "initialized" )
assert os.environ.has_key( "PATH" ), \
"expected environment to have PATH attribute " \
"(this may not apply to all platforms!)"
示例3: testPutEnv
# 需要导入模块: import os [as 别名]
# 或者: from os import environment [as 别名]
def testPutEnv( self ):
"Put an environment variable and ensure that spawned processes see the change"
value = "Value we set"
os.putenv( "NEWVARIABLE", value )
newValue = os.popen( "echo $NEWVARIABLE" ).read().strip()
if newValue == "$NEWVARIABLE":
newValue = os.popen( "echo %NEWVARIABLE%" ).read().strip()
if newValue == "%NEWVARIABLE%":
raise test_support.TestSkipped( "Unable to find a subshell to execute echo" )
assert newValue == value, (
"Expected (%s) to equal value we set (%s)" % (
newValue, value
))