Skip to content

Commit

Permalink
test: added tests for ipython
Browse files Browse the repository at this point in the history
  • Loading branch information
15r10nk committed Mar 29, 2023
1 parent 0e5096a commit 97bb702
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ jobs:
- name: Test
env:
EXECUTING_SLOW_TESTS: 1
COVERAGE_PROCESS_START: ${GITHUB_WORKSPACE}/setup.cfg
run: |
coverage run --include=executing/executing.py --append -m pytest tests
coverage run -m pytest tests
coverage combine
coverage report -m
- name: Coveralls Python
uses: AndreMiras/coveralls-python-action@v20201129
Expand Down
6 changes: 6 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ install_requires =
[options.extras_require]
tests=
asttokens>=2.1.0
ipython
pytest
coverage
coverage-enable-subprocess
littleutils
rich; python_version >='3.11'

Expand All @@ -41,6 +44,9 @@ executing = py.typed

[coverage:run]
relative_files = True
include = executing/executing.py
parallel = true
branch = true

[bdist_wheel]
universal=1
49 changes: 49 additions & 0 deletions tests/test_ipython.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

import subprocess as sp
import sys

def test_one_lookup():
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")
test()
"""
p=sp.run([sys.executable,"-m","IPython", '--colors=nocolor', '--simple-prompt'],input=code,capture_output=True,encoding="utf8")
print(p.stdout)
assert "test failure" not in p.stdout


def test_two_statement_lookups():
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")
test();test()
"""
p=sp.run([sys.executable,"-m","IPython", '--colors=nocolor', '--simple-prompt'],input=code,capture_output=True,encoding="utf8")
print(p.stdout)
assert "test failure" in p.stdout

0 comments on commit 97bb702

Please sign in to comment.