Skip to content

Commit e71482e

Browse files
committed
Add tests for six.environ
1 parent 6f5915a commit e71482e

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

test_six.py

+54
Original file line numberDiff line numberDiff line change
@@ -990,3 +990,57 @@ def test_ensure_text(self):
990990
assert converted_unicode == self.UNICODE_EMOJI and isinstance(converted_unicode, str)
991991
# PY3: bytes -> str
992992
assert converted_binary == self.UNICODE_EMOJI and isinstance(converted_unicode, str)
993+
994+
995+
@py.test.fixture
996+
def env_var():
997+
try:
998+
old_six_test = os.environ['_six_test']
999+
except KeyError:
1000+
old_six_test = None
1001+
else:
1002+
del os.environ['_six_test']
1003+
1004+
yield
1005+
1006+
if old_six_test is not None:
1007+
os.envion['_six_test'] = old_six_test
1008+
1009+
1010+
class EnvironTests:
1011+
1012+
# grinning face emoji
1013+
UNICODE_EMOJI = six.u("\U0001F600")
1014+
BINARY_EMOJI = b"\xf0\x9f\x98\x80"
1015+
1016+
def test_set_environ(self, env_var):
1017+
six.environ['_six_test'] = UNICODE_EMOJI
1018+
1019+
assert six.environ['_six_test'] == UNICODE_EMOJI
1020+
assert six.environb['_six_test'] == BINARY_EMOJI
1021+
if PY3:
1022+
assert os.environ == UNICODE_EMOJI
1023+
else:
1024+
assert os.environ == BINARY_EMOJI
1025+
1026+
def test_set_environb(self, env_var):
1027+
six.environb['_six_test'] = BINARY_EMOJI
1028+
1029+
assert six.environ['_six_test'] == UNICODE_EMOJI
1030+
assert six.environb['_six_test'] == BINARY_EMOJI
1031+
if PY3:
1032+
assert os.environ == UNICODE_EMOJI
1033+
else:
1034+
assert os.environ == BINARY_EMOJI
1035+
1036+
def test_del_environ(self, env_var):
1037+
six.environ['_six_test'] = 'testing'
1038+
assert '_six_test' in os.environ
1039+
del six.environ['_six_test']
1040+
assert '_six_test' not in os.environ
1041+
1042+
def test_del_environb(self, env_var):
1043+
six.environb['_six_test'] = 'testing'
1044+
assert '_six_test' in os.environ
1045+
del six.environb['_six_test']
1046+
assert '_six_test' not in os.environ

0 commit comments

Comments
 (0)