Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test ipython support #69

Merged
merged 2 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ jobs:
env:
EXECUTING_SLOW_TESTS: 1
run: |
coverage run --include=executing/executing.py --append -m pytest tests
# COVERAGE_PROCESS_START defines the path to the coverage config for coverage-enable-subprocess
export COVERAGE_PROCESS_START=${GITHUB_WORKSPACE}/setup.cfg
coverage run -m pytest tests
# combine the coverage of all subprocesses
coverage combine
alexmojaki marked this conversation as resolved.
Show resolved Hide resolved
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
41 changes: 41 additions & 0 deletions tests/test_ipython.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
Loading