本文整理匯總了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
))