Branch and push for 2.0
[profile/ivi/pygobject2.git] / tests / compathelper.py
1 import sys
2
3 if sys.version_info >= (3, 0):
4     '''
5     for tests that need to test long values in python 2
6
7     python 3 does not differentiate between long and int
8     and does not supply a long keyword
9
10     instead of testing longs by using values such as 10L
11     test writters should do this:
12
13     from compathelper import _long
14     _long(10)
15     '''
16     _long = int
17
18     '''
19     for tests that need to test string values in python 2
20
21     python 3 does differentiate between str and bytes
22     and does not supply a basestring keyword
23
24     any tests that use basestring should do this:
25
26     from compathelper import _basestring
27     isinstance(_basestring, "hello")
28     '''
29     _basestring = str
30
31     '''
32     for tests that need to write to intefaces that take bytes in
33     python 3
34
35     python 3 has a seperate bytes type for low level functions like os.write
36
37     python 2 treats these as strings
38
39     any tests that need to write a string of bytes should do something like
40     this:
41
42     from compathelper import _bytes
43     os.write(_bytes("hello"))
44     '''
45
46     _bytes = lambda s: s.encode()
47
48     '''
49     for tests that need to write to intefaces that take unicode in
50     python 2
51
52     python 3 strings are unicode encoded as UTF-8 so the unicode object 
53     doesn't exist
54
55     python 2 differs between a string an unicode string and you must specify
56     an encoding.  This macro will specify UTF-8 in python 2
57
58     any tests that need to use unicode should do this
59
60     from compathelper import _unicode
61     unicode_string = _unicode('this is a unicode string')
62     '''
63
64     _unicode = lambda s: str(s)
65 else:
66     _long = long
67     _basestring = basestring
68     _bytes = str
69     _unicode = lambda s: unicode(s, 'UTF-8')