summaryrefslogtreecommitdiff
path: root/test/input/func_string_format_py27.py
blob: cd3071be57d8de4c233a8cb3ae665ccfce27f16f (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
70
"""test for Python 3 string formatting error
"""
# pylint: disable=too-few-public-methods, import-error, unused-argument
import os
from missing import Missing

__revision__ = 1

class Custom(object):
    """ Has a __getattr__ """
    def __getattr__(self):
        return self

class Test(object):
    """ test format attribute access """
    custom = Custom()
    ids = [1, 2, 3, [4, 5, 6]]

class Getitem(object):
    """ test custom getitem for lookup access """
    def __getitem__(self, index):
        return 42

class ReturnYes(object):
    """ can't be properly infered """
    missing = Missing()

def log(message, message_type="error"):
    """ Test """
    return message

def pprint():
    """Test string format """
    print "{{}}".format(1)
    print "{} {".format()
    print "{} }".format()
    print "{0} {}".format(1, 2)
    print "{0} {1}".format(1, 2)
    print "{0} {1} {a}".format(1, 2, 3)
    print "{a} {b}".format(a=1, c=2)
    print "{} {a}".format(1, 2)
    print "{} {}".format(1)
    print "{} {}".format(1, 2, 3)
    print "{a} {b} {c}".format()
    print "{} {}".format(a=1, b=2)
    print "{a} {b}".format(1, 2)
    print "{0!r:20}".format("Hello")
    print "{!r:20}".format("Hello")
    print "{a!r:20}".format(a="Hello")
    print "{a.test}".format(a=Custom())
    print "{a.__len__}".format(a=[])
    print "{a.ids.__len__}".format(a=Test())
    print "{a.ids.__len__.length}".format(a=Test())
    print "{a[0]}".format(a=Getitem())
    print "{a[0][0]}".format(a=[Getitem()])
    print "{a[0][0]}".format(a=[[1]])
    print "{[0][0]}".format(((1, )))
    print "{[0][0]}".format({0: {0: 1}})
    print "{[0][0]}".format(["test"])
    print "{a.ids[3][1]}".format(a=Test())
    print "{a.ids[3][400]}".format(a=Test())
    print "{a.ids[3]['string']}".format(a=Test())
    print "{[0][1]}".format(["a"])
    print "{0.missing.length}".format(ReturnYes())
    print "{1.missing.length}".format(ReturnYes())
    print "{b[0]}".format(a=23)
    print "{a[0]}".format(a=object)
    print "{a}".format(a=Missing())
    print log("{}".format(2, "info"))
    print "{pid}".format(pid=os.getpid())