From 97bb7023d531f2a1bc94d25e3ca6c8e77ca4d7bc Mon Sep 17 00:00:00 2001 From: Frank Hoffmann <15r10nk-git@polarbit.de> Date: Wed, 29 Mar 2023 22:08:24 +0200 Subject: [PATCH] test: added tests for ipython --- .github/workflows/test.yml | 4 +++- setup.cfg | 6 +++++ tests/test_ipython.py | 49 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/test_ipython.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fca96d0..9e3e49f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/setup.cfg b/setup.cfg index d22b4e2..3ee513e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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' @@ -41,6 +44,9 @@ executing = py.typed [coverage:run] relative_files = True +include = executing/executing.py +parallel = true +branch = true [bdist_wheel] universal=1 diff --git a/tests/test_ipython.py b/tests/test_ipython.py new file mode 100644 index 0000000..b2ea648 --- /dev/null +++ b/tests/test_ipython.py @@ -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 +