mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-12 11:45:38 +08:00
Replace Travis and Appveyor with Github Actions
This commit is contained in:
parent
358714829a
commit
364ac5257d
52
.github/workflows/docs.yml
vendored
Normal file
52
.github/workflows/docs.yml
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
name: Docs Tests
|
||||
on:
|
||||
push:
|
||||
branches: '*'
|
||||
pull_request:
|
||||
branches: '*'
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu]
|
||||
python-version: [ '3.6' ]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
- name: Install Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
architecture: 'x64'
|
||||
- name: Upgrade packaging dependencies
|
||||
run: |
|
||||
pip install --upgrade pip setuptools wheel
|
||||
- name: Get pip cache dir
|
||||
id: pip-cache
|
||||
run: |
|
||||
echo "::set-output name=dir::$(pip cache dir)"
|
||||
- name: Cache pip
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ${{ steps.pip-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pip-${{ matrix.python-version }}-
|
||||
${{ runner.os }}-pip-
|
||||
- name: Install the Python dependencies
|
||||
run: |
|
||||
pip install -e .[test] codecov
|
||||
pip install -r docs/doc-requirements.txt
|
||||
wget https://github.com/jgm/pandoc/releases/download/1.19.1/pandoc-1.19.1-1-amd64.deb && sudo dpkg -i pandoc-1.19.1-1-amd64.deb
|
||||
- name: List installed packages
|
||||
run: |
|
||||
pip freeze
|
||||
pip check
|
||||
- name: Run tests on documentation
|
||||
run: |
|
||||
EXIT_STATUS=0
|
||||
make -C docs/ html || EXIT_STATUS=$?
|
||||
pytest --nbval --current-env docs || EXIT_STATUS=$?
|
||||
exit $EXIT_STATUS
|
61
.github/workflows/js.yml
vendored
Normal file
61
.github/workflows/js.yml
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
name: Linux JS Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: '*'
|
||||
pull_request:
|
||||
branches: '*'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu, macos]
|
||||
group: [notebook, base, services]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: 3.8
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: '12.x'
|
||||
|
||||
- name: Cache node modules
|
||||
uses: actions/cache@v2
|
||||
env:
|
||||
cache-name: cache-node-modules
|
||||
with:
|
||||
# npm cache files are stored in `~/.npm` on Linux/macOS
|
||||
path: ~/.npm
|
||||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-build-${{ env.cache-name }}-
|
||||
${{ runner.os }}-build-
|
||||
${{ runner.os }}-
|
||||
|
||||
- name: Cache pip on Linux
|
||||
uses: actions/cache@v1
|
||||
if: startsWith(runner.os, 'Linux')
|
||||
with:
|
||||
path: ~/.cache/pip
|
||||
key: ${{ runner.os }}-pip-${{ matrix.python }}-${{ hashFiles('**/requirements.txt', 'setup.py') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pip-${{ matrix.python }}
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
pip install --upgrade pip
|
||||
pip install --upgrade setuptools wheel
|
||||
npm install
|
||||
npm install -g casperjs@1.1.3 phantomjs-prebuilt@2.1.7
|
||||
pip install .[test]
|
||||
|
||||
- name: Run Tests
|
||||
run: |
|
||||
python -m notebook.jstest ${{ matrix.group }}
|
53
.github/workflows/python-nbconvert.yml
vendored
Normal file
53
.github/workflows/python-nbconvert.yml
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
# The NBConvert Service requires pandoc. Instead of testing
|
||||
# Pandoc on every operating system (which should already be
|
||||
# done in nbconvert directly), we'll only test these services
|
||||
# on ubuntu where we can easily load Pandoc from a Github
|
||||
# Actions docker image (this docker image is not on other
|
||||
# operating systems).
|
||||
name: NBConvert Service Tests
|
||||
on:
|
||||
push:
|
||||
branches: '*'
|
||||
pull_request:
|
||||
branches: '*'
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
python-version: [ '3.6' , '3.7', '3.8', '3.9' ]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
- name: Install Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
architecture: 'x64'
|
||||
- name: Setup Pandoc
|
||||
uses: r-lib/actions/setup-pandoc@v1
|
||||
- name: Upgrade packaging dependencies
|
||||
run: |
|
||||
pip install --upgrade pip setuptools wheel
|
||||
- name: Get pip cache dir
|
||||
id: pip-cache
|
||||
run: |
|
||||
echo "::set-output name=dir::$(pip cache dir)"
|
||||
- name: Cache pip
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ${{ steps.pip-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pip-${{ matrix.python-version }}-
|
||||
${{ runner.os }}-pip-
|
||||
- name: Install the Python dependencies
|
||||
run: |
|
||||
pip install -e .[test]
|
||||
- name: Run NBConvert Tests
|
||||
run: |
|
||||
pytest notebook/nbconvert/tests/
|
||||
- name: Run NBConvert Service Tests
|
||||
run: |
|
||||
pytest notebook/services/nbconvert/tests/
|
53
.github/workflows/python.yml
vendored
Normal file
53
.github/workflows/python.yml
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
name: Python Tests
|
||||
on:
|
||||
push:
|
||||
branches: '*'
|
||||
pull_request:
|
||||
branches: '*'
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu, macos, windows]
|
||||
python-version: [ '3.6' , '3.7', '3.8', '3.9' ] # Windows 3.9 fails due to the pywinpty dependency not working
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v1
|
||||
- name: Install Python ${{ matrix.python-version }}
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
architecture: 'x64'
|
||||
- name: Upgrade packaging dependencies
|
||||
run: |
|
||||
pip install --upgrade pip setuptools wheel --user
|
||||
- name: Get pip cache dir
|
||||
id: pip-cache
|
||||
run: |
|
||||
echo "::set-output name=dir::$(pip cache dir)"
|
||||
- name: Cache pip
|
||||
uses: actions/cache@v1
|
||||
with:
|
||||
path: ${{ steps.pip-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('setup.py') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pip-${{ matrix.python-version }}-
|
||||
${{ runner.os }}-pip-
|
||||
- name: Install the Python dependencies
|
||||
run: |
|
||||
pip install -e .[test] codecov
|
||||
- name: List installed packages
|
||||
run: |
|
||||
pip freeze
|
||||
pip check
|
||||
- name: Run Server-side tests
|
||||
run: |
|
||||
pytest -vv --cov notebook --cov-branch --cov-report term-missing:skip-covered --ignore-glob=notebook/tests/selenium/* --ignore-glob=notebook/nbconvert/tests/* --ignore-glob=notebook/services/nbconvert/tests/*
|
||||
- name: Run Integration Tests
|
||||
run: |
|
||||
pytest -v notebook/tests/test_notebookapp_integration.py --integration_tests
|
||||
- name: Coverage
|
||||
run: |
|
||||
codecov
|
46
.github/workflows/selenium.yml
vendored
Normal file
46
.github/workflows/selenium.yml
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
name: Selenium Tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: '*'
|
||||
pull_request:
|
||||
branches: '*'
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu, macos]
|
||||
python-version: [ '3.6', '3.7', '3.8', '3.9' ]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
architecture: 'x64'
|
||||
|
||||
- name: Set up Node
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: '12.x'
|
||||
|
||||
- name: Install JS
|
||||
run: |
|
||||
npm install
|
||||
|
||||
- name: Install Python dependencies
|
||||
run: |
|
||||
python -m pip install -U pip setuptools wheel
|
||||
pip install --upgrade selenium
|
||||
pip install pytest
|
||||
pip install .[test]
|
||||
|
||||
- name: Run Tests
|
||||
run: |
|
||||
export JUPYTER_TEST_BROWSER=firefox
|
||||
export MOZ_HEADLESS=1
|
||||
pytest -sv notebook/tests/selenium
|
106
.travis.yml
106
.travis.yml
@ -1,106 +0,0 @@
|
||||
# http://travis-ci.org/#!/ipython/ipython
|
||||
language: python
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.cache/bower
|
||||
- $HOME/.cache/pip
|
||||
python:
|
||||
- 3.6
|
||||
|
||||
env:
|
||||
global:
|
||||
- PATH=$TRAVIS_BUILD_DIR/pandoc:$PATH
|
||||
matrix:
|
||||
- GROUP=js/notebook
|
||||
- GROUP=python
|
||||
- GROUP=js/base
|
||||
- GROUP=js/services
|
||||
|
||||
before_install:
|
||||
- pip install --upgrade pip
|
||||
- pip install --upgrade setuptools wheel pytest pytest-cov coverage codecov
|
||||
- nvm install 6.9.2
|
||||
- nvm use 6.9.2
|
||||
- node --version
|
||||
- npm --version
|
||||
- npm install -g npm
|
||||
- npm install
|
||||
- |
|
||||
if [[ $GROUP == js* ]]; then
|
||||
npm install -g casperjs@1.1.3 phantomjs-prebuilt@2.1.7
|
||||
fi
|
||||
- |
|
||||
if [[ $GROUP == docs ]]; then
|
||||
pip install -r docs/doc-requirements.txt
|
||||
pip install --upgrade pytest
|
||||
fi
|
||||
- |
|
||||
if [[ $GROUP == selenium ]]; then
|
||||
pip install --upgrade selenium pytest
|
||||
# Install Webdriver backend for Firefox:
|
||||
wget https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-linux64.tar.gz
|
||||
mkdir geckodriver
|
||||
tar -xzf geckodriver-v0.19.1-linux64.tar.gz -C geckodriver
|
||||
export PATH=$PATH:$PWD/geckodriver
|
||||
fi
|
||||
- pip install "attrs>=17.4.0"
|
||||
|
||||
install:
|
||||
- pip install --pre .[test] $EXTRA_PIP
|
||||
- pip freeze
|
||||
- wget https://github.com/jgm/pandoc/releases/download/1.19.1/pandoc-1.19.1-1-amd64.deb && sudo dpkg -i pandoc-1.19.1-1-amd64.deb
|
||||
|
||||
|
||||
script:
|
||||
- jupyter kernelspec list
|
||||
- |
|
||||
symlinks=$(find . -type l| grep -v './node_modules/' | grep -v './git-hooks')
|
||||
if [[ $(echo $symlinks) ]]; then
|
||||
echo "Repository contains symlinks which won't work on windows:"
|
||||
echo $symlinks
|
||||
echo ""
|
||||
false
|
||||
else
|
||||
true
|
||||
fi
|
||||
- 'if [[ $GROUP == js* ]]; then travis_retry python -m notebook.jstest ${GROUP:3}; fi'
|
||||
- 'if [[ $GROUP == python ]]; then py.test -v --ignore notebook/tests/selenium --cov=notebook notebook; fi'
|
||||
- 'if [[ $GROUP == selenium ]]; then py.test -sv notebook/tests/selenium; fi'
|
||||
- |
|
||||
if [[ $GROUP == docs ]]; then
|
||||
EXIT_STATUS=0
|
||||
make -C docs/ html || EXIT_STATUS=$?
|
||||
|
||||
if [[ $TRAVIS_EVENT_TYPE == cron ]]; then
|
||||
make -C docs/ linkcheck || EXIT_STATUS=$?;
|
||||
fi
|
||||
|
||||
pytest --nbval --current-env docs || EXIT_STATUS=$?
|
||||
exit $EXIT_STATUS
|
||||
fi
|
||||
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- python: 3.6
|
||||
env:
|
||||
- GROUP=selenium
|
||||
- JUPYTER_TEST_BROWSER=firefox
|
||||
- MOZ_HEADLESS=1
|
||||
addons:
|
||||
firefox: 57.0
|
||||
- python: 3.5
|
||||
env: GROUP=python
|
||||
- python: 3.7
|
||||
dist: xenial
|
||||
env: GROUP=python
|
||||
- python: 3.8
|
||||
env: GROUP=python
|
||||
- python: 3.9-dev
|
||||
env: GROUP=python
|
||||
- python: 3.6
|
||||
env: GROUP=docs
|
||||
|
||||
after_success:
|
||||
- codecov
|
32
appveyor.yml
32
appveyor.yml
@ -1,32 +0,0 @@
|
||||
# miniconda bootstrap from conda-forge recipe
|
||||
matrix:
|
||||
fast_finish: true
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- CONDA_PY: 36
|
||||
CONDA_PY_SPEC: 3.6
|
||||
CONDA_INSTALL_LOCN: "C:\\Miniconda36-x64"
|
||||
- CONDA_PY: 38
|
||||
CONDA_PY_SPEC: 3.8
|
||||
CONDA_INSTALL_LOCN: "C:\\Miniconda37-x64"
|
||||
|
||||
platform:
|
||||
- x64
|
||||
|
||||
build: off
|
||||
|
||||
install:
|
||||
- cmd: call %CONDA_INSTALL_LOCN%\Scripts\activate.bat
|
||||
- cmd: conda config --set show_channel_urls true
|
||||
- cmd: conda config --add channels conda-forge
|
||||
#- cmd: conda update --yes --quiet conda
|
||||
- cmd: conda install -y python=%CONDA_PY_SPEC% pyzmq tornado jupyter_client nbformat ipykernel pip nodejs pytest nose
|
||||
# not using `conda install -y` on nbconvent package because there is
|
||||
# currently a bug with the version that the anaconda installs, so we will just install it with pip
|
||||
- cmd: pip install nbconvert
|
||||
- cmd: python setup.py build
|
||||
- cmd: pip install .[test]
|
||||
|
||||
test_script:
|
||||
- py.test -v notebook --ignore notebook\tests\selenium
|
@ -5,7 +5,7 @@ from os.path import join as pjoin
|
||||
import shutil
|
||||
|
||||
import requests
|
||||
|
||||
import pytest
|
||||
from notebook.utils import url_path_join
|
||||
from notebook.tests.launchnotebook import NotebookTestBase, assert_http_error
|
||||
from nbformat import write
|
||||
@ -18,6 +18,13 @@ from ipython_genutils.testing.decorators import onlyif_cmds_exist
|
||||
from base64 import encodebytes
|
||||
|
||||
|
||||
def cmd_exists(cmd):
|
||||
"""Check is a command exists."""
|
||||
if shutil.which(cmd) is None:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
class NbconvertAPI(object):
|
||||
"""Wrapper for nbconvert API calls."""
|
||||
def __init__(self, request):
|
||||
@ -50,7 +57,7 @@ b'\x08\xd7c\x90\xfb\xcf\x00\x00\x02\\\x01\x1e.~d\x87\x00\x00\x00\x00IEND\xaeB`\x
|
||||
class APITest(NotebookTestBase):
|
||||
def setUp(self):
|
||||
nbdir = self.notebook_dir
|
||||
|
||||
|
||||
if not os.path.isdir(pjoin(nbdir, 'foo')):
|
||||
subdir = pjoin(nbdir, 'foo')
|
||||
|
||||
@ -64,7 +71,7 @@ class APITest(NotebookTestBase):
|
||||
shutil.rmtree(subdir, ignore_errors=True)
|
||||
|
||||
nb = new_notebook()
|
||||
|
||||
|
||||
nb.cells.append(new_markdown_cell(u'Created by test ³'))
|
||||
cc1 = new_code_cell(source=u'print(2*6)')
|
||||
cc1.outputs.append(new_output(output_type="stream", text=u'12'))
|
||||
@ -73,14 +80,17 @@ class APITest(NotebookTestBase):
|
||||
execution_count=1,
|
||||
))
|
||||
nb.cells.append(cc1)
|
||||
|
||||
|
||||
with io.open(pjoin(nbdir, 'foo', 'testnb.ipynb'), 'w',
|
||||
encoding='utf-8') as f:
|
||||
write(nb, f, version=4)
|
||||
|
||||
self.nbconvert_api = NbconvertAPI(self.request)
|
||||
|
||||
@onlyif_cmds_exist('pandoc')
|
||||
@pytest.mark.skipif(
|
||||
not cmd_exists('pandoc'),
|
||||
reason="Pandoc wasn't found. Skipping this test."
|
||||
)
|
||||
def test_from_file(self):
|
||||
r = self.nbconvert_api.from_file('html', 'foo', 'testnb.ipynb')
|
||||
self.assertEqual(r.status_code, 200)
|
||||
@ -92,39 +102,54 @@ class APITest(NotebookTestBase):
|
||||
self.assertIn(u'text/x-python', r.headers['Content-Type'])
|
||||
self.assertIn(u'print(2*6)', r.text)
|
||||
|
||||
@onlyif_cmds_exist('pandoc')
|
||||
@pytest.mark.skipif(
|
||||
not cmd_exists('pandoc'),
|
||||
reason="Pandoc wasn't found. Skipping this test."
|
||||
)
|
||||
def test_from_file_404(self):
|
||||
with assert_http_error(404):
|
||||
self.nbconvert_api.from_file('html', 'foo', 'thisdoesntexist.ipynb')
|
||||
|
||||
@onlyif_cmds_exist('pandoc')
|
||||
@pytest.mark.skipif(
|
||||
not cmd_exists('pandoc'),
|
||||
reason="Pandoc wasn't found. Skipping this test."
|
||||
)
|
||||
def test_from_file_download(self):
|
||||
r = self.nbconvert_api.from_file('python', 'foo', 'testnb.ipynb', download=True)
|
||||
content_disposition = r.headers['Content-Disposition']
|
||||
self.assertIn('attachment', content_disposition)
|
||||
self.assertIn('testnb.py', content_disposition)
|
||||
|
||||
@onlyif_cmds_exist('pandoc')
|
||||
@pytest.mark.skipif(
|
||||
not cmd_exists('pandoc'),
|
||||
reason="Pandoc wasn't found. Skipping this test."
|
||||
)
|
||||
def test_from_file_zip(self):
|
||||
r = self.nbconvert_api.from_file('latex', 'foo', 'testnb.ipynb', download=True)
|
||||
self.assertIn(u'application/zip', r.headers['Content-Type'])
|
||||
self.assertIn(u'.zip', r.headers['Content-Disposition'])
|
||||
|
||||
@onlyif_cmds_exist('pandoc')
|
||||
@pytest.mark.skipif(
|
||||
not cmd_exists('pandoc'),
|
||||
reason="Pandoc wasn't found. Skipping this test."
|
||||
)
|
||||
def test_from_post(self):
|
||||
nbmodel = self.request('GET', 'api/contents/foo/testnb.ipynb').json()
|
||||
|
||||
|
||||
r = self.nbconvert_api.from_post(format='html', nbmodel=nbmodel)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertIn(u'text/html', r.headers['Content-Type'])
|
||||
self.assertIn(u'Created by test', r.text)
|
||||
self.assertIn(u'print', r.text)
|
||||
|
||||
|
||||
r = self.nbconvert_api.from_post(format='python', nbmodel=nbmodel)
|
||||
self.assertIn(u'text/x-python', r.headers['Content-Type'])
|
||||
self.assertIn(u'print(2*6)', r.text)
|
||||
|
||||
@onlyif_cmds_exist('pandoc')
|
||||
@pytest.mark.skipif(
|
||||
not cmd_exists('pandoc'),
|
||||
reason="Pandoc wasn't found. Skipping this test."
|
||||
)
|
||||
def test_from_post_zip(self):
|
||||
nbmodel = self.request('GET', 'api/contents/foo/testnb.ipynb').json()
|
||||
|
||||
|
9
notebook/tests/conftest.py
Normal file
9
notebook/tests/conftest.py
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
parser.addoption('--integration_tests', action='store_true', dest="integration_tests",
|
||||
default=False, help="enable integration tests")
|
||||
|
||||
def pytest_configure(config):
|
||||
if not config.option.integration_tests:
|
||||
setattr(config.option, 'markexpr', 'not integration_tests')
|
@ -16,7 +16,6 @@ from unittest import TestCase
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
import ipython_genutils.testing.decorators as dec
|
||||
from ipython_genutils import py3compat
|
||||
from ipython_genutils.tempdir import TemporaryDirectory
|
||||
from notebook import nbextensions
|
||||
@ -32,7 +31,7 @@ from notebook.config_manager import BaseJSONConfigManager
|
||||
|
||||
def touch(file_name, mtime=None):
|
||||
"""ensure a file exists, and set its modification time
|
||||
|
||||
|
||||
returns the modification time of the file
|
||||
"""
|
||||
open(file_name, 'a').close()
|
||||
@ -52,7 +51,7 @@ def test_help_output():
|
||||
|
||||
|
||||
class TestInstallNBExtension(TestCase):
|
||||
|
||||
|
||||
def tempdir(self):
|
||||
td = TemporaryDirectory()
|
||||
self.tempdirs.append(td)
|
||||
@ -109,11 +108,11 @@ class TestInstallNBExtension(TestCase):
|
||||
if not os.path.exists(path):
|
||||
do_exist = os.listdir(os.path.dirname(path))
|
||||
self.fail(u"%s should exist (found %s)" % (path, do_exist))
|
||||
|
||||
|
||||
def assert_not_dir_exists(self, path):
|
||||
if os.path.exists(path):
|
||||
self.fail(u"%s should not exist" % path)
|
||||
|
||||
|
||||
def assert_installed(self, relative_path, user=False):
|
||||
if user:
|
||||
nbext = pjoin(self.data_dir, u'nbextensions')
|
||||
@ -122,7 +121,7 @@ class TestInstallNBExtension(TestCase):
|
||||
self.assert_dir_exists(
|
||||
pjoin(nbext, relative_path)
|
||||
)
|
||||
|
||||
|
||||
def assert_not_installed(self, relative_path, user=False):
|
||||
if user:
|
||||
nbext = pjoin(self.data_dir, u'nbextensions')
|
||||
@ -131,7 +130,7 @@ class TestInstallNBExtension(TestCase):
|
||||
self.assert_not_dir_exists(
|
||||
pjoin(nbext, relative_path)
|
||||
)
|
||||
|
||||
|
||||
def test_create_data_dir(self):
|
||||
"""install_nbextension when data_dir doesn't exist"""
|
||||
with TemporaryDirectory() as td:
|
||||
@ -146,7 +145,7 @@ class TestInstallNBExtension(TestCase):
|
||||
pjoin(basename(self.src), file_name),
|
||||
user=True,
|
||||
)
|
||||
|
||||
|
||||
def test_create_nbextensions_user(self):
|
||||
with TemporaryDirectory() as td:
|
||||
install_nbextension(self.src, user=True)
|
||||
@ -154,7 +153,7 @@ class TestInstallNBExtension(TestCase):
|
||||
pjoin(basename(self.src), u'ƒile'),
|
||||
user=True
|
||||
)
|
||||
|
||||
|
||||
def test_create_nbextensions_system(self):
|
||||
with TemporaryDirectory() as td:
|
||||
self.system_nbext = pjoin(td, u'nbextensions')
|
||||
@ -164,17 +163,17 @@ class TestInstallNBExtension(TestCase):
|
||||
pjoin(basename(self.src), u'ƒile'),
|
||||
user=False
|
||||
)
|
||||
|
||||
|
||||
def test_single_file(self):
|
||||
file_name = self.files[0]
|
||||
install_nbextension(pjoin(self.src, file_name))
|
||||
self.assert_installed(file_name)
|
||||
|
||||
|
||||
def test_single_dir(self):
|
||||
d = u'∂ir'
|
||||
install_nbextension(pjoin(self.src, d))
|
||||
self.assert_installed(self.files[-1])
|
||||
|
||||
|
||||
def test_single_dir_trailing_slash(self):
|
||||
d = u'∂ir/'
|
||||
install_nbextension(pjoin(self.src, d))
|
||||
@ -193,11 +192,11 @@ class TestInstallNBExtension(TestCase):
|
||||
d = u'∂ir'
|
||||
install_nbextension(pjoin(self.src, d), destination = u'ƒiledest2')
|
||||
self.assert_installed(pjoin(u'ƒiledest2', u'∂ir2', u'ƒile2'))
|
||||
|
||||
|
||||
def test_install_nbextension(self):
|
||||
with self.assertRaises(TypeError):
|
||||
install_nbextension(glob.glob(pjoin(self.src, '*')))
|
||||
|
||||
|
||||
def test_overwrite_file(self):
|
||||
with TemporaryDirectory() as d:
|
||||
fname = u'ƒ.js'
|
||||
@ -213,7 +212,7 @@ class TestInstallNBExtension(TestCase):
|
||||
install_nbextension(src, overwrite=True)
|
||||
with open(dest) as f:
|
||||
self.assertEqual(f.read(), 'overwrite')
|
||||
|
||||
|
||||
def test_overwrite_dir(self):
|
||||
with TemporaryDirectory() as src:
|
||||
base = basename(src)
|
||||
@ -227,7 +226,7 @@ class TestInstallNBExtension(TestCase):
|
||||
install_nbextension(src, overwrite=True)
|
||||
self.assert_installed(pjoin(base, fname2))
|
||||
self.assert_not_installed(pjoin(base, fname))
|
||||
|
||||
|
||||
def test_update_file(self):
|
||||
with TemporaryDirectory() as d:
|
||||
fname = u'ƒ.js'
|
||||
@ -245,7 +244,7 @@ class TestInstallNBExtension(TestCase):
|
||||
install_nbextension(src)
|
||||
with open(dest) as f:
|
||||
self.assertEqual(f.read(), 'overwrite')
|
||||
|
||||
|
||||
def test_skip_old_file(self):
|
||||
with TemporaryDirectory() as d:
|
||||
fname = u'ƒ.js'
|
||||
@ -255,7 +254,7 @@ class TestInstallNBExtension(TestCase):
|
||||
self.assert_installed(fname)
|
||||
dest = pjoin(self.system_nbext, fname)
|
||||
old_mtime = os.stat(dest).st_mtime
|
||||
|
||||
|
||||
mtime = touch(src, mtime - 100)
|
||||
install_nbextension(src)
|
||||
new_mtime = os.stat(dest).st_mtime
|
||||
@ -269,7 +268,7 @@ class TestInstallNBExtension(TestCase):
|
||||
install_nbextension(self.src)
|
||||
self.assertEqual(stdout.getvalue(), '')
|
||||
self.assertEqual(stderr.getvalue(), '')
|
||||
|
||||
|
||||
def test_install_zip(self):
|
||||
path = pjoin(self.src, "myjsext.zip")
|
||||
with zipfile.ZipFile(path, 'w') as f:
|
||||
@ -278,13 +277,13 @@ class TestInstallNBExtension(TestCase):
|
||||
install_nbextension(path)
|
||||
self.assert_installed("a.js")
|
||||
self.assert_installed(pjoin("foo", "a.js"))
|
||||
|
||||
|
||||
def test_install_tar(self):
|
||||
def _add_file(f, fname, buf):
|
||||
info = tarfile.TarInfo(fname)
|
||||
info.size = len(buf)
|
||||
f.addfile(info, BytesIO(buf))
|
||||
|
||||
|
||||
for i,ext in enumerate((".tar.gz", ".tgz", ".tar.bz2")):
|
||||
path = pjoin(self.src, "myjsext" + ext)
|
||||
with tarfile.open(path, 'w') as f:
|
||||
@ -293,7 +292,7 @@ class TestInstallNBExtension(TestCase):
|
||||
install_nbextension(path)
|
||||
self.assert_installed("b%i.js" % i)
|
||||
self.assert_installed(pjoin("foo", "b%i.js" % i))
|
||||
|
||||
|
||||
def test_install_url(self):
|
||||
def fake_urlretrieve(url, dest):
|
||||
touch(dest)
|
||||
@ -304,23 +303,23 @@ class TestInstallNBExtension(TestCase):
|
||||
self.assert_installed("foo.js")
|
||||
install_nbextension("https://example.com/path/to/another/bar.js")
|
||||
self.assert_installed("bar.js")
|
||||
install_nbextension("https://example.com/path/to/another/bar.js",
|
||||
install_nbextension("https://example.com/path/to/another/bar.js",
|
||||
destination = 'foobar.js')
|
||||
self.assert_installed("foobar.js")
|
||||
finally:
|
||||
nbextensions.urlretrieve = save_urlretrieve
|
||||
|
||||
|
||||
def test_check_nbextension(self):
|
||||
with TemporaryDirectory() as d:
|
||||
f = u'ƒ.js'
|
||||
src = pjoin(d, f)
|
||||
touch(src)
|
||||
install_nbextension(src, user=True)
|
||||
|
||||
|
||||
assert check_nbextension(f, user=True)
|
||||
assert check_nbextension([f], user=True)
|
||||
assert not check_nbextension([f, pjoin('dne', f)], user=True)
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.platform == "win32", reason="do not run on windows")
|
||||
def test_install_symlink(self):
|
||||
with TemporaryDirectory() as d:
|
||||
@ -332,7 +331,7 @@ class TestInstallNBExtension(TestCase):
|
||||
assert os.path.islink(dest)
|
||||
link = os.readlink(dest)
|
||||
self.assertEqual(link, src)
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.platform == "win32", reason="do not run on windows")
|
||||
def test_overwrite_broken_symlink(self):
|
||||
with TemporaryDirectory() as d:
|
||||
@ -393,21 +392,21 @@ class TestInstallNBExtension(TestCase):
|
||||
touch(src)
|
||||
install_nbextension(src, user=True)
|
||||
enable_nbextension(section='notebook', require=u'ƒ')
|
||||
|
||||
|
||||
config_dir = os.path.join(_get_config_dir(user=True), 'nbconfig')
|
||||
cm = BaseJSONConfigManager(config_dir=config_dir)
|
||||
enabled = cm.get('notebook').get('load_extensions', {}).get(u'ƒ', False)
|
||||
assert enabled
|
||||
|
||||
|
||||
def test_nbextension_disable(self):
|
||||
self.test_nbextension_enable()
|
||||
disable_nbextension(section='notebook', require=u'ƒ')
|
||||
|
||||
|
||||
config_dir = os.path.join(_get_config_dir(user=True), 'nbconfig')
|
||||
cm = BaseJSONConfigManager(config_dir=config_dir)
|
||||
enabled = cm.get('notebook').get('load_extensions', {}).get(u'ƒ', False)
|
||||
assert not enabled
|
||||
|
||||
|
||||
|
||||
def _mock_extension_spec_meta(self, section='notebook'):
|
||||
return {
|
||||
@ -424,52 +423,52 @@ class TestInstallNBExtension(TestCase):
|
||||
|
||||
class mock():
|
||||
__file__ = outer_file
|
||||
|
||||
|
||||
@staticmethod
|
||||
def _jupyter_nbextension_paths():
|
||||
return [meta]
|
||||
|
||||
|
||||
import sys
|
||||
sys.modules['mockextension'] = mock
|
||||
|
||||
|
||||
def test_nbextensionpy_files(self):
|
||||
self._inject_mock_extension()
|
||||
install_nbextension_python('mockextension')
|
||||
|
||||
|
||||
assert check_nbextension('_mockdestination/index.js')
|
||||
assert check_nbextension(['_mockdestination/index.js'])
|
||||
|
||||
|
||||
def test_nbextensionpy_user_files(self):
|
||||
self._inject_mock_extension()
|
||||
install_nbextension_python('mockextension', user=True)
|
||||
|
||||
|
||||
assert check_nbextension('_mockdestination/index.js', user=True)
|
||||
assert check_nbextension(['_mockdestination/index.js'], user=True)
|
||||
|
||||
|
||||
def test_nbextensionpy_uninstall_files(self):
|
||||
self._inject_mock_extension()
|
||||
install_nbextension_python('mockextension', user=True)
|
||||
uninstall_nbextension_python('mockextension', user=True)
|
||||
|
||||
|
||||
assert not check_nbextension('_mockdestination/index.js')
|
||||
assert not check_nbextension(['_mockdestination/index.js'])
|
||||
|
||||
|
||||
def test_nbextensionpy_enable(self):
|
||||
self._inject_mock_extension('notebook')
|
||||
install_nbextension_python('mockextension', user=True)
|
||||
enable_nbextension_python('mockextension')
|
||||
|
||||
|
||||
config_dir = os.path.join(_get_config_dir(user=True), 'nbconfig')
|
||||
cm = BaseJSONConfigManager(config_dir=config_dir)
|
||||
enabled = cm.get('notebook').get('load_extensions', {}).get('_mockdestination/index', False)
|
||||
assert enabled
|
||||
|
||||
|
||||
def test_nbextensionpy_disable(self):
|
||||
self._inject_mock_extension('notebook')
|
||||
install_nbextension_python('mockextension', user=True)
|
||||
enable_nbextension_python('mockextension')
|
||||
disable_nbextension_python('mockextension', user=True)
|
||||
|
||||
|
||||
config_dir = os.path.join(_get_config_dir(user=True), 'nbconfig')
|
||||
cm = BaseJSONConfigManager(config_dir=config_dir)
|
||||
enabled = cm.get('notebook').get('load_extensions', {}).get('_mockdestination/index', False)
|
||||
|
@ -4,6 +4,7 @@ import stat
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import pytest
|
||||
|
||||
from notebook import DEFAULT_NOTEBOOK_PORT
|
||||
|
||||
@ -11,6 +12,9 @@ from .launchnotebook import UNIXSocketNotebookTestBase
|
||||
from ..utils import urlencode_unix_socket, urlencode_unix_socket_path
|
||||
|
||||
|
||||
pytestmark = pytest.mark.integration_tests
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.platform == "win32", reason="do not run on windows")
|
||||
def test_shutdown_sock_server_integration():
|
||||
sock = UNIXSocketNotebookTestBase.sock
|
||||
|
@ -13,7 +13,6 @@ from traitlets.tests.utils import check_help_all_output
|
||||
from notebook.utils import url_escape, url_unescape, is_hidden, is_file_hidden
|
||||
from ipython_genutils.py3compat import cast_unicode
|
||||
from ipython_genutils.tempdir import TemporaryDirectory
|
||||
from ipython_genutils.testing.decorators import skip_if_not_win32
|
||||
|
||||
|
||||
def test_help_output():
|
||||
@ -34,7 +33,7 @@ def test_url_escape():
|
||||
|
||||
path = url_escape('/path with a/notebook and space.ipynb')
|
||||
assert path == '/path%20with%20a/notebook%20and%20space.ipynb'
|
||||
|
||||
|
||||
path = url_escape('/ !@$#%^&* / test %^ notebook @#$ name.ipynb')
|
||||
assert path == '/%20%21%40%24%23%25%5E%26%2A%20/%20test%20%25%5E%20notebook%20%40%23%24%20name.ipynb'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user