Skip to content

Commit

Permalink
Add tests for six.environ
Browse files Browse the repository at this point in the history
  • Loading branch information
abadger committed Nov 14, 2018
1 parent 277c50d commit 1650149
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test_six.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1650149

Please sign in to comment.