Close #17702: os.environ now raises KeyError with the original environment

variable name (str on UNIX), instead of using the encoded name (bytes on UNIX).
This commit is contained in:
Victor Stinner 2013-04-14 16:35:04 +02:00
parent c4e0d982f3
commit 6d10139d70
3 changed files with 34 additions and 4 deletions

View file

@ -632,6 +632,24 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
key = 'key='
self.assertRaises(OSError, os.environ.__delitem__, key)
def test_key_type(self):
missing = 'missingkey'
self.assertNotIn(missing, os.environ)
try:
os.environ[missing]
except KeyError as err:
self.assertIs(err.args[0], missing)
else:
self.fail("KeyError not raised")
try:
del os.environ[missing]
except KeyError as err:
self.assertIs(err.args[0], missing)
else:
self.fail("KeyError not raised")
class WalkTests(unittest.TestCase):
"""Tests for os.walk()."""