diff options
author | Thomas Grainger <tagrain@gmail.com> | 2014-09-16 10:32:06 +0100 |
---|---|---|
committer | Thomas Grainger <tagrain@gmail.com> | 2014-09-16 10:32:06 +0100 |
commit | 5ddcb9e038680badbeef5a560311f16099b7e9ea (patch) | |
tree | 22b0711a2b069c4125b000d8139e731cc28462ca /test_six.py | |
parent | 6fcb27ef82c673e17012e95a079fe77757db62ea (diff) | |
download | six-git-5ddcb9e038680badbeef5a560311f16099b7e9ea.tar.gz |
add tests for python_2_unicode_comapatible
Diffstat (limited to 'test_six.py')
-rw-r--r-- | test_six.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test_six.py b/test_six.py index 0125d6b..c744b29 100644 --- a/test_six.py +++ b/test_six.py @@ -734,3 +734,24 @@ def test_add_metaclass(): __slots__ = "__weakref__", MySlotsWeakref = six.add_metaclass(Meta)(MySlotsWeakref) assert type(MySlotsWeakref) is Meta + + +def test_python_2_unicode_compatible(): + @six.python_2_unicode_compatible + class MyTest(object): + def __str__(self): + return six.u('hello') + + def __bytes__(self): + return six.b('hello') + + my_test = MyTest() + + if six.PY2: + assert str(my_test) == six.b("hello") + assert unicode(my_test) == six.u("hello") + elif six.PY3: + assert bytes(my_test) == six.b("hello") + assert str(my_test) == six.u("hello") + + assert getattr(six.moves.builtins, 'bytes', str)(my_test) == six.b("hello") |