Skip to content

Commit

Permalink
Tests for python3.
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-golovanov committed Apr 9, 2017
1 parent 8a338f5 commit c5b2351
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import unittest

import unilog.convert
import unilog.compat


class TestClass(object):
Expand All @@ -17,6 +18,14 @@ def __init__(self):
class UniTest(unittest.TestCase):

def test_iterable(self):
values = {
'date': u"u'2016-12-06'",
'datetime': u"u'2016-12-06 11:22:33.444444'",
'unicode': u"u'пункт3'"
}
if unilog.compat.PY33:
values = {k: v.replace('u', '') for k, v in values.items()}

self.assertEqual(
unilog.as_unicode(
[
Expand All @@ -33,35 +42,44 @@ def test_iterable(self):
False
]
),
u"[u'2016-12-06', u'2016-12-06 11:22:33.444444', 'item1', 'пункт2', "
u"u'пункт3', 4, 4.44, b'\\\\x00\\\\x01\\\\x02', None, True, False]"
u"[{date}, {datetime}, 'item1', 'пункт2', {unicode}, 4, 4.44, "
u"b'\\x00\\x01\\x02', None, True, False]".format(**values)
)

def test_mapping(self):
generator = (i for i in xrange(10))
generator = (i for i in unilog.compat.XRangeType(10))
result = (
"{{\n"
" 'generators': [\n"
" '{!r}',\n"
" '{}'\n"
" ]\n"
"}}".format(
generator, 'range(0, 10)' if unilog.compat.PY33 else 'xrange(10)'
)
)
if unilog.compat.PY33:
result = result.encode(unilog.convert.LOCALE)

self.assertEqual(
unilog.as_str(
{
'generators': [
generator,
xrange(10)
unilog.compat.XRangeType(10)
]
},
pretty=True
),
"{{\n"
" 'generators': [\n"
" '{!r}',\n"
" 'xrange(10)'\n"
" ]\n"
"}}".format(generator)
result
)

def test_register_converter(self):
unilog.register_converter(
TestClass,
lambda x: [x.test1, x.test2]
)

self.assertEqual(
unilog.as_unicode(TestClass()),
u"['test1', 2]"
Expand Down

0 comments on commit c5b2351

Please sign in to comment.