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

do not require nose for testing #5826

Merged
merged 6 commits into from
Oct 29, 2020
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ env:

before_install:
- pip install --upgrade pip
- pip install --upgrade setuptools wheel nose coverage codecov
- pip install --upgrade setuptools wheel pytest pytest-cov coverage codecov
- nvm install 6.9.2
- nvm use 6.9.2
- node --version
Expand Down Expand Up @@ -65,7 +65,7 @@ script:
true
fi
- 'if [[ $GROUP == js* ]]; then travis_retry python -m notebook.jstest ${GROUP:3}; fi'
- 'if [[ $GROUP == python ]]; then nosetests -v --exclude-dir notebook/tests/selenium --with-coverage --cover-package=notebook notebook; 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
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ install:
- 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 nose
- 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:
- nosetests -v notebook --exclude-dir notebook\tests\selenium
- py.test -v notebook --ignore notebook\tests\selenium
13 changes: 6 additions & 7 deletions notebook/auth/tests/test_security.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
from ..security import passwd, passwd_check
import nose.tools as nt

def test_passwd_structure():
p = passwd('passphrase')
algorithm, hashed = p.split(':')
nt.assert_equal(algorithm, 'argon2')
nt.assert_true(hashed.startswith('$argon2id$'))
assert algorithm == 'argon2'
assert hashed.startswith('$argon2id$')

def test_roundtrip():
p = passwd('passphrase')
nt.assert_equal(passwd_check(p, 'passphrase'), True)
assert passwd_check(p, 'passphrase') == True

def test_bad():
p = passwd('passphrase')
nt.assert_equal(passwd_check(p, p), False)
nt.assert_equal(passwd_check(p, 'a:b:c:d'), False)
nt.assert_equal(passwd_check(p, 'a:b'), False)
assert passwd_check(p, p) == False
assert passwd_check(p, 'a:b:c:d') == False
assert passwd_check(p, 'a:b') == False

def test_passwd_check_unicode():
# GH issue #4524
Expand Down
78 changes: 40 additions & 38 deletions notebook/services/contents/tests/test_fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

import io as stdlib_io
import os.path
import unittest
import pytest
import stat
import sys

import nose.tools as nt

from ipython_genutils.testing.decorators import skip_win32
from ..fileio import atomic_writing

from ipython_genutils.tempdir import TemporaryDirectory
Expand Down Expand Up @@ -38,58 +38,60 @@ class CustomExc(Exception): pass
# OSError: The user lacks the privilege (Windows)
have_symlink = False

with nt.assert_raises(CustomExc):
with pytest.raises(CustomExc):
with atomic_writing(f1) as f:
f.write(u'Failing write')
raise CustomExc

# Because of the exception, the file should not have been modified
with stdlib_io.open(f1, 'r') as f:
nt.assert_equal(f.read(), u'Before')
assert f.read() == u'Before'

with atomic_writing(f1) as f:
f.write(u'Overwritten')

with stdlib_io.open(f1, 'r') as f:
nt.assert_equal(f.read(), u'Overwritten')
assert f.read() == u'Overwritten'

if os.name != 'nt':
mode = stat.S_IMODE(os.stat(f1).st_mode)
nt.assert_equal(mode, orig_mode)
assert mode == orig_mode

if have_symlink:
# Check that writing over a file preserves a symlink
with atomic_writing(f2) as f:
f.write(u'written from symlink')

with stdlib_io.open(f1, 'r') as f:
nt.assert_equal(f.read(), u'written from symlink')

def _save_umask():
global umask
umask = os.umask(0)
os.umask(umask)

def _restore_umask():
os.umask(umask)

@skip_win32
@nt.with_setup(_save_umask, _restore_umask)
def test_atomic_writing_umask():
with TemporaryDirectory() as td:
os.umask(0o022)
f1 = os.path.join(td, '1')
with atomic_writing(f1) as f:
f.write(u'1')
mode = stat.S_IMODE(os.stat(f1).st_mode)
nt.assert_equal(mode, 0o644, '{:o} != 644'.format(mode))

os.umask(0o057)
f2 = os.path.join(td, '2')
with atomic_writing(f2) as f:
f.write(u'2')
mode = stat.S_IMODE(os.stat(f2).st_mode)
nt.assert_equal(mode, 0o620, '{:o} != 620'.format(mode))
assert f.read() == u'written from symlink'

class TestWithSetUmask(unittest.TestCase):
def setUp(self):
# save umask
global umask
umask = os.umask(0)
os.umask(umask)

def tearDown(self):
# restore umask
os.umask(umask)

@pytest.mark.skipif(sys.platform == "win32", reason="do not run on windows")
def test_atomic_writing_umask(self):
with TemporaryDirectory() as td:
os.umask(0o022)
f1 = os.path.join(td, '1')
with atomic_writing(f1) as f:
f.write(u'1')
mode = stat.S_IMODE(os.stat(f1).st_mode)
assert mode == 0o644

