pax_global_header00006660000000000000000000000064143007055020014506gustar00rootroot0000000000000052 comment=3de4a3bcb44b1952f00ed03197c378abbd2e4a20 jupyter_kernel_test-0.4.5/000077500000000000000000000000001430070550200156155ustar00rootroot00000000000000jupyter_kernel_test-0.4.5/.flake8000066400000000000000000000006451430070550200167750ustar00rootroot00000000000000[flake8] ignore = E501, W503, E402 builtins = c, get_config exclude = .cache, .github, docs, setup.py enable-extensions = G extend-ignore = G001, G002, G004, G200, G201, G202, # black adds spaces around ':' E203, per-file-ignores = # B011: Do not call assert False since python -O removes these calls # F841 local variable 'foo' is assigned to but never used test_*.py: B011, F841 jupyter_kernel_test-0.4.5/.git-blame-ignore-revs000066400000000000000000000001631430070550200217150ustar00rootroot00000000000000# Adopt pre-commit https://github.com/jupyter/jupyter_kernel_test/pull/73 0f56150ddb3775fcbcf114a205a4ceb8c469e492 jupyter_kernel_test-0.4.5/.github/000077500000000000000000000000001430070550200171555ustar00rootroot00000000000000jupyter_kernel_test-0.4.5/.github/workflows/000077500000000000000000000000001430070550200212125ustar00rootroot00000000000000jupyter_kernel_test-0.4.5/.github/workflows/check-release.yml000066400000000000000000000014741430070550200244360ustar00rootroot00000000000000name: Check Release on: push: branches: ["master"] pull_request: branches: ["*"] jobs: check_release: runs-on: ubuntu-latest strategy: matrix: group: [check_release, link_check] steps: - name: Checkout uses: actions/checkout@v2 - name: Base Setup uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 - name: Install Dependencies run: | pip install -e . - name: Check Release if: ${{ matrix.group == 'check_release' }} uses: jupyter-server/jupyter_releaser/.github/actions/check-release@v1 with: token: ${{ secrets.GITHUB_TOKEN }} - name: Run Link Check if: ${{ matrix.group == 'link_check' }} uses: jupyter-server/jupyter_releaser/.github/actions/check-links@v1 jupyter_kernel_test-0.4.5/.github/workflows/enforce-label.yml000066400000000000000000000005001430070550200244260ustar00rootroot00000000000000name: Enforce PR label on: pull_request: types: [labeled, unlabeled, opened, edited, synchronize] jobs: enforce-label: runs-on: ubuntu-latest permissions: pull-requests: write steps: - name: enforce-triage-label uses: jupyterlab/maintainer-tools/.github/actions/enforce-label@v1 jupyter_kernel_test-0.4.5/.github/workflows/tests.yml000066400000000000000000000061641430070550200231060ustar00rootroot00000000000000name: Tests on: push: pull_request: schedule: - cron: "0 0 * * *" concurrency: group: tests-${{ github.ref }} cancel-in-progress: true defaults: run: shell: bash -l {0} jobs: test: name: Test runs-on: ${{ matrix.os }} timeout-minutes: 15 strategy: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] python-version: ["3.7", "3.10"] include: - os: windows-latest python-version: "3.9" - os: macos-latest python-version: "3.8" env: OS: ${{ matrix.os }} steps: - name: Checkout uses: actions/checkout@v2 - name: Base setup uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 - name: Setup conda ${{ matrix.python-version }} uses: conda-incubator/setup-miniconda@v2 with: auto-update-conda: true environment-file: environment.yml activate-environment: jupyter_kernel_test python-version: ${{ matrix.python-version }} # Xeus Cling Kernel Test is not working - times out. # - name: Install xeus-cling # if: startsWith(runner.os, 'Linux') # run: | # conda install -c conda-forge xeus-cling - name: Install dependencies run: | pip install -e .[test] - name: Run the tests run: python -m unittest -v || python -m unittest -v test_minimum_versions: name: Test Minimum Versions timeout-minutes: 20 runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Base Setup uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 with: python_version: "3.7" - name: Install miniumum versions uses: jupyterlab/maintainer-tools/.github/actions/install-minimums@v1 - name: Run the unit tests run: | python -m unittest -v || python -m unittest -v test_prereleases: name: Test Prereleases runs-on: ubuntu-latest timeout-minutes: 20 steps: - name: Checkout uses: actions/checkout@v2 - name: Base Setup uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 - name: Install the Python dependencies run: | pip install --pre -e ".[test]" - name: List installed packages run: | pip freeze pip check - name: Run the tests run: | python -m unittest -v || python -m unittest -v make_sdist: name: Make SDist runs-on: ubuntu-latest timeout-minutes: 10 steps: - uses: actions/checkout@v2 - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 - uses: jupyterlab/maintainer-tools/.github/actions/make-sdist@v1 test_sdist: runs-on: ubuntu-latest needs: [make_sdist] name: Install from SDist and Test timeout-minutes: 15 steps: - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 - uses: jupyterlab/maintainer-tools/.github/actions/test-sdist@v1 with: test_command: "python -m unittest -v || python -m unittest -v" jupyter_kernel_test-0.4.5/.gitignore000066400000000000000000000000341430070550200176020ustar00rootroot00000000000000__pycache__/ /build/ /dist/ jupyter_kernel_test-0.4.5/.pre-commit-config.yaml000066400000000000000000000031131430070550200220740ustar00rootroot00000000000000ci: skip: [check-jsonschema] repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.3.0 hooks: - id: end-of-file-fixer - id: check-case-conflict - id: check-executables-have-shebangs - id: requirements-txt-fixer - id: check-added-large-files - id: check-case-conflict - id: check-toml - id: check-yaml - id: debug-statements - id: forbid-new-submodules - id: check-builtin-literals - id: trailing-whitespace - repo: https://github.com/psf/black rev: 22.6.0 hooks: - id: black args: ["--line-length", "100"] - repo: https://github.com/PyCQA/isort rev: 5.10.1 hooks: - id: isort files: \.py$ args: [--profile=black] - repo: https://github.com/pre-commit/mirrors-prettier rev: v2.7.1 hooks: - id: prettier - repo: https://github.com/asottile/pyupgrade rev: v2.37.3 hooks: - id: pyupgrade args: [--py37-plus] - repo: https://github.com/PyCQA/doc8 rev: v1.0.0 hooks: - id: doc8 args: [--max-line-length=200] - repo: https://github.com/pycqa/flake8 rev: 5.0.4 hooks: - id: flake8 additional_dependencies: ["flake8-bugbear==22.6.22", "flake8-implicit-str-concat==0.2.0"] - repo: https://github.com/sirosen/check-jsonschema rev: 0.17.1 hooks: - id: check-jsonschema name: "Check GitHub Workflows" files: ^\.github/workflows/ types: [yaml] args: ["--schemafile", "https://json.schemastore.org/github-workflow"] jupyter_kernel_test-0.4.5/CHANGELOG.md000066400000000000000000000264371430070550200174420ustar00rootroot00000000000000# Changelog ## 0.4.5 ([Full Changelog](https://github.com/jupyter/jupyter_kernel_test/compare/v0.4.4...85c23f820f8127808f60dab6f5871e8d26c01192)) ### Maintenance and upkeep improvements - Switch to hatch backend [#100](https://github.com/jupyter/jupyter_kernel_test/pull/100) ([@blink1073](https://github.com/blink1073)) ### Contributors to this release ([GitHub contributors page for this release](https://github.com/jupyter/jupyter_kernel_test/graphs/contributors?from=2022-08-19&to=2022-08-22&type=c)) [@blink1073](https://github.com/search?q=repo%3Ajupyter%2Fjupyter_kernel_test+involves%3Ablink1073+updated%3A2022-08-19..2022-08-22&type=Issues) ## 0.4.4 ([Full Changelog](https://github.com/jupyter/jupyter_kernel_test/compare/v0.4.3...b723ce668df0de185f9b682d85379e515cfc012b)) ### Maintenance and upkeep improvements - Stop testing xeus cling [#97](https://github.com/jupyter/jupyter_kernel_test/pull/97) ([@blink1073](https://github.com/blink1073)) - [pre-commit.ci] pre-commit autoupdate [#96](https://github.com/jupyter/jupyter_kernel_test/pull/96) ([@pre-commit-ci](https://github.com/pre-commit-ci)) - Fix flake8 v5 compat [#95](https://github.com/jupyter/jupyter_kernel_test/pull/95) ([@blink1073](https://github.com/blink1073)) - [pre-commit.ci] pre-commit autoupdate [#94](https://github.com/jupyter/jupyter_kernel_test/pull/94) ([@pre-commit-ci](https://github.com/pre-commit-ci)) - [pre-commit.ci] pre-commit autoupdate [#92](https://github.com/jupyter/jupyter_kernel_test/pull/92) ([@pre-commit-ci](https://github.com/pre-commit-ci)) - [pre-commit.ci] pre-commit autoupdate [#91](https://github.com/jupyter/jupyter_kernel_test/pull/91) ([@pre-commit-ci](https://github.com/pre-commit-ci)) - [pre-commit.ci] pre-commit autoupdate [#90](https://github.com/jupyter/jupyter_kernel_test/pull/90) ([@pre-commit-ci](https://github.com/pre-commit-ci)) - [pre-commit.ci] pre-commit autoupdate [#89](https://github.com/jupyter/jupyter_kernel_test/pull/89) ([@pre-commit-ci](https://github.com/pre-commit-ci)) - [pre-commit.ci] pre-commit autoupdate [#88](https://github.com/jupyter/jupyter_kernel_test/pull/88) ([@pre-commit-ci](https://github.com/pre-commit-ci)) - [pre-commit.ci] pre-commit autoupdate [#87](https://github.com/jupyter/jupyter_kernel_test/pull/87) ([@pre-commit-ci](https://github.com/pre-commit-ci)) - [pre-commit.ci] pre-commit autoupdate [#86](https://github.com/jupyter/jupyter_kernel_test/pull/86) ([@pre-commit-ci](https://github.com/pre-commit-ci)) - [pre-commit.ci] pre-commit autoupdate [#85](https://github.com/jupyter/jupyter_kernel_test/pull/85) ([@pre-commit-ci](https://github.com/pre-commit-ci)) - [pre-commit.ci] pre-commit autoupdate [#84](https://github.com/jupyter/jupyter_kernel_test/pull/84) ([@pre-commit-ci](https://github.com/pre-commit-ci)) - [pre-commit.ci] pre-commit autoupdate [#83](https://github.com/jupyter/jupyter_kernel_test/pull/83) ([@pre-commit-ci](https://github.com/pre-commit-ci)) - Enable auto-label for bot PRs [#82](https://github.com/jupyter/jupyter_kernel_test/pull/82) ([@blink1073](https://github.com/blink1073)) - [pre-commit.ci] pre-commit autoupdate [#81](https://github.com/jupyter/jupyter_kernel_test/pull/81) ([@pre-commit-ci](https://github.com/pre-commit-ci)) - Run tests twice [#80](https://github.com/jupyter/jupyter_kernel_test/pull/80) ([@blink1073](https://github.com/blink1073)) - Use flit build backend [#79](https://github.com/jupyter/jupyter_kernel_test/pull/79) ([@blink1073](https://github.com/blink1073)) - [pre-commit.ci] pre-commit autoupdate [#78](https://github.com/jupyter/jupyter_kernel_test/pull/78) ([@pre-commit-ci](https://github.com/pre-commit-ci)) - [pre-commit.ci] pre-commit autoupdate [#77](https://github.com/jupyter/jupyter_kernel_test/pull/77) ([@pre-commit-ci](https://github.com/pre-commit-ci)) - [pre-commit.ci] pre-commit autoupdate [#76](https://github.com/jupyter/jupyter_kernel_test/pull/76) ([@pre-commit-ci](https://github.com/pre-commit-ci)) - Adopt flake8 and update ci [#75](https://github.com/jupyter/jupyter_kernel_test/pull/75) ([@blink1073](https://github.com/blink1073)) - Add git-blame-ignore-revs [#74](https://github.com/jupyter/jupyter_kernel_test/pull/74) ([@blink1073](https://github.com/blink1073)) - Adopt pre-commit [#73](https://github.com/jupyter/jupyter_kernel_test/pull/73) ([@blink1073](https://github.com/blink1073)) - Drop support for py36 [#72](https://github.com/jupyter/jupyter_kernel_test/pull/72) ([@blink1073](https://github.com/blink1073)) - Fix typos [#71](https://github.com/jupyter/jupyter_kernel_test/pull/71) ([@martinRenou](https://github.com/martinRenou)) - Add xeus-cling test [#69](https://github.com/jupyter/jupyter_kernel_test/pull/69) ([@blink1073](https://github.com/blink1073)) ### Contributors to this release ([GitHub contributors page for this release](https://github.com/jupyter/jupyter_kernel_test/graphs/contributors?from=2021-12-06&to=2022-08-19&type=c)) [@blink1073](https://github.com/search?q=repo%3Ajupyter%2Fjupyter_kernel_test+involves%3Ablink1073+updated%3A2021-12-06..2022-08-19&type=Issues) | [@martinRenou](https://github.com/search?q=repo%3Ajupyter%2Fjupyter_kernel_test+involves%3AmartinRenou+updated%3A2021-12-06..2022-08-19&type=Issues) | [@pre-commit-ci](https://github.com/search?q=repo%3Ajupyter%2Fjupyter_kernel_test+involves%3Apre-commit-ci+updated%3A2021-12-06..2022-08-19&type=Issues) ## 0.4.3 ([Full Changelog](https://github.com/jupyter/jupyter_kernel_test/compare/v0.4.2...77a01dc64e0449e026bc505948c3f773f7a01be3)) ### Maintenance and upkeep improvements - Clean up ci [#67](https://github.com/jupyter/jupyter_kernel_test/pull/67) ([@blink1073](https://github.com/blink1073)) ### Contributors to this release ([GitHub contributors page for this release](https://github.com/jupyter/jupyter_kernel_test/graphs/contributors?from=2021-12-05&to=2021-12-06&type=c)) [@blink1073](https://github.com/search?q=repo%3Ajupyter%2Fjupyter_kernel_test+involves%3Ablink1073+updated%3A2021-12-05..2021-12-06&type=Issues) ## 0.4.2 ([Full Changelog](https://github.com/jupyter/jupyter_kernel_test/compare/v0.4.1...fcc3d1e7eaf262a1dd5b3bce7b5e160bd1d69265)) ### Bugs fixed - Add minimum `jupyter_client` version [#64](https://github.com/jupyter/jupyter_kernel_test/pull/64) ([@blink1073](https://github.com/blink1073)) ### Contributors to this release ([GitHub contributors page for this release](https://github.com/jupyter/jupyter_kernel_test/graphs/contributors?from=2021-12-02&to=2021-12-05&type=c)) [@blink1073](https://github.com/search?q=repo%3Ajupyter%2Fjupyter_kernel_test+involves%3Ablink1073+updated%3A2021-12-02..2021-12-05&type=Issues) ## 0.4.1 ([Full Changelog](https://github.com/jupyter/jupyter_kernel_test/compare/v0.4.0...87bdb591a83640ec76fe74ce11611a821653d0a6)) ### Maintenance and upkeep improvements - Add more robustness [#62](https://github.com/jupyter/jupyter_kernel_test/pull/62) ([@blink1073](https://github.com/blink1073)) ### Contributors to this release ([GitHub contributors page for this release](https://github.com/jupyter/jupyter_kernel_test/graphs/contributors?from=2021-11-30&to=2021-12-02&type=c)) [@blink1073](https://github.com/search?q=repo%3Ajupyter%2Fjupyter_kernel_test+involves%3Ablink1073+updated%3A2021-11-30..2021-12-02&type=Issues) ## 0.4.0 ([Full Changelog](https://github.com/jupyter/jupyter_kernel_test/compare/0.3...687e6f83af9cecae832c4ad8f79291322def23e5)) ### Enhancements made - Use jsonschema to validate messages [#37](https://github.com/jupyter/jupyter_kernel_test/pull/37) ([@takluyver](https://github.com/takluyver)) ### Maintenance and upkeep improvements - Prep for jupyter releaser usage [#59](https://github.com/jupyter/jupyter_kernel_test/pull/59) ([@blink1073](https://github.com/blink1073)) - Test IR Kernel and Clean Up [#58](https://github.com/jupyter/jupyter_kernel_test/pull/58) ([@blink1073](https://github.com/blink1073)) - Update for Jupyter Client 7 and GitHub Actions [#57](https://github.com/jupyter/jupyter_kernel_test/pull/57) ([@blink1073](https://github.com/blink1073)) - Fix import issue with pytest [#46](https://github.com/jupyter/jupyter_kernel_test/pull/46) ([@martinRenou](https://github.com/martinRenou)) - Use new kernel management modules [#41](https://github.com/jupyter/jupyter_kernel_test/pull/41) ([@takluyver](https://github.com/takluyver)) - Replace COPYING.md with LICENCE file [#34](https://github.com/jupyter/jupyter_kernel_test/pull/34) ([@tgb417](https://github.com/tgb417)) - Fix custom test example in README [#49](https://github.com/jupyter/jupyter_kernel_test/pull/49) ([@kylebarron](https://github.com/kylebarron)) - Fix readme [#45](https://github.com/jupyter/jupyter_kernel_test/pull/45) ([@martinRenou](https://github.com/martinRenou)) ### Contributors to this release ([GitHub contributors page for this release](https://github.com/jupyter/jupyter_kernel_test/graphs/contributors?from=2017-04-28&to=2021-11-30&type=c)) [@blink1073](https://github.com/search?q=repo%3Ajupyter%2Fjupyter_kernel_test+involves%3Ablink1073+updated%3A2017-04-28..2021-11-30&type=Issues) | [@kylebarron](https://github.com/search?q=repo%3Ajupyter%2Fjupyter_kernel_test+involves%3Akylebarron+updated%3A2017-04-28..2021-11-30&type=Issues) | [@martinRenou](https://github.com/search?q=repo%3Ajupyter%2Fjupyter_kernel_test+involves%3AmartinRenou+updated%3A2017-04-28..2021-11-30&type=Issues) | [@SylvainCorlay](https://github.com/search?q=repo%3Ajupyter%2Fjupyter_kernel_test+involves%3ASylvainCorlay+updated%3A2017-04-28..2021-11-30&type=Issues) | [@takluyver](https://github.com/search?q=repo%3Ajupyter%2Fjupyter_kernel_test+involves%3Atakluyver+updated%3A2017-04-28..2021-11-30&type=Issues) | [@tgb417](https://github.com/search?q=repo%3Ajupyter%2Fjupyter_kernel_test+involves%3Atgb417+updated%3A2017-04-28..2021-11-30&type=Issues) ## 0.3 ([Full Changelog](https://github.com/jupyter/jupyter_kernel_test/compare/7283c8c...309feed)) ### Merged PRs - Add stop_on_error [#32](https://github.com/jupyter/jupyter_kernel_test/pull/32) ([@shzhng](https://github.com/shzhng)) - Update README.rst [#29](https://github.com/jupyter/jupyter_kernel_test/pull/29) ([@maveme](https://github.com/maveme)) - Made stdout/stderr tests less order dependent. [#28](https://github.com/jupyter/jupyter_kernel_test/pull/28) ([@mariusvniekerk](https://github.com/mariusvniekerk)) - Convert readthedocs links for their .org -> .io migration for hosted projects [#26](https://github.com/jupyter/jupyter_kernel_test/pull/26) ([@adamchainz](https://github.com/adamchainz)) ### Contributors to this release ([GitHub contributors page for this release](https://github.com/jupyter/jupyter_kernel_test/graphs/contributors?from=2016-06-13&to=2017-04-28&type=c)) [@adamchainz](https://github.com/search?q=repo%3Ajupyter%2Fjupyter_kernel_test+involves%3Aadamchainz+updated%3A2016-06-13..2017-04-28&type=Issues) | [@mariusvniekerk](https://github.com/search?q=repo%3Ajupyter%2Fjupyter_kernel_test+involves%3Amariusvniekerk+updated%3A2016-06-13..2017-04-28&type=Issues) | [@maveme](https://github.com/search?q=repo%3Ajupyter%2Fjupyter_kernel_test+involves%3Amaveme+updated%3A2016-06-13..2017-04-28&type=Issues) | [@shzhng](https://github.com/search?q=repo%3Ajupyter%2Fjupyter_kernel_test+involves%3Ashzhng+updated%3A2016-06-13..2017-04-28&type=Issues) | [@takluyver](https://github.com/search?q=repo%3Ajupyter%2Fjupyter_kernel_test+involves%3Atakluyver+updated%3A2016-06-13..2017-04-28&type=Issues) jupyter_kernel_test-0.4.5/LICENSE000066400000000000000000000027561430070550200166340ustar00rootroot00000000000000Copyright (c) 2015-2021 Project Jupyter Contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. jupyter_kernel_test-0.4.5/README.rst000066400000000000000000000066161430070550200173150ustar00rootroot00000000000000=================== jupyter_kernel_test =================== ``jupyter_kernel_test`` is a tool for testing Jupyter_ kernels. It tests kernels for successful code execution and conformance with the `Jupyter Messaging Protocol`_ (currently 5.0). ------- Install ------- Install it with pip (python3.4 or greater required):: pip3 install jupyter_kernel_test ----- Usage ----- To use it, you need to write a (python) ``unittest`` file containing code samples in the relevant language which test various parts of the messaging protocol. A short example is given below, and you can also refer to the ``test_ipykernel.py`` and ``test_irkernel.py`` files for complete examples. Some parts of the messaging protocol are relevant only to the browser-based notebook (rich display) or console interfaces (code completeness, history searching). Only parts of the spec for which you provide code samples are tested. Run this file directly using python, or use ``nosetests`` or ``py.test`` to find and run it. ------- Example ------- .. code-block:: python import unittest import jupyter_kernel_test class MyKernelTests(jupyter_kernel_test.KernelTests): # Required -------------------------------------- # The name identifying an installed kernel to run the tests against kernel_name = "mykernel" # language_info.name in a kernel_info_reply should match this language_name = "mylanguage" # Optional -------------------------------------- # Code in the kernel's language to write "hello, world" to stdout code_hello_world = "print 'hello, world'" # Pager: code that should display something (anything) in the pager code_page_something = "help(something)" # Samples of code which generate a result value (ie, some text # displayed as Out[n]) code_execute_result = [ {'code': '6*7', 'result': '42'} ] # Samples of code which should generate a rich display output, and # the expected MIME type code_display_data = [ {'code': 'show_image()', 'mime': 'image/png'} ] # You can also write extra tests. We recommend putting your kernel name # in the method name, to avoid clashing with any tests that # jupyter_kernel_test adds in the future. def test_mykernel_stderr(self): self.flush_channels() reply, output_msgs = self.execute_helper(code='print_err "oops"') self.assertEqual(output_msgs[0]['header']['msg_type'], 'stream') self.assertEqual(output_msgs[0]['content']['name'], 'stderr') self.assertEqual(output_msgs[0]['content']['text'], 'oops\n') if __name__ == '__main__': unittest.main() -------- Coverage -------- The following aspects of the messaging protocol are not explicitly tested: - Widget comms: ``comm_open``, ``comm_msg``, ``comm_close`` - stdin: ``input_request``, ``input_reply`` - display_data metadata - Shutdown/restart: ``shutdown_request``, ``shutdown_reply`` - History: not all option combinations covered - Inspection: multiple levels - Execution payloads (deprecated but still used): payloads ``load``, ``edit``, ``ask_exit`` - User expressions - Execution: combinations of ``silent``, ``store_history`` and ``stop_on_error`` .. _Jupyter: http://jupyter.org .. _Jupyter Messaging Protocol: https://jupyter-client.readthedocs.io/en/latest/messaging.html jupyter_kernel_test-0.4.5/RELEASE.md000066400000000000000000000010031430070550200172110ustar00rootroot00000000000000# Release Guide ## Using `jupyter_releaser` The recommended way to make a release is to use [`jupyter_releaser`](https://github.com/jupyter-server/jupyter_releaser#checklist-for-adoption). ## Manual Release - Update `CHANGELOG` - Run the following: ```bash export VERSION= pip install jupyter_releaser tbump --only-patch $VERSION git commit -a -m "Release $VERSION" git tag $VERSION; true; git push --all git push --tags rm -rf dist build python -m build . twine check dist/* twine upload dist/* ``` jupyter_kernel_test-0.4.5/environment.yml000066400000000000000000000002041430070550200207000ustar00rootroot00000000000000name: jupyter_kernel_test channels: - conda-forge dependencies: - r-recommended - r-irkernel - pip - setuptools - wheel jupyter_kernel_test-0.4.5/jupyter_kernel_test/000077500000000000000000000000001430070550200217165ustar00rootroot00000000000000jupyter_kernel_test-0.4.5/jupyter_kernel_test/__init__.py000066400000000000000000000326621430070550200240400ustar00rootroot00000000000000"""Machinery for testing Jupyter kernels via the messaging protocol. """ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. from queue import Empty from unittest import SkipTest, TestCase from jupyter_client.manager import start_new_kernel from jupyter_client.utils import run_sync from .msgspec_v5 import validate_message TIMEOUT = 15 __version__ = "0.4.5" class KernelTests(TestCase): kernel_name = "python3" @classmethod def setUpClass(cls): cls.km, cls.kc = start_new_kernel(kernel_name=cls.kernel_name) @classmethod def tearDownClass(cls): cls.kc.stop_channels() cls.km.shutdown_kernel() def flush_channels(self): for channel in (self.kc.shell_channel, self.kc.iopub_channel): while True: try: msg = run_sync(channel.get_msg)(timeout=0.1) except Empty: break else: validate_message(msg) language_name = "" file_extension = "" def test_kernel_info(self): self.flush_channels() msg_id = self.kc.kernel_info() reply = self.kc.get_shell_msg(timeout=TIMEOUT) validate_message(reply, "kernel_info_reply", msg_id) if self.language_name: self.assertEqual(reply["content"]["language_info"]["name"], self.language_name) if self.file_extension: self.assertEqual( reply["content"]["language_info"]["file_extension"], self.file_extension ) self.assertTrue(reply["content"]["language_info"]["file_extension"].startswith(".")) def execute_helper( self, code, timeout=TIMEOUT, silent=False, store_history=True, stop_on_error=True ): msg_id = self.kc.execute( code=code, silent=silent, store_history=store_history, stop_on_error=stop_on_error ) reply = self.get_non_kernel_info_reply(timeout=timeout) validate_message(reply, "execute_reply", msg_id) busy_msg = run_sync(self.kc.iopub_channel.get_msg)(timeout=1) validate_message(busy_msg, "status", msg_id) self.assertEqual(busy_msg["content"]["execution_state"], "busy") output_msgs = [] while True: msg = run_sync(self.kc.iopub_channel.get_msg)(timeout=0.1) validate_message(msg, msg["msg_type"], msg_id) if msg["msg_type"] == "status": self.assertEqual(msg["content"]["execution_state"], "idle") break elif msg["msg_type"] == "execute_input": self.assertEqual(msg["content"]["code"], code) continue output_msgs.append(msg) return reply, output_msgs code_hello_world = "" def test_execute_stdout(self): if not self.code_hello_world: raise SkipTest self.flush_channels() reply, output_msgs = self.execute_helper(code=self.code_hello_world) self.assertEqual(reply["content"]["status"], "ok") self.assertGreaterEqual(len(output_msgs), 1) for msg in output_msgs: if (msg["msg_type"] == "stream") and (msg["content"]["name"] == "stdout"): self.assertIn("hello, world", msg["content"]["text"]) break else: self.assertTrue( False, "Expected one output message of type 'stream' and 'content.name'='stdout'" ) code_stderr = "" def test_execute_stderr(self): if not self.code_stderr: raise SkipTest self.flush_channels() reply, output_msgs = self.execute_helper(code=self.code_stderr) self.assertEqual(reply["content"]["status"], "ok") self.assertGreaterEqual(len(output_msgs), 1) for msg in output_msgs: if (msg["msg_type"] == "stream") and (msg["content"]["name"] == "stderr"): break else: self.assertTrue( False, "Expected one output message of type 'stream' and 'content.name'='stderr'" ) completion_samples = [] def get_non_kernel_info_reply(self, timeout=None): while True: reply = self.kc.get_shell_msg(timeout=timeout) if reply["header"]["msg_type"] != "kernel_info_reply": return reply def test_completion(self): if not self.completion_samples: raise SkipTest for sample in self.completion_samples: with self.subTest(text=sample["text"]): msg_id = self.kc.complete(sample["text"]) reply = self.get_non_kernel_info_reply() validate_message(reply, "complete_reply", msg_id) if "matches" in sample: self.assertEqual(set(reply["content"]["matches"]), set(sample["matches"])) complete_code_samples = [] incomplete_code_samples = [] invalid_code_samples = [] def check_is_complete(self, sample, status): msg_id = self.kc.is_complete(sample) reply = self.get_non_kernel_info_reply() validate_message(reply, "is_complete_reply", msg_id) if reply["content"]["status"] != status: msg = "For code sample\n {!r}\nExpected {!r}, got {!r}." raise AssertionError(msg.format(sample, status, reply["content"]["status"])) def test_is_complete(self): if not ( self.complete_code_samples or self.incomplete_code_samples or self.invalid_code_samples ): raise SkipTest self.flush_channels() with self.subTest(status="complete"): for sample in self.complete_code_samples: self.check_is_complete(sample, "complete") with self.subTest(status="incomplete"): for sample in self.incomplete_code_samples: self.check_is_complete(sample, "incomplete") with self.subTest(status="invalid"): for sample in self.invalid_code_samples: self.check_is_complete(sample, "invalid") code_page_something = "" def test_pager(self): if not self.code_page_something: raise SkipTest self.flush_channels() reply, output_msgs = self.execute_helper(self.code_page_something) self.assertEqual(reply["content"]["status"], "ok") payloads = reply["content"]["payload"] self.assertEqual(len(payloads), 1) self.assertEqual(payloads[0]["source"], "page") mimebundle = payloads[0]["data"] self.assertIn("text/plain", mimebundle) code_generate_error = "" def test_error(self): if not self.code_generate_error: raise SkipTest self.flush_channels() reply, output_msgs = self.execute_helper(self.code_generate_error) self.assertEqual(reply["content"]["status"], "error") self.assertEqual(len(output_msgs), 1) self.assertEqual(output_msgs[0]["msg_type"], "error") code_execute_result = [] def test_execute_result(self): if not self.code_execute_result: raise SkipTest for sample in self.code_execute_result: with self.subTest(code=sample["code"]): self.flush_channels() reply, output_msgs = self.execute_helper(sample["code"]) self.assertEqual(reply["content"]["status"], "ok") self.assertGreaterEqual(len(output_msgs), 1) found = False for msg in output_msgs: if msg["msg_type"] == "execute_result": found = True else: continue mime = sample.get("mime", "text/plain") self.assertIn(mime, msg["content"]["data"]) if "result" in sample: self.assertEqual(msg["content"]["data"][mime], sample["result"]) assert found, "execute_result message not found" code_display_data = [] def test_display_data(self): if not self.code_display_data: raise SkipTest for sample in self.code_display_data: with self.subTest(code=sample["code"]): self.flush_channels() reply, output_msgs = self.execute_helper(sample["code"]) self.assertEqual(reply["content"]["status"], "ok") self.assertGreaterEqual(len(output_msgs), 1) found = False for msg in output_msgs: if msg["msg_type"] == "display_data": found = True else: continue self.assertIn(sample["mime"], msg["content"]["data"]) assert found, "display_data message not found" # this should match one of the values in code_execute_result code_history_pattern = "" supported_history_operations = () def history_helper(self, execute_first, timeout=TIMEOUT, **histargs): self.flush_channels() for code in execute_first: reply, output_msgs = self.execute_helper(code) self.flush_channels() msg_id = self.kc.history(**histargs) reply = self.get_non_kernel_info_reply(timeout=timeout) validate_message(reply, "history_reply", msg_id) return reply def test_history(self): if not self.code_execute_result: raise SkipTest codes = [s["code"] for s in self.code_execute_result] _ = [s.get("result", "") for s in self.code_execute_result] n = len(codes) session = start = None with self.subTest(hist_access_type="tail"): if "tail" not in self.supported_history_operations: raise SkipTest reply = self.history_helper(codes, output=False, raw=True, hist_access_type="tail", n=n) self.assertEqual(len(reply["content"]["history"]), n) self.assertEqual(len(reply["content"]["history"][0]), 3) self.assertEqual(codes, [h[2] for h in reply["content"]["history"]]) session, start = reply["content"]["history"][0][0:2] with self.subTest(output=True): reply = self.history_helper( codes, output=True, raw=True, hist_access_type="tail", n=n ) self.assertEqual(len(reply["content"]["history"][0][2]), 2) with self.subTest(hist_access_type="range"): if "range" not in self.supported_history_operations: raise SkipTest if session is None: raise SkipTest reply = self.history_helper( codes, output=False, raw=True, hist_access_type="range", session=session, start=start, stop=start + 1, ) self.assertEqual(len(reply["content"]["history"]), 1) self.assertEqual(reply["content"]["history"][0][0], session) self.assertEqual(reply["content"]["history"][0][1], start) with self.subTest(hist_access_type="search"): if not self.code_history_pattern: raise SkipTest if "search" not in self.supported_history_operations: raise SkipTest with self.subTest(subsearch="normal"): reply = self.history_helper( codes, output=False, raw=True, hist_access_type="search", pattern=self.code_history_pattern, ) self.assertGreaterEqual(len(reply["content"]["history"]), 1) with self.subTest(subsearch="unique"): reply = self.history_helper( codes, output=False, raw=True, hist_access_type="search", pattern=self.code_history_pattern, unique=True, ) self.assertEqual(len(reply["content"]["history"]), 1) with self.subTest(subsearch="n"): reply = self.history_helper( codes, output=False, raw=True, hist_access_type="search", pattern=self.code_history_pattern, n=3, ) self.assertEqual(len(reply["content"]["history"]), 3) code_inspect_sample = "" def test_inspect(self): if not self.code_inspect_sample: raise SkipTest self.flush_channels() msg_id = self.kc.inspect(self.code_inspect_sample) reply = self.get_non_kernel_info_reply(timeout=TIMEOUT) validate_message(reply, "inspect_reply", msg_id) self.assertEqual(reply["content"]["status"], "ok") self.assertTrue(reply["content"]["found"]) self.assertGreaterEqual(len(reply["content"]["data"]), 1) code_clear_output = "" def test_clear_output(self): if not self.code_clear_output: raise SkipTest self.flush_channels() reply, output_msgs = self.execute_helper(code=self.code_clear_output) self.assertEqual(reply["content"]["status"], "ok") self.assertGreaterEqual(len(output_msgs), 1) found = False for msg in output_msgs: if msg["msg_type"] == "clear_output": found = True else: continue assert found, "clear_output message not found" jupyter_kernel_test-0.4.5/jupyter_kernel_test/msgspec_v5.py000066400000000000000000000302731430070550200243500ustar00rootroot00000000000000"""Message schemas for message spec version 5""" # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. import re from jsonschema import Draft4Validator, ValidationError protocol_version = (5, 1) # These fragments will be wrapped in the boilerplate for a valid JSON schema. # We also add a default 'required' containing all keys. schema_fragments = {} def get_msg_content_validator(msg_type, version_minor): frag = schema_fragments[msg_type] schema = { "$schema": "http://json-schema.org/draft-04/schema#", "description": f"{msg_type} message contents schema", "type": "object", "properties": {}, "additionalProperties": version_minor > protocol_version[1], } schema.update(frag) if "required" not in schema: # Require all keys by default schema["required"] = sorted(schema["properties"].keys()) return Draft4Validator(schema) header_part = { "type": "object", "properties": { "msg_id": {"type": "string"}, "username": {"type": "string"}, "session": {"type": "string"}, # TODO - this is parsed to a datetime before we get it: "date": {}, # {"type": "string"}, "msg_type": {"type": "string"}, "version": {"type": "string"}, }, "required": ["msg_id", "username", "session", "date", "msg_type", "version"], } msg_schema = { "$schema": "http://json-schema.org/draft-04/schema#", "description": "Jupyter message structure schema", "type": "object", "properties": { "header": header_part, "parent_header": {"type": "object"}, "metadata": {"type": "object"}, "content": {"type": "object"}, # Checked separately "buffers": {"type": "array"}, }, "required": ["header", "parent_header", "metadata", "content"], } msg_structure_validator = Draft4Validator(msg_schema) def get_error_reply_validator(version_minor): return Draft4Validator( { "$schema": "http://json-schema.org/draft-04/schema#", "description": "Jupyter 'error' reply schema", "type": "object", "properties": { "status": {"const": "error"}, "ename": {"type": "string"}, "evalue": {"type": "string"}, "traceback": {"type": "array", "items": {"type": "string"}}, }, "required": ["status", "ename", "evalue", "traceback"], "additionalProperties": version_minor > protocol_version[1], } ) def get_abort_reply_validator(version_minor): return Draft4Validator( { "$schema": "http://json-schema.org/draft-04/schema#", "description": "Jupyter 'abort' reply schema", "type": "object", "properties": { "status": {"const": "error"}, "ename": {"type": "string"}, "evalue": {"type": "string"}, "traceback": {"type": "list", "items": {"type": "string"}}, }, "required": ["status", "ename", "evalue", "traceback"], "additionalProperties": version_minor > protocol_version[1], } ) reply_msgs_using_status = { "execute_reply", "inspect_reply", "complete_reply", "history_reply", "connect_reply", "comm_info_reply", "kernel_info_reply", "shutdown_reply", "interrupt_reply", } def validate_message(msg, msg_type=None, parent_id=None): msg_structure_validator.validate(msg) msg_version_s = msg["header"]["version"] m = re.match(r"(\d+)\.(\d+)", msg_version_s) if not m: raise ValidationError("Version {} not like 'x.y'") version_minor = int(m.group(2)) if msg_type is not None: if msg["header"]["msg_type"] != msg_type: raise ValidationError( "Message type {!r} != {!r}".format(msg["header"]["msg_type"], msg_type) ) else: msg_type = msg["header"]["msg_type"] # Check for unexpected fields, unless it's a newer protocol version if version_minor <= protocol_version[1]: unx_top = set(msg) - set(msg_schema["properties"]) if unx_top: raise ValidationError(f"Unexpected keys: {unx_top}") unx_header = set(msg["header"]) - set(header_part["properties"]) if unx_header: raise ValidationError(f"Unexpected keys in header: {unx_header}") # Check the parent id if "reply" in msg_type and parent_id and msg["parent_header"]["msg_id"] != parent_id: raise ValidationError("Parent header does not match expected") if msg_type in reply_msgs_using_status: # Most _reply messages have common 'error' and 'abort' structures try: status = msg["content"]["status"] except KeyError as e: raise ValidationError(str(e)) if status == "error": content_vdor = get_error_reply_validator(version_minor) elif status == "abort": content_vdor = get_abort_reply_validator(version_minor) elif status == "ok": content_vdor = get_msg_content_validator(msg_type, version_minor) else: raise ValidationError(f"status {status!r} should be ok/error/abort") else: content_vdor = get_msg_content_validator(msg_type, version_minor) content_vdor.validate(msg["content"]) # Shell messages ---------------------------------------------- schema_fragments["execute_request"] = { "properties": { "code": {"type": "string"}, "silent": {"type": "boolean"}, "store_history": {"type": "boolean"}, "user_expressions": {"type": "object"}, "allow_stdin": {"type": "boolean"}, "stop_on_error": {"type": "boolean"}, } } schema_fragments["execute_reply"] = { "properties": { # statuses 'error' and 'abort' change the structure, so check separately "status": {"const": "ok"}, "execution_count": {"type": "number"}, "payload": { "type": "array", "items": { "type": "object", "properties": {"source": {"type": "string"}}, "additionalProperties": True, }, }, "user_expressions": {"type": "object"}, }, "required": ["status", "execution_count"], } schema_fragments["inspect_request"] = { "properties": { "code": {"type": "string"}, "cursor_pos": {"type": "number"}, "detail_level": {"enum": [0, 1]}, } } schema_fragments["inspect_reply"] = { "properties": { # statuses 'error' and 'abort' change the structure, so check separately "status": {"const": "ok"}, "found": {"type": "boolean"}, "data": {"type": "object"}, "metadata": {"type": "object"}, } } schema_fragments["complete_request"] = { "properties": { "code": {"type": "string"}, "cursor_pos": {"type": "number"}, } } schema_fragments["complete_reply"] = { "properties": { # statuses 'error' and 'abort' change the structure, so check separately "status": {"const": "ok"}, "matches": {"type": "array", "items": {"type": "string"}}, "cursor_start": {"type": "number"}, "cursor_end": {"type": "number"}, "metadata": {"type": "object"}, } } schema_fragments["history_request"] = { "properties": { "output": {"type": "boolean"}, "raw": {"type": "boolean"}, "hist_access_type": {"enum": ["range", "tail", "search"]}, "session": {"type": "number"}, "start": {"type": "number"}, "stop": {"type": "number"}, "n": {"type": "number"}, "pattern": {"type": "string"}, "unique": {"type": "boolean"}, }, "required": ["output", "raw", "hist_access_type"], } schema_fragments["history_reply"] = { "properties": { "status": {"const": "ok"}, "history": {"type": "array", "items": {"minItems": 3, "maxItems": 3}}, } } schema_fragments["is_complete_request"] = { "properties": { "code": {"type": "string"}, } } schema_fragments["is_complete_reply"] = { "properties": { "status": {"enum": ["complete", "incomplete", "invalid", "unknown"]}, "indent": {"type": "string"}, }, "required": ["status"], } # NB connect_request is deprecated schema_fragments["connect_request"] = {"properties": {}} schema_fragments["connect_reply"] = { "properties": { "shell_port": {"type": "number"}, "iopub_port": {"type": "number"}, "stdin_port": {"type": "number"}, "hb_port": {"type": "number"}, "control_port": {"type": "number"}, } } schema_fragments["comm_info_request"] = { "properties": { "target_name": {"type": "string"}, }, "required": [], } schema_fragments["comm_info_reply"] = { "properties": { # statuses 'error' and 'abort' change the structure, so check separately "status": {"const": "ok"}, "comms": {"type": "object"}, } } schema_fragments["kernel_info_request"] = {"properties": {}} schema_fragments["kernel_info_reply"] = { "properties": { # statuses 'error' and 'abort' change the structure, so check separately "status": {"const": "ok"}, "protocol_version": {"type": "string"}, "implementation": {"type": "string"}, "implementation_version": {"type": "string"}, "language_info": {"type": "object"}, "banner": {"type": "string"}, "debugger": {"type": "boolean"}, "help_links": { "type": "array", "items": { "type": "object", "properties": {"text": {"type": "string"}, "url": {"type": "string"}}, }, }, }, "required": ["status", "protocol_version", "implementation", "language_info", "banner"], } schema_fragments["shutdown_request"] = { "properties": { "restart": {"type": "boolean"}, } } schema_fragments["shutdown_reply"] = { "properties": { # statuses 'error' and 'abort' change the structure, so check separately "status": {"const": "ok"}, "restart": {"type": "boolean"}, } } schema_fragments["interrupt_request"] = {"properties": {}} schema_fragments["interrupt_reply"] = { "properties": { # statuses 'error' and 'abort' change the structure, so check separately "status": {"const": "ok"}, } } # IOPub messages ---------------------------------------------- mime_data = { "type": "object", "patternProperties": {r"^[\w\-\+\.]+/[\w\-\+\.]+$": {}}, "additionalProperties": False, } schema_fragments["stream"] = { "properties": { "name": {"enum": ["stdout", "stderr"]}, "text": {"type": "string"}, } } schema_fragments["display_data"] = { "properties": { "data": mime_data, "metadata": {"type": "object"}, "transient": {"type": "object"}, }, "required": ["data", "metadata"], } schema_fragments["update_display_data"] = { "properties": { "data": mime_data, "metadata": {"type": "object"}, "transient": {"type": "object"}, } } schema_fragments["execute_result"] = { "properties": { "execution_count": {"type": "number"}, "data": mime_data, "metadata": {"type": "object"}, "transient": {"type": "object"}, }, "required": ["execution_count", "data", "metadata"], } schema_fragments["clear_output"] = { "properties": { "wait": {"type": "boolean"}, } } schema_fragments["execute_input"] = { "properties": { "code": {"type": "string"}, "execution_count": {"type": "number"}, } } schema_fragments["error"] = { "properties": { "ename": {"type": "string"}, "evalue": {"type": "string"}, "traceback": {"type": "array", "items": {"type": "string"}}, } } schema_fragments["status"] = { "properties": { "execution_state": {"enum": ["busy", "idle", "starting"]}, } } # Stdin messages --------------------------------------------- schema_fragments["input_request"] = { "properties": { "prompt": {"type": "string"}, "password": {"type": "number"}, } } schema_fragments["input_reply"] = { "properties": { "value": {"type": "string"}, } } jupyter_kernel_test-0.4.5/pyproject.toml000066400000000000000000000022401430070550200205270ustar00rootroot00000000000000[build-system] requires = ["hatchling >=1.5"] build-backend = "hatchling.build" [project] name = "jupyter_kernel_test" license = { file = "LICENSE" } classifiers = [ "License :: OSI Approved :: BSD License", "Intended Audience :: Developers", "Programming Language :: Python :: 3", "Topic :: Software Development :: Testing" ] requires-python = ">=3.7" dependencies = [ "jupyter_client >=6.1.13", "jsonschema" ] dynamic = ["description", "version"] [[project.authors]] name = "Jupyter Development Team" email = "jupyter@googlegroups.com" [project.readme] file = "README.rst" content-type = "text/x-rst" [project.urls] Homepage = "https://github.com/jupyter/jupyter_kernel_test" [project.optional-dependencies] test = [ "ipykernel", "pre-commit" ] [tool.hatch.version] path = "jupyter_kernel_test/__init__.py" [tool.jupyter-releaser] skip = ["check-links"] [tool.tbump.version] current = "0.4.5" regex = ''' (?P\d+)\.(?P\d+)\.(?P\d+) ((?Pa|b|rc|.dev)(?P\d+))? ''' [tool.tbump.git] message_template = "Bump to {new_version}" tag_template = "v{new_version}" [[tool.tbump.file]] src = "jupyter_kernel_test/__init__.py" jupyter_kernel_test-0.4.5/test_ipykernel.py000066400000000000000000000106521430070550200212340ustar00rootroot00000000000000""" Example use of jupyter_kernel_test, with tests for the default python3 kernel (IPyKernel). This includes all the currently available tests. """ import unittest import jupyter_kernel_test as jkt class IPyKernelTests(jkt.KernelTests): # REQUIRED # the kernel to be tested # this is the normally the name of the directory containing the # kernel.json file - you should be able to do # `jupyter console --kernel KERNEL_NAME` kernel_name = "python3" # Everything else is OPTIONAL # the name of the language the kernel executes # checked against language_info.name in kernel_info_reply language_name = "python" # the normal file extension (including the leading dot) for this language # checked against language_info.file_extension in kernel_info_reply file_extension = ".py" # code which should write the exact string `hello, world` to STDOUT code_hello_world = "print('hello, world')" # code which should cause (any) text to be written to STDERR code_stderr = "import sys; print('test', file=sys.stderr)" # samples for the autocompletion functionality # for each dictionary, `text` is the input to try and complete, and # `matches` the list of all complete matching strings which should be found completion_samples = [ { "text": "zi", "matches": {"zip"}, }, ] # samples for testing code-completeness (used by console only) # these samples should respectively be unambigiously complete statements # (which should be executed on ), incomplete statements or code # which should be identified as invalid complete_code_samples = ["1", "print('hello, world')", "def f(x):\n return x*2\n\n\n"] incomplete_code_samples = ["print('''hello", "def f(x):\n x*2"] invalid_code_samples = ["import = 7q"] # code which should cause a help pager to be displayed (as of 4.1, this is # displayed by the notebook only as inline text, so it's probably more # useful for console clients) code_page_something = "zip?" # code which should generate a (user-level) error in the kernel, and send # a traceback to the client code_generate_error = "raise" # a statement or block of code which generates a result (which is shown # as Out[n] instead of just something printed to stdout) # running each `code` should cause `result` to be displayed (note that the # result here will always be a string representation of whatever the actual # result type is - be careful of string formatting) code_execute_result = [ {"code": "1+2+3", "result": "6"}, {"code": "[n*n for n in range(1, 4)]", "result": "[1, 4, 9]"}, ] # code which generates some sort of rich output # for each `code` input a single rich display object with the specified # `mime` type should be sent to the frontend # note that this expects a `display_data` message rather than # `execute_result`; this test might be a little too inflexible in some cases code_display_data = [ { "code": "from IPython.display import HTML, display; display(HTML('test'))", "mime": "text/html", }, { "code": "from IPython.display import Math, display; display(Math('\\frac{1}{2}'))", "mime": "text/latex", }, ] # test the support for searching/recalling history (used by console only) # the history tests re-use the code blocks in `code_execute_result` above, # so will not run if no test code is available # `code_history_pattern` is a glob-style pattern which should match at least # one code sample in `code_execute_result` # `supported_history_operations` is a list of the `hist_access_type` options # which should be tested; possible values are "tail", "range" and "search" code_history_pattern = "1?2*" supported_history_operations = ("tail", "search") # test the support for object inspection # the sample should be a name about which the kernel can give some help # information (a built-in function is probably a good choice) # only the default inspection level (equivalent to ipython "obj?") # is currently tested code_inspect_sample = "zip" # a code sample which should cause a `clear_output` message to be sent to # the client code_clear_output = "from IPython.display import clear_output; clear_output()" if __name__ == "__main__": unittest.main() jupyter_kernel_test-0.4.5/test_irkernel.py000066400000000000000000000023731430070550200210460ustar00rootroot00000000000000""" A non-python example, with tests for IRKernel (irkernel.github.io). (Beware of python quoting/string escaping rules being different to the language being tested) """ import os import unittest from jupyter_client.kernelspec import NoSuchKernel import jupyter_kernel_test as jkt class IRKernelTests(jkt.KernelTests): kernel_name = "ir" @classmethod def setUpClass(cls): try: cls.km, cls.kc = jkt.start_new_kernel(kernel_name=cls.kernel_name) except NoSuchKernel: raise unittest.SkipTest("No ir kernel installed") language_name = "R" file_extension = ".r" code_hello_world = 'print("hello, world")' completion_samples = ( [ { "text": "zi", "matches": {"zip"}, }, ] if os.name != "nt" else [] ) # zip is not available on Windows complete_code_samples = ["1", "print('hello, world')", "f <- function(x) {x*2}"] incomplete_code_samples = ["print('hello", "f <- function(x) {x"] code_generate_error = "raise" code_display_data = [ {"code": "plot(iris)", "mime": "image/png"}, {"code": "1+2+3", "mime": "text/plain"}, ] if __name__ == "__main__": unittest.main() jupyter_kernel_test-0.4.5/test_xeus_cling.py000066400000000000000000000022001430070550200213600ustar00rootroot00000000000000""" A non-python example, with tests for xeus-cling kernel (https://github.com/jupyter-xeus/xeus-cling). (Beware of python quoting/string escaping rules being different to the language being tested) """ import unittest from jupyter_client.kernelspec import NoSuchKernel import jupyter_kernel_test as jkt class XeusClingKernelTests(jkt.KernelTests): kernel_name = "xcpp17" @classmethod def setUpClass(cls): try: cls.km, cls.kc = jkt.start_new_kernel(kernel_name=cls.kernel_name) except NoSuchKernel: raise unittest.SkipTest("Xeus-Cling Kernel not installed") language_name = "c++" file_extension = ".cpp" code_hello_world = '#include \nstd::cout << "hello, world!" << std::endl;' code_stderr = '#include \nstd::cerr << "some error" << std::endl;' complete_code_samples = ["1", "int j=5"] incomplete_code_samples = ["double sqr(double a"] code_generate_error = 'throw std::runtime_error("Unknown exception");' code_execute_result = [ {"code": "int j = 5;j", "result": "5"}, ] if __name__ == "__main__": unittest.main()