Esempio n. 1
0
def test_block_trailing_close_paren():
    body = ('    x += int("42"\n'
            '             )\n')
    s = X1_WITH + body
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    yield from block_checks_glb('b', glbs, body, {'x': 1})
Esempio n. 2
0
def test_blockfunc__trailing_line_continuation():
    body = ('        x += \\\n'
            '             42\n')
    s = FUNC_WITH.format(body=body)
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    yield from block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL)
Esempio n. 3
0
def test_block_func_trailing_close_paren():
    body = ('        x += int("42"\n'
            '                 )\n')
    s = FUNC_WITH.format(body=body)
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    yield from block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL)
Esempio n. 4
0
def test_functor_oneline_append():
    body = '    x.append(3)\n'
    calls = 'f()\n'
    s = XA_WITH.format(body=body, calls=calls)
    glbs = {'Functor': Functor}
    check_exec(s, glbs=glbs, locs=None)
    yield from block_checks_glb('f', glbs, body, {'x': [1, 2, 3]})
Esempio n. 5
0
def test_block_trailing_line_continuation():
    body = ('    x += \\\n'
            '         42\n')
    s = X1_WITH + body
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    yield from block_checks_glb('b', glbs, body, {'x': 1})
Esempio n. 6
0
def test_block_leading_comment():
    # leading comments do not show up in block lines
    body = "    # I am a leading comment\n" "    x += 42\n"
    s = X1_WITH + body
    glbs = {"Block": Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb("b", glbs, ["    x += 42"], {"x": 1})
Esempio n. 7
0
def test_block_noexec():
    s = ('x = 1\n'
         'with Block():\n'
         '    x += 42\n')
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    assert_equal(1, glbs['x'])
Esempio n. 8
0
def test_functor_return():
    body = "    x = 42"
    t = "res = 0\n" 'with! Functor(rtn="x") as f:\n' "{body}\n" "res = f()\n"
    s = t.format(body=body)
    glbs = {"Functor": Functor}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb("f", glbs, body, {"res": 42})
Esempio n. 9
0
def test_functor_oneline_onecall_both():
    body = "    global x\n" "    x += 42\n"
    calls = "f()\nf.func()"
    s = X2_WITH.format(body=body, calls=calls, var="x")
    glbs = {"Functor": Functor}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb("f", glbs, body, {"x": 86})
Esempio n. 10
0
def test_functor_oneline_append():
    body = "    x.append(3)\n"
    calls = "f()\n"
    s = XA_WITH.format(body=body, calls=calls)
    glbs = {"Functor": Functor}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb("f", glbs, body, {"x": [1, 2, 3]})
Esempio n. 11
0
def test_block_func_trailing_comment():
    # trailing comments show up in block lines
    body = "        x += 42\n" "        # I am a trailing comment\n"
    s = FUNC_WITH.format(body=body)
    glbs = {"Block": Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_func("rtn", glbs, body, FUNC_OBSG, FUNC_OBSL)
Esempio n. 12
0
def test_functor_oneline_onecall_func():
    body = "    global z\n" "    z += 42\n"
    calls = "f.func()"
    s = X2_WITH.format(body=body, calls=calls, var="z")
    glbs = {"Functor": Functor}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb("f", glbs, body, {"z": 44})
Esempio n. 13
0
def test_block_func_leading_comment():
    # leading comments do not show up in block lines
    body = "        # I am a leading comment\n" "        x += 42\n"
    s = FUNC_WITH.format(body=body)
    glbs = {"Block": Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_func("rtn", glbs, "        x += 42\n", FUNC_OBSG, FUNC_OBSL)
Esempio n. 14
0
def test_block_trailing_comment():
    # trailing comments show up in block lines
    body = "    x += 42\n" "    # I am a trailing comment\n"
    s = X1_WITH + body
    glbs = {"Block": Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb("b", glbs, body, {"x": 1})
Esempio n. 15
0
def test_block_leading_comment():
    # leading comments do not show up in block lines
    body = ('    # I am a leading comment\n'
            '    x += 42\n')
    s = X1_WITH + body
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    yield from block_checks_glb('b', glbs, ['    x += 42'], {'x': 1})
Esempio n. 16
0
def test_block_manylines():
    body = ('    ![echo wow mom]\n'
            '# bad place for a comment\n'
            '    x += 42')
    s = X1_WITH + body
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    yield from block_checks_glb('b', glbs, body, {'x': 1})
Esempio n. 17
0
def test_functor_oneline_onecall_class():
    body = ('    global x\n'
            '    x += 42\n')
    calls = 'f()'
    s = X2_WITH.format(body=body, calls=calls)
    glbs = {'Functor': Functor}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb('f', glbs, body, {'x': 44})
Esempio n. 18
0
def test_functor_oneline_onecall_func():
    body = ('    global z\n'
            '    z += 42\n')
    calls = 'f.func()'
    s = X2_WITH.format(body=body, calls=calls, var='z')
    glbs = {'Functor': Functor}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb('f', glbs, body, {'z': 44})
Esempio n. 19
0
def test_functor_oneline_onecall_both():
    body = ('    global x\n'
            '    x += 42\n')
    calls = 'f()\nf.func()'
    s = X2_WITH.format(body=body, calls=calls)
    glbs = {'Functor': Functor}
    check_exec(s, glbs=glbs, locs=None)
    yield from block_checks_glb('f', glbs, body, {'x': 86})
Esempio n. 20
0
def test_block_func_manylines():
    body = ('        ![echo wow mom]\n'
            '# bad place for a comment\n'
            '        x += 42\n')
    s = FUNC_WITH.format(body=body)
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    yield from block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL)
Esempio n. 21
0
def test_block_trailing_close_many():
    body = ('    x = {None: [int("42"\n'
            '                    )\n'
            '                ]\n'
            '         }\n')
    s = SIMPLE_WITH + body
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb('b', glbs, body)
Esempio n. 22
0
def test_block_func_trailing_comment():
    # trailing comments do not show up in block lines
    body = ('        x += 42\n'
            '        # I am a trailing comment\n')
    s = FUNC_WITH.format(body=body)
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_func('rtn', glbs, '        x += 42\n',
                                 FUNC_OBSG, FUNC_OBSL)
Esempio n. 23
0
def test_block_func_trailing_close_many():
    body = ('        x = {None: [int("42"\n'
            '                        )\n'
            '                    ]\n'
            '             }\n')
    s = FUNC_WITH.format(body=body)
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL)
Esempio n. 24
0
def test_block_func_trailing_comment():
    # trailing comments do not show up in block lines
    body = ('        x += 42\n'
            '        # I am a trailing comment\n')
    s = FUNC_WITH.format(body=body)
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    yield from block_checks_func('rtn', glbs, '        x += 42\n',
                                 FUNC_OBSG, FUNC_OBSL)
Esempio n. 25
0
def test_block_trailing_close_many():
    body = ('    x = {None: [int("42"\n'
            '                    )\n'
            '                ]\n'
            '         }\n')
    s = SIMPLE_WITH + body
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    yield from block_checks_glb('b', glbs, body)
Esempio n. 26
0
def test_block_func_trailing_close_many():
    body = ('        x = {None: [int("42"\n'
            '                        )\n'
            '                    ]\n'
            '             }\n')
    s = FUNC_WITH.format(body=body)
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL)
Esempio n. 27
0
def test_functor_fullsig():
    body = '    x = 42 + a + b + c\n'
    t = ('res = 0\n'
         'with Functor(args=("c",), kwargs={{"a": 1, "b": 12}}, rtn="x") as f:\n'
         '{body}\n'
         'res = f(55)\n')
    s = t.format(body=body)
    glbs = {'Functor': Functor}
    check_exec(s, glbs=glbs, locs=None)
    yield from block_checks_glb('f', glbs, body, {'res': 110})
Esempio n. 28
0
def test_functor_kwargs():
    body = '    x = 42 + a + b\n'
    t = ('res = 0\n'
         'with Functor(kwargs={{"a": 1, "b": 12}}, rtn="x") as f:\n'
         '{body}\n'
         'res = f(b=6)\n')
    s = t.format(body=body)
    glbs = {'Functor': Functor}
    check_exec(s, glbs=glbs, locs=None)
    yield from block_checks_glb('f', glbs, body, {'res': 49})
Esempio n. 29
0
def test_functor_return():
    body = '    x = 42\n'
    t = ('res = 0\n'
         'with Functor(rtn="x") as f:\n'
         '{body}\n'
         'res = f()\n')
    s = t.format(body=body)
    glbs = {'Functor': Functor}
    check_exec(s, glbs=glbs, locs=None)
    yield from block_checks_glb('f', glbs, body, {'res': 42})
Esempio n. 30
0
def test_block_func_trailing_triple_string():
    body = ('        x = """This\n'
            'is\n'
            '"probably"\n'
            '\'not\' what I meant.\n'
            '"""\n')
    s = FUNC_WITH.format(body=body)
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    yield from block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL)
Esempio n. 31
0
def test_functor_return():
    body = '    x = 42\n'
    t = ('res = 0\n'
         'with Functor(rtn="x") as f:\n'
         '{body}\n'
         'res = f()\n')
    s = t.format(body=body)
    glbs = {'Functor': Functor}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb('f', glbs, body, {'res': 42})
Esempio n. 32
0
def test_block_trailing_triple_string():
    body = ('    x = """This\n'
            'is\n'
            '"probably"\n'
            '\'not\' what I meant.\n'
            '"""\n')
    s = SIMPLE_WITH + body
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    yield from block_checks_glb('b', glbs, body)
Esempio n. 33
0
def test_functor_fullsig():
    body = '    x = 42 + a + b + c\n'
    t = ('res = 0\n'
         'with Functor(args=("c",), kwargs={{"a": 1, "b": 12}}, rtn="x") as f:\n'
         '{body}\n'
         'res = f(55)\n')
    s = t.format(body=body)
    glbs = {'Functor': Functor}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb('f', glbs, body, {'res': 110})
Esempio n. 34
0
def test_functor_args():
    body = '    x = 42 + a\n'
    t = ('res = 0\n'
         'with Functor(args=("a",), rtn="x") as f:\n'
         '{body}\n'
         'res = f(2)\n')
    s = t.format(body=body)
    glbs = {'Functor': Functor}
    check_exec(s, glbs=glbs, locs=None)
    yield from block_checks_glb('f', glbs, body, {'res': 44})
Esempio n. 35
0
def test_functor_kwargs():
    body = '    x = 42 + a + b\n'
    t = ('res = 0\n'
         'with Functor(kwargs={{"a": 1, "b": 12}}, rtn="x") as f:\n'
         '{body}\n'
         'res = f(b=6)\n')
    s = t.format(body=body)
    glbs = {'Functor': Functor}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb('f', glbs, body, {'res': 49})
Esempio n. 36
0
def test_functor_kwargs():
    body = "    x = 42 + a + b"
    t = ("res = 0\n"
         'with! Functor(kwargs={{"a": 1, "b": 12}}, rtn="x") as f:\n'
         "{body}\n"
         "res = f(b=6)\n")
    s = t.format(body=body)
    glbs = {"Functor": Functor}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb("f", glbs, body, {"res": 49})
Esempio n. 37
0
def test_block_func_trailing_triple_string():
    body = ('        x = """This\n'
            'is\n'
            '"probably"\n'
            '\'not\' what I meant.\n'
            '"""\n')
    s = FUNC_WITH.format(body=body)
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL)
Esempio n. 38
0
def test_functor_args():
    body = "    x = 42 + a"
    t = ("res = 0\n"
         'with! Functor(args=("a",), rtn="x") as f:\n'
         "{body}\n"
         "res = f(2)\n")
    s = t.format(body=body)
    glbs = {"Functor": Functor}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb("f", glbs, body, {"res": 44})
Esempio n. 39
0
def test_functor_args():
    body = '    x = 42 + a\n'
    t = ('res = 0\n'
         'with Functor(args=("a",), rtn="x") as f:\n'
         '{body}\n'
         'res = f(2)\n')
    s = t.format(body=body)
    glbs = {'Functor': Functor}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb('f', glbs, body, {'res': 44})
Esempio n. 40
0
def test_block_trailing_triple_string():
    body = ('    x = """This\n'
            'is\n'
            '"probably"\n'
            '\'not\' what I meant.\n'
            '"""\n')
    s = SIMPLE_WITH + body
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb('b', glbs, body)
Esempio n. 41
0
def test_block_func_trailing_close_many():
    body = (
        '        x = {None: [int("42"\n'
        "                        )\n"
        "                    ]\n"
        "             }\n"
    )
    s = FUNC_WITH.format(body=body)
    glbs = {"Block": Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_func("rtn", glbs, body, FUNC_OBSG, FUNC_OBSL)
Esempio n. 42
0
def test_functor_fullsig():
    body = "    x = 42 + a + b + c"
    t = (
        "res = 0\n"
        'with! Functor(args=("c",), kwargs={{"a": 1, "b": 12}}, rtn="x") as f:\n'
        "{body}\n"
        "res = f(55)\n")
    s = t.format(body=body)
    glbs = {"Functor": Functor}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb("f", glbs, body, {"res": 110})
Esempio n. 43
0
def test_blockfunc__trailing_line_continuation():
    body = "        x += \\\n" "             42\n"
    s = FUNC_WITH.format(body=body)
    glbs = {"Block": Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_func("rtn", glbs, body, FUNC_OBSG, FUNC_OBSL)
Esempio n. 44
0
def test_block_func_manylines():
    body = "        ![echo wow mom]\n" "# bad place for a comment\n" "        x += 42\n"
    s = FUNC_WITH.format(body=body)
    glbs = {"Block": Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_func("rtn", glbs, body, FUNC_OBSG, FUNC_OBSL)
Esempio n. 45
0
def test_block_func_oneline():
    body = "        x += 42\n"
    s = FUNC_WITH.format(body=body)
    glbs = {"Block": Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_func("rtn", glbs, body, FUNC_OBSG, FUNC_OBSL)
Esempio n. 46
0
def test_block_trailing_triple_string():
    body = '    x = """This\n' "is\n" '"probably"\n' "'not' what I meant.\n" '"""\n'
    s = SIMPLE_WITH + body
    glbs = {"Block": Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb("b", glbs, body)
Esempio n. 47
0
def test_block_oneline():
    body = "    x += 42\n"
    s = X1_WITH + body
    glbs = {"Block": Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb("b", glbs, body, {"x": 1})
Esempio n. 48
0
def test_block_func_trailing_close_paren():
    body = '        x += int("42"\n' "                 )\n"
    s = FUNC_WITH.format(body=body)
    glbs = {"Block": Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_func("rtn", glbs, body, FUNC_OBSG, FUNC_OBSL)
Esempio n. 49
0
def test_blockfunc__trailing_line_continuation():
    body = ('        x += \\\n' '             42\n')
    s = FUNC_WITH.format(body=body)
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL)
Esempio n. 50
0
def test_block_func_oneline():
    body = '        x += 42\n'
    s = FUNC_WITH.format(body=body)
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_func('rtn', glbs, body, FUNC_OBSG, FUNC_OBSL)
Esempio n. 51
0
def test_block_trailing_close_paren():
    body = ('    x += int("42"\n' '             )\n')
    s = X1_WITH + body
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb('b', glbs, body, {'x': 1})
Esempio n. 52
0
def test_block_trailing_line_continuation():
    body = ('    x += \\\n' '         42\n')
    s = X1_WITH + body
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb('b', glbs, body, {'x': 1})
Esempio n. 53
0
def test_block_func_trailing_triple_string():
    body = '        x = """This\n' "is\n" '"probably"\n' "'not' what I meant.\n" '"""\n'
    s = FUNC_WITH.format(body=body)
    glbs = {"Block": Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_func("rtn", glbs, body, FUNC_OBSG, FUNC_OBSL)
Esempio n. 54
0
def test_block_noexec():
    s = ('x = 1\n' 'with Block():\n' '    x += 42\n')
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    assert 1 == glbs['x']
Esempio n. 55
0
def test_block_oneline():
    body = '    x += 42\n'
    s = X1_WITH + body
    glbs = {'Block': Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb('b', glbs, body, {'x': 1})
Esempio n. 56
0
def test_block_trailing_line_continuation():
    body = "    x += \\\n" "         42\n"
    s = X1_WITH + body
    glbs = {"Block": Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb("b", glbs, body, {"x": 1})
Esempio n. 57
0
def test_block_noexec():
    s = "x = 1\n" "with! Block():\n" "    x += 42\n"
    glbs = {"Block": Block}
    check_exec(s, glbs=glbs, locs=None)
    assert 1 == glbs["x"]
Esempio n. 58
0
def test_block_trailing_close_paren():
    body = '    x += int("42"\n' "             )\n"
    s = X1_WITH + body
    glbs = {"Block": Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb("b", glbs, body, {"x": 1})
Esempio n. 59
0
def test_block_manylines():
    body = "    ![echo wow mom]\n" "# bad place for a comment\n" "    x += 42"
    s = X1_WITH + body
    glbs = {"Block": Block}
    check_exec(s, glbs=glbs, locs=None)
    block_checks_glb("b", glbs, body, {"x": 1})
Esempio n. 60
0
def test_exec_scope_reuse():
    # Scopes should not be reused between execs.
    # A first-pass incorrect solution to issue 4363 made this mistake.
    assert check_exec("x = 0")
    with pytest.raises(NameError):
        check_exec("print(x)")