os.umask(0o057)
f2 = os.path.join(td, '2')
with atomic_writing(f2) as f:
f.write(u'2')
mode = stat.S_IMODE(os.stat(f2).st_mode)
assert mode == 0o620


def test_atomic_writing_newlines():
Expand All @@ -105,26 +107,26 @@ def test_atomic_writing_newlines():
f.write(lf)
with stdlib_io.open(path, 'r', newline='') as f:
read = f.read()
nt.assert_equal(read, plat)
assert read == plat

# test newline=LF
with stdlib_io.open(path, 'w', newline='\n') as f:
f.write(lf)
with stdlib_io.open(path, 'r', newline='') as f:
read = f.read()
nt.assert_equal(read, lf)
assert read == lf

# test newline=CRLF
with atomic_writing(path, newline='\r\n') as f:
f.write(lf)
with stdlib_io.open(path, 'r', newline='') as f:
read = f.read()
nt.assert_equal(read, crlf)
assert read == crlf

# test newline=no convert
text = u'crlf\r\ncr\rlf\n'
with atomic_writing(path, newline='') as f:
f.write(text)
with stdlib_io.open(path, 'r', newline='') as f:
read = f.read()
nt.assert_equal(read, text)
assert read == text
15 changes: 5 additions & 10 deletions notebook/services/contents/tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
from contextlib import contextmanager
from itertools import combinations

from nose import SkipTest
from tornado.web import HTTPError
from unittest import TestCase
from unittest import TestCase, skipIf
from tempfile import NamedTemporaryFile

from nbformat import v4 as nbformat

from ipython_genutils.tempdir import TemporaryDirectory
from traitlets import TraitError
from ipython_genutils.testing import decorators as dec

from ..filemanager import FileContentsManager

Expand Down Expand Up @@ -126,7 +124,7 @@ def test_bad_symlink(self):
# broken symlinks should still be shown in the contents manager
self.assertTrue('bad symlink' in contents)

@dec.skipif(sys.platform == 'win32')
@skipIf(sys.platform == 'win32', "will not run on windows")
def test_recursive_symlink(self):
with TemporaryDirectory() as td:
cm = FileContentsManager(root_dir=td)
Expand Down Expand Up @@ -165,13 +163,10 @@ def test_good_symlink(self):
[symlink_model, file_model],
)

def test_403(self):
if hasattr(os, 'getuid'):
if os.getuid() == 0:
raise SkipTest("Can't test permissions as root")
if sys.platform.startswith('win'):
raise SkipTest("Can't test permissions on Windows")

@skipIf(hasattr(os, 'getuid') and os.getuid() == 0, "Can't test permissions as root")
@skipIf(sys.platform.startswith('win'), "Can't test permissions on Windows")
def test_403(self):
with TemporaryDirectory() as td:
cm = FileContentsManager(root_dir=td)
model = cm.new_untitled(type='file')
Expand Down
33 changes: 16 additions & 17 deletions notebook/tests/test_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from io import StringIO
from unittest.mock import patch

import nose.tools as nt
from tornado import gen
from tornado.web import HTTPError
from tornado.httpclient import HTTPRequest, HTTPResponse
Expand Down Expand Up @@ -72,7 +71,7 @@ def mock_gateway_request(url, **kwargs):
name = json_body.get('name')
env = json_body.get('env')
kspec_name = env.get('KERNEL_KSPEC_NAME')
nt.assert_equal(name, kspec_name) # Ensure that KERNEL_ env values get propagated
assert name == kspec_name # Ensure that KERNEL_ env values get propagated
model = generate_model(name)
running_kernels[model.get('id')] = model # Register model as a running kernel
response_buf = StringIO(json.dumps(model))
Expand Down Expand Up @@ -164,19 +163,19 @@ def setUp(self):
super().setUp()

def test_gateway_options(self):
nt.assert_equal(self.notebook.gateway_config.gateway_enabled, True)
nt.assert_equal(self.notebook.gateway_config.url, TestGateway.mock_gateway_url)
nt.assert_equal(self.notebook.gateway_config.http_user, TestGateway.mock_http_user)
nt.assert_equal(self.notebook.gateway_config.connect_timeout, self.notebook.gateway_config.connect_timeout)
nt.assert_equal(self.notebook.gateway_config.connect_timeout, 44.4)
nt.assert_equal(self.notebook.gateway_config.request_timeout, 96.0)
nt.assert_equal(os.environ['KERNEL_LAUNCH_TIMEOUT'], str(96)) # Ensure KLT gets set from request-timeout
assert self.notebook.gateway_config.gateway_enabled == True
assert self.notebook.gateway_config.url == TestGateway.mock_gateway_url
assert self.notebook.gateway_config.http_user == TestGateway.mock_http_user
assert self.notebook.gateway_config.connect_timeout == self.notebook.gateway_config.connect_timeout
assert self.notebook.gateway_config.connect_timeout == 44.4
assert self.notebook.gateway_config.request_timeout == 96.0
assert os.environ['KERNEL_LAUNCH_TIMEOUT'] == str(96) # Ensure KLT gets set from request-timeout

