From 1650149733eee84a21ee4e27e88d495dff80264e Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Fri, 14 Sep 2018 07:08:32 -0700 Subject: [PATCH] Add tests for six.environ --- test_six.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/test_six.py b/test_six.py index 897e2322f..5f484862f 100644 --- a/test_six.py +++ b/test_six.py @@ -1010,3 +1010,57 @@ def test_ensure_text(self): assert converted_unicode == self.UNICODE_EMOJI and isinstance(converted_unicode, str) # PY3: bytes -> str assert converted_binary == self.UNICODE_EMOJI and isinstance(converted_unicode, str) + + +@py.test.fixture +def env_var(): + try: + old_six_test = os.environ['_six_test'] + except KeyError: + old_six_test = None + else: + del os.environ['_six_test'] + + yield + + if old_six_test is not None: + os.environ['_six_test'] = old_six_test + + +class EnvironTests: + + # grinning face emoji + UNICODE_EMOJI = six.u("\U0001F600") + BINARY_EMOJI = b"\xf0\x9f\x98\x80" + + def test_set_environ(self, env_var): + six.environ['_six_test'] = UNICODE_EMOJI + + assert six.environ['_six_test'] == UNICODE_EMOJI + assert six.environb['_six_test'] == BINARY_EMOJI + if PY3: + assert os.environ == UNICODE_EMOJI + else: + assert os.environ == BINARY_EMOJI + + def test_set_environb(self, env_var): + six.environb['_six_test'] = BINARY_EMOJI + + assert six.environ['_six_test'] == UNICODE_EMOJI + assert six.environb['_six_test'] == BINARY_EMOJI + if PY3: + assert os.environ == UNICODE_EMOJI + else: + assert os.environ == BINARY_EMOJI + + def test_del_environ(self, env_var): + six.environ['_six_test'] = 'testing' + assert '_six_test' in os.environ + del six.environ['_six_test'] + assert '_six_test' not in os.environ + + def test_del_environb(self, env_var): + six.environb['_six_test'] = 'testing' + assert '_six_test' in os.environ + del six.environb['_six_test'] + assert '_six_test' not in os.environ