Clean up, remove compat with py < 3.6
[pyi2ncommon] / test / test_type_helpers.py
CommitLineData
3237d2a6
CH
1# The software in this package is distributed under the GNU General
2# Public License version 2 (with a special exception described below).
3#
4# A copy of GNU General Public License (GPL) is included in this distribution,
5# in the file COPYING.GPL.
6#
7# As a special exception, if other files instantiate templates or use macros
8# or inline functions from this file, or you compile this file and link it
9# with other works to produce a work based on this file, this file
10# does not by itself cause the resulting work to be covered
11# by the GNU General Public License.
12#
13# However the source code for this file must still be made available
14# in accordance with section (3) of the GNU General Public License.
15#
16# This exception does not invalidate any other reasons why a work based
17# on this file might be covered by the GNU General Public License.
f365f614
CH
18#
19# Copyright (c) 2016-2018 Intra2net AG <info@intra2net.com>
3237d2a6 20
e8de64e2
CH
21""" type_helper_unittest.py: unit tests for type_helpers
22
7628bc48 23Test classes and functions in type_helpers
e8de64e2
CH
24
25Should be run from python2 and python3!
26
27For help see :py:mod:`unittest`
e8de64e2
CH
28"""
29
30import unittest
e8de64e2
CH
31from sys import version_info
32
7628bc48 33from src.type_helpers import is_unicode, isstr
e8de64e2 34
e8de64e2
CH
35
36class TypeHelperTester(unittest.TestCase):
37
e8de64e2
CH
38 def test_is_unicode(self):
39 """ tests function is_unicode """
40
41 self.assertFalse(is_unicode(1))
42 self.assertFalse(is_unicode([]))
43 self.assertFalse(is_unicode(unittest.TestCase))
44 self.assertFalse(is_unicode(type(unittest.TestCase)))
45
7628bc48
CH
46 self.assertTrue(is_unicode('bla'))
47 self.assertTrue(is_unicode(r'bla'))
48 self.assertFalse(is_unicode(b'bla'))
49 self.assertFalse(is_unicode(br'bla'))
e8de64e2
CH
50
51 def test_isstr(self):
52 """ test function isstr """
53
54 tests = [
55 ('abc', True), (u'abc', True), (r'abc', True),
7628bc48
CH
56 (1, False), (['a', 'b', 'c'], False), (('a', 'b', 'c'), False),
57 (b'abc', False)]
e8de64e2
CH
58
59 for test_var, expected_result in tests:
60 self.assertEqual(isstr(test_var), expected_result,
61 'isstr of var {0} (which is of type {1}) returned'
62 '{2} but expected {3}!'
63 .format(test_var, type(test_var), isstr(test_var),
64 expected_result))
65
66
67if __name__ == '__main__':
68 unittest.main()