Python os.environment() Examples
The following are 9
code examples of os.environment().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
os
, or try the search function
.
Example #1
Source File: test_javashell.py From medicare-demo with Apache License 2.0 | 5 votes |
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)
Example #2
Source File: test_javashell.py From medicare-demo with Apache License 2.0 | 5 votes |
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!)"
Example #3
Source File: test_javashell.py From medicare-demo with Apache License 2.0 | 5 votes |
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 ))
Example #4
Source File: test_javashell.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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)
Example #5
Source File: test_javashell.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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!)"
Example #6
Source File: test_javashell.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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 ))
Example #7
Source File: test_javashell.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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)
Example #8
Source File: test_javashell.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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!)"
Example #9
Source File: test_javashell.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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 ))