[pypy-svn] r16758 - in pypy/release/0.7.x/pypy/module/posix: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Sat Aug 27 14:34:50 CEST 2005
Author: cfbolz
Date: Sat Aug 27 14:34:49 2005
New Revision: 16758
Modified:
pypy/release/0.7.x/pypy/module/posix/interp_posix.py
pypy/release/0.7.x/pypy/module/posix/test/test_posix2.py
Log:
test + fix for a bug in unsetenv that crashed the interpreter :-(
Modified: pypy/release/0.7.x/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/release/0.7.x/pypy/module/posix/interp_posix.py (original)
+++ pypy/release/0.7.x/pypy/module/posix/interp_posix.py Sat Aug 27 14:34:49 2005
@@ -224,10 +224,11 @@
"""unsetenv(key)
Delete an environment variable."""
- os.unsetenv(name)
- # Remove the key from posix_putenv_garbage;
- # this will cause it to be collected. This has to
- # happen after the real unsetenv() call because the
- # old value was still accessible until then.
- del get(space).posix_putenv_garbage[name]
+ if name in get(space).posix_putenv_garbage:
+ os.unsetenv(name)
+ # Remove the key from posix_putenv_garbage;
+ # this will cause it to be collected. This has to
+ # happen after the real unsetenv() call because the
+ # old value was still accessible until then.
+ del get(space).posix_putenv_garbage[name]
unsetenv.unwrap_spec = [ObjSpace, str]
Modified: pypy/release/0.7.x/pypy/module/posix/test/test_posix2.py
==============================================================================
--- pypy/release/0.7.x/pypy/module/posix/test/test_posix2.py (original)
+++ pypy/release/0.7.x/pypy/module/posix/test/test_posix2.py Sat Aug 27 14:34:49 2005
@@ -74,3 +74,31 @@
pass
else:
raise "did not raise"
+
+class AppTestEnvironment(object):
+ def setup_class(cls):
+ cls.space = space
+ cls.w_posix = space.appexec([], "(): import %s as m ; return m" % os.name)
+ cls.w_os = space.appexec([], "(): import os; return os")
+ cls.w_path = space.wrap(str(path))
+ def test_environ(self):
+ posix = self.posix
+ os = self.os
+
+ def test_unsetenv_nonexisting(self):
+ os = self.os
+ os.unsetenv("XYZABC") #does not raise
+ try:
+ os.environ["ABCABC"]
+ except KeyError:
+ pass
+ else:
+ raise AssertionError("did not raise KeyError")
+ os.environ["ABCABC"] = "1"
+ assert os.environ["ABCABC"] == "1"
+ if hasattr(os, "unsetenv"):
+ os.unsetenv("ABCABC")
+ cmd = '''python -c "import os, sys; sys.exit(int('ABCABC' in os.environ))" '''
+ res = os.system(cmd)
+ assert res == 0
+
More information about the Pypy-commit
mailing list