From: <le...@us...> - 2008-08-12 22:58:49
|
Revision: 5163 http://jython.svn.sourceforge.net/jython/?rev=5163&view=rev Author: leosoto Date: 2008-08-12 22:58:47 +0000 (Tue, 12 Aug 2008) Log Message: ----------- subprocess.Popen now "inherits" os.environ if env is not explictely set. Fixes #1104 Modified Paths: -------------- branches/asm/Lib/subprocess.py Added Paths: ----------- branches/asm/Lib/test/test_subprocess_jy.py Modified: branches/asm/Lib/subprocess.py =================================================================== --- branches/asm/Lib/subprocess.py 2008-08-12 19:47:24 UTC (rev 5162) +++ branches/asm/Lib/subprocess.py 2008-08-12 22:58:47 UTC (rev 5163) @@ -1156,11 +1156,16 @@ except java.lang.IllegalArgumentException, iae: raise OSError(iae.getMessage() or iae) - if env is not None: - builder_env = builder.environment() - builder_env.clear() - builder_env.putAll(dict(env)) + if env is None: + # This is for compatibility with the CPython implementation, + # that ends up calling os.execvp(). So os.environ is "inherited" + # there if env is not explicitly set. + env = os.environ + builder_env = builder.environment() + builder_env.clear() + builder_env.putAll(dict(env)) + if cwd is None: cwd = os.getcwd() elif not os.path.exists(cwd): Added: branches/asm/Lib/test/test_subprocess_jy.py =================================================================== --- branches/asm/Lib/test/test_subprocess_jy.py (rev 0) +++ branches/asm/Lib/test/test_subprocess_jy.py 2008-08-12 22:58:47 UTC (rev 5163) @@ -0,0 +1,23 @@ +"Tests for cmp() compatibility with CPython" +import unittest +import os +import sys +from test import test_support +from subprocess import Popen, PIPE + +class EnvironmentInheritanceTest(unittest.TestCase): + def testDefaultEnvIsInherited(self): + # Test for issue #1104 + os.environ['foo'] = 'something' + p1 = Popen([sys.executable, "-c", + 'import os, sys; sys.stdout.write(os.environ["foo"])'], + stdout=PIPE) + self.assertEquals('something', p1.stdout.read()) + +def test_main(): + test_support.run_unittest(EnvironmentInheritanceTest) + +if __name__ == '__main__': + test_main() + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |