File: test_ipython.py

package info (click to toggle)
python-executing 2.2.0-0.3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,860 kB
  • sloc: python: 10,235; sh: 48; makefile: 10
file content (41 lines) | stat: -rw-r--r-- 855 bytes parent folder | download | duplicates (2)
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
import subprocess as sp
import sys
import pytest


def run(input):
    p = sp.run(
        [sys.executable, "-m", "IPython", "--colors=nocolor", "--simple-prompt"],
        input=input.encode("utf8"),
        stdout=sp.PIPE,
    )
    output = p.stdout.decode("utf8")
    print(output)
    return output


test_function_code = """
from executing import Source
import inspect
import ast

def test():
    frame = inspect.currentframe()
    ex = Source.executing(frame.f_back)
    print(ex.node)
    if not isinstance(ex.node,ast.Call):
        print("test failure")
    if not ex.node.func.id=="test":
        print("test failure")

"""


def test_one_lookup():
    p = run(test_function_code + "test()")
    assert "test failure" not in p


def test_two_statement_lookups():
    p = run(test_function_code + "test();test()")
    assert "test failure" in p