-
-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compat: support unicode in environment variables
On Python2 we have to encode provide utf-8 bytestrings if we want unicode values in enviornment variables. Python3 accepts them as-is. Related-to: #282 Reported-by: V字龍(Vdragon) <pika1021@gmail.com> Signed-off-by: David Aguilar <davvid@gmail.com>
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python | ||
# -*- encoding: utf-8 -*- | ||
|
||
from __future__ import unicode_literals | ||
|
||
import os | ||
import unittest | ||
|
||
from cola import compat | ||
|
||
|
||
class CompatTestCase(unittest.TestCase): | ||
"""Tests the compat module""" | ||
|
||
def test_setenv(self): | ||
"""Test the core.decode function | ||
""" | ||
key = 'COLA_UNICODE_TEST' | ||
value = '字龍' | ||
compat.setenv(key, value) | ||
self.assertTrue(key in os.environ) | ||
self.assertTrue(os.getenv(key)) | ||
|
||
compat.unsetenv(key) | ||
self.assertFalse(key in os.environ) | ||
self.assertFalse(os.getenv(key)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |