Esempio n. 1
0
def test_map_06():
    source = """
print(foo.map())
"""
    expected = """
print(foo.map())
"""
    check_result(source, expected)
Esempio n. 2
0
def test_param_01():
    source = """
def foo(
        i,  # type: int
):
    # type: (...) -> bool
    b, a, d = i > 2  # type: bool
    return b
"""
    expected = source
    check_result(source, expected)
Esempio n. 3
0
def test_range_01():
    source = """
print(range(5))
"""
    expected = """
from builtins import range


print(list(range(5)))
"""
    check_result(source, expected)
Esempio n. 4
0
def test_param_02():
    source = """
def foo(i):
    # type: (int) -> bool
    if not i:
        # boo!
        raise ValueError("i is nothing")
    
    return i > 2
"""
    expected = source
    check_result(source, expected)
Esempio n. 5
0
def test_03():
    source = """
def foo(d):
    for k, v in d.iterkeys():
        print("{}={}".format(k, v))
"""
    expected = """
from future.utils import iterkeys


def foo(d):
    for k, v in iterkeys(d):
        print("{}={}".format(k, v))
"""
    check_result(source, expected)
Esempio n. 6
0
def test_01():
    source = """
def foo(s):
    if isinstance(s, unicode):
        return s.encode("utf-8")
"""
    expected = """
from future.utils import text_type


def foo(s):
    if isinstance(s, text_type):
        return s.encode("utf-8")
"""
    check_result(source, expected)
Esempio n. 7
0
def test_map_01():
    source = """
def foo():
    results = [1, 2, 3]
    return map(lambda i: i * 2, results)
"""
    expected = """
from builtins import map


def foo():
    results = [1, 2, 3]
    return list(map(lambda i: i * 2, results))
"""
    check_result(source, expected)
Esempio n. 8
0
def test_xrange_01():
    source = """
print(list(xrange(5)))
for i in xrange(4):
    print(i)
"""
    expected = """
from builtins import range


print(list(range(5)))
for i in range(4):
    print(i)
"""
    check_result(source, expected)
Esempio n. 9
0
def test_02():
    source = """
def foo(s):
    if isinstance(s, unicode):
        return map(lambda c:c.encode("utf-8"), s)
"""
    expected = """
from builtins import map
from future.utils import text_type


def foo(s):
    if isinstance(s, text_type):
        return list(map(lambda c:c.encode("utf-8"), s))
"""
    check_result(source, expected)
Esempio n. 10
0
def test_04():
    source = """
def foo(d):
    for k in d.iterkeys():
        print("{}".format(k))
    for k, v in d.iteritems():
        print("{}={}".format(k, v))
    for v in d.itervalues():
        print("={}".format(v))
"""
    expected = """
from future.utils import iteritems, iterkeys, itervalues


def foo(d):
    for k in iterkeys(d):
        print("{}".format(k))
    for k, v in iteritems(d):
        print("{}={}".format(k, v))
    for v in itervalues(d):
        print("={}".format(v))
"""
    check_result(source, expected)