summaryrefslogtreecommitdiff
path: root/tests/compathelper.py
blob: 668e60a55eb133cd6860fa291b964fd048b2870a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import sys

if sys.version_info >= (3, 0):
    '''
    for tests that need to test long values in python 2

    python 3 does not differentiate between long and int
    and does not supply a long keyword

    instead of testing longs by using values such as 10L
    test writters should do this:

    from compathelper import _long
    _long(10)
    '''
    _long = int

    '''
    for tests that need to test string values in python 2

    python 3 does differentiate between str and bytes
    and does not supply a basestring keyword

    any tests that use basestring should do this:

    from compathelper import _basestring
    isinstance(_basestring, "hello")
    '''
    _basestring = str

    '''
    for tests that need to write to intefaces that take bytes in
    python 3

    python 3 has a seperate bytes type for low level functions like os.write

    python 2 treats these as strings

    any tests that need to write a string of bytes should do something like
    this:

    from compathelper import _bytes
    os.write(_bytes("hello"))
    '''

    _bytes = lambda s: s.encode()

    '''
    for tests that need to write to intefaces that take unicode in
    python 2

    python 3 strings are unicode encoded as UTF-8 so the unicode object
    doesn't exist

    python 2 differs between a string an unicode string and you must specify
    an encoding.  This macro will specify UTF-8 in python 2

    any tests that need to use unicode should do this

    from compathelper import _unicode
    unicode_string = _unicode('this is a unicode string')
    '''

    _unicode = lambda s: str(s)
else:
    _long = long
    _basestring = basestring
    _bytes = str
    _unicode = lambda s: unicode(s, 'UTF-8')