def test_gateway_class_mappings(self):
# Ensure appropriate class mappings are in place.
nt.assert_equal(self.notebook.kernel_manager_class.__name__, 'GatewayKernelManager')
nt.assert_equal(self.notebook.session_manager_class.__name__, 'GatewaySessionManager')
nt.assert_equal(self.notebook.kernel_spec_manager_class.__name__, 'GatewayKernelSpecManager')
assert self.notebook.kernel_manager_class.__name__ == 'GatewayKernelManager'
assert self.notebook.session_manager_class.__name__ == 'GatewaySessionManager'
assert self.notebook.kernel_spec_manager_class.__name__ == 'GatewayKernelSpecManager'

def test_gateway_get_kernelspecs(self):
# Validate that kernelspecs come from gateway.
Expand All @@ -185,19 +184,19 @@ def test_gateway_get_kernelspecs(self):
self.assertEqual(response.status_code, 200)
content = json.loads(response.content.decode('utf-8'))
kspecs = content.get('kernelspecs')
self.assertEqual(len(kspecs), 2)
self.assertEqual(kspecs.get('kspec_bar').get('name'), 'kspec_bar')
assert len(kspecs) == 2
assert kspecs.get('kspec_bar').get('name') == 'kspec_bar'

def test_gateway_get_named_kernelspec(self):
# Validate that a specific kernelspec can be retrieved from gateway.
with mocked_gateway:
response = self.request('GET', '/api/kernelspecs/kspec_foo')
self.assertEqual(response.status_code, 200)
assert response.status_code == 200
kspec_foo = json.loads(response.content.decode('utf-8'))
self.assertEqual(kspec_foo.get('name'), 'kspec_foo')
assert kspec_foo.get('name') == 'kspec_foo'

response = self.request('GET', '/api/kernelspecs/no_such_spec')
self.assertEqual(response.status_code, 404)
assert response.status_code == 404

def test_gateway_session_lifecycle(self):
# Validate session lifecycle functions; create and delete.
Expand Down
9 changes: 3 additions & 6 deletions notebook/tests/test_i18n.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import nose.tools as nt

from notebook import i18n

def test_parse_accept_lang_header():
palh = i18n.parse_accept_lang_header
nt.assert_equal(palh(''), [])
nt.assert_equal(palh('zh-CN,en-GB;q=0.7,en;q=0.3'),
['en', 'en_GB', 'zh', 'zh_CN'])
nt.assert_equal(palh('nl,fr;q=0'), ['nl'])
assert palh('') == []
assert palh('zh-CN,en-GB;q=0.7,en;q=0.3') == ['en', 'en_GB', 'zh', 'zh_CN']
assert palh('nl,fr;q=0') == ['nl']
9 changes: 5 additions & 4 deletions notebook/tests/test_nbextensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import glob
import os
import pytest
import sys
import tarfile
import zipfile
Expand Down Expand Up @@ -320,7 +321,7 @@ def test_check_nbextension(self):
assert check_nbextension([f], user=True)
assert not check_nbextension([f, pjoin('dne', f)], user=True)

@dec.skip_win32
@pytest.mark.skipif(sys.platform == "win32", reason="do not run on windows")
def test_install_symlink(self):
with TemporaryDirectory() as d:
f = u'ƒ.js'
Expand All @@ -332,7 +333,7 @@ def test_install_symlink(self):
link = os.readlink(dest)
self.assertEqual(link, src)

@dec.skip_win32
@pytest.mark.skipif(sys.platform == "win32", reason="do not run on windows")
def test_overwrite_broken_symlink(self):
with TemporaryDirectory() as d:
f = u'ƒ.js'
Expand All @@ -348,7 +349,7 @@ def test_overwrite_broken_symlink(self):
link = os.readlink(dest)
self.assertEqual(link, src2)

@dec.skip_win32
@pytest.mark.skipif(sys.platform == "win32", reason="do not run on windows")
def test_install_symlink_destination(self):
with TemporaryDirectory() as d:
f = u'ƒ.js'
Expand All @@ -361,7 +362,7 @@ def test_install_symlink_destination(self):
link = os.readlink(dest)
self.assertEqual(link, src)

@dec.skip_win32
@pytest.mark.skipif(sys.platform == "win32", reason="do not run on windows")
def test_install_symlink_bad(self):
with self.assertRaises(ValueError):
install_nbextension("http://example.com/foo.js", symlink=True)
Expand Down
Loading