Skip to content

Commit 7221718

Browse files
authored
Merge pull request #5826 from pgajdos/denose
do not require nose for testing
2 parents 8a53994 + 30a716f commit 7221718

File tree

13 files changed

+126
-136
lines changed

13 files changed

+126
-136
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ env:
1919

2020
before_install:
2121
- pip install --upgrade pip
22-
- pip install --upgrade setuptools wheel nose coverage codecov
22+
- pip install --upgrade setuptools wheel pytest pytest-cov coverage codecov
2323
- nvm install 6.9.2
2424
- nvm use 6.9.2
2525
- node --version
@@ -65,7 +65,7 @@ script:
6565
true
6666
fi
6767
- 'if [[ $GROUP == js* ]]; then travis_retry python -m notebook.jstest ${GROUP:3}; fi'
68-
- 'if [[ $GROUP == python ]]; then nosetests -v --exclude-dir notebook/tests/selenium --with-coverage --cover-package=notebook notebook; fi'
68+
- 'if [[ $GROUP == python ]]; then py.test -v --ignore notebook/tests/selenium --cov=notebook notebook; fi'
6969
- 'if [[ $GROUP == selenium ]]; then py.test -sv notebook/tests/selenium; fi'
7070
- |
7171
if [[ $GROUP == docs ]]; then

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ install:
2121
- cmd: conda config --set show_channel_urls true
2222
- cmd: conda config --add channels conda-forge
2323
#- cmd: conda update --yes --quiet conda
24-
- cmd: conda install -y python=%CONDA_PY_SPEC% pyzmq tornado jupyter_client nbformat ipykernel pip nodejs nose
24+
- cmd: conda install -y python=%CONDA_PY_SPEC% pyzmq tornado jupyter_client nbformat ipykernel pip nodejs pytest nose
2525
# not using `conda install -y` on nbconvent package because there is
2626
# currently a bug with the version that the anaconda installs, so we will just install it with pip
2727
- cmd: pip install nbconvert
2828
- cmd: python setup.py build
2929
- cmd: pip install .[test]
3030

3131
test_script:
32-
- nosetests -v notebook --exclude-dir notebook\tests\selenium
32+
- py.test -v notebook --ignore notebook\tests\selenium

notebook/auth/tests/test_security.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
from ..security import passwd, passwd_check
2-
import nose.tools as nt
32

43
def test_passwd_structure():
54
p = passwd('passphrase')
65
algorithm, hashed = p.split(':')
7-
nt.assert_equal(algorithm, 'argon2')
8-
nt.assert_true(hashed.startswith('$argon2id$'))
6+
assert algorithm == 'argon2'
7+
assert hashed.startswith('$argon2id$')
98

109
def test_roundtrip():
1110
p = passwd('passphrase')
12-
nt.assert_equal(passwd_check(p, 'passphrase'), True)
11+
assert passwd_check(p, 'passphrase') == True
1312

1413
def test_bad():
1514
p = passwd('passphrase')
16-
nt.assert_equal(passwd_check(p, p), False)
17-
nt.assert_equal(passwd_check(p, 'a:b:c:d'), False)
18-
nt.assert_equal(passwd_check(p, 'a:b'), False)
15+
assert passwd_check(p, p) == False
16+
assert passwd_check(p, 'a:b:c:d') == False
17+
assert passwd_check(p, 'a:b') == False
1918

2019
def test_passwd_check_unicode():
2120
# GH issue #4524

notebook/services/contents/tests/test_fileio.py

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
import io as stdlib_io
77
import os.path
8+
import unittest
9+
import pytest
810
import stat
11+
import sys
912

10-
import nose.tools as nt
11-
12-
from ipython_genutils.testing.decorators import skip_win32
1313
from ..fileio import atomic_writing
1414

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

41-
with nt.assert_raises(CustomExc):
41+
with pytest.raises(CustomExc):
4242
with atomic_writing(f1) as f:
4343
f.write(u'Failing write')
4444
raise CustomExc
4545

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

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

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

5656
if os.name != 'nt':
5757
mode = stat.S_IMODE(os.stat(f1).st_mode)
58-
nt.assert_equal(mode, orig_mode)
58+
assert mode == orig_mode
5959

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

6565
with stdlib_io.open(f1, 'r') as f:
66-
nt.assert_equal(f.read(), u'written from symlink')
67-
68-
def _save_umask():
69-
global umask
70-
umask = os.umask(0)
71-
os.umask(umask)
72-
73-
def _restore_umask():
74-
os.umask(umask)
75-
76-
@skip_win32
77-
@nt.with_setup(_save_umask, _restore_umask)
78-
def test_atomic_writing_umask():
79-
with TemporaryDirectory() as td:
80-
os.umask(0o022)
81-
f1 = os.path.join(td, '1')
82-
with atomic_writing(f1) as f:
83-
f.write(u'1')
84-
mode = stat.S_IMODE(os.stat(f1).st_mode)
85-
nt.assert_equal(mode, 0o644, '{:o} != 644'.format(mode))
86-
87-
os.umask(0o057)
88-
f2 = os.path.join(td, '2')
89-
with atomic_writing(f2) as f:
90-
f.write(u'2')
91-
mode = stat.S_IMODE(os.stat(f2).st_mode)
92-
nt.assert_equal(mode, 0o620, '{:o} != 620'.format(mode))
66+
assert f.read() == u'written from symlink'
67+
68+
class TestWithSetUmask(unittest.TestCase):
69+
def setUp(self):
70+
# save umask
71+
global umask
72+
umask = os.umask(0)
73+
os.umask(umask)
74+
75+
def tearDown(self):
76+
# restore umask
77+
os.umask(umask)
78+
79+
@pytest.mark.skipif(sys.platform == "win32", reason="do not run on windows")
80+
def test_atomic_writing_umask(self):
81+
with TemporaryDirectory() as td:
82+
os.umask(0o022)
83+
f1 = os.path.join(td, '1')
84+
with atomic_writing(f1) as f:
85+
f.write(u'1')
86+
mode = stat.S_IMODE(os.stat(f1).st_mode)
87+
assert mode == 0o644
88+
89+
os.umask(0o057)
90+
f2 = os.path.join(td, '2')
91+
with atomic_writing(f2) as f:
92+
f.write(u'2')
93+
mode = stat.S_IMODE(os.stat(f2).st_mode)
94+
assert mode == 0o620
9395

9496

9597
def test_atomic_writing_newlines():
@@ -105,26 +107,26 @@ def test_atomic_writing_newlines():
105107
f.write(lf)
106108
with stdlib_io.open(path, 'r', newline='') as f:
107109
read = f.read()
108-
nt.assert_equal(read, plat)
110+
assert read == plat
109111

110112
# test newline=LF
111113
with stdlib_io.open(path, 'w', newline='\n') as f:
112114
f.write(lf)
113115
with stdlib_io.open(path, 'r', newline='') as f:
114116
read = f.read()
115-
nt.assert_equal(read, lf)
117+
assert read == lf
116118

117119
# test newline=CRLF
118120
with atomic_writing(path, newline='\r\n') as f:
119121
f.write(lf)
120122
with stdlib_io.open(path, 'r', newline='') as f:
121123
read = f.read()
122-
nt.assert_equal(read, crlf)
124+
assert read == crlf
123125

124126
# test newline=no convert
125127
text = u'crlf\r\ncr\rlf\n'
126128
with atomic_writing(path, newline='') as f:
127129
f.write(text)
128130
with stdlib_io.open(path, 'r', newline='') as f:
129131
read = f.read()
130-
nt.assert_equal(read, text)
132+
assert read == text

notebook/services/contents/tests/test_manager.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66
from contextlib import contextmanager
77
from itertools import combinations
88

9-
from nose import SkipTest
109
from tornado.web import HTTPError
11-
from unittest import TestCase
10+
from unittest import TestCase, skipIf
1211
from tempfile import NamedTemporaryFile
1312

1413
from nbformat import v4 as nbformat
1514

1615
from ipython_genutils.tempdir import TemporaryDirectory
1716
from traitlets import TraitError
18-
from ipython_genutils.testing import decorators as dec
1917

2018
from ..filemanager import FileContentsManager
2119

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

129-
@dec.skipif(sys.platform == 'win32')
127+
@skipIf(sys.platform == 'win32', "will not run on windows")
130128
def test_recursive_symlink(self):
131129
with TemporaryDirectory() as td:
132130
cm = FileContentsManager(root_dir=td)
@@ -165,13 +163,10 @@ def test_good_symlink(self):
165163
[symlink_model, file_model],
166164
)
167165

168-
def test_403(self):
169-
if hasattr(os, 'getuid'):
170-
if os.getuid() == 0:
171-
raise SkipTest("Can't test permissions as root")
172-
if sys.platform.startswith('win'):
173-
raise SkipTest("Can't test permissions on Windows")
174166

167+
@skipIf(hasattr(os, 'getuid') and os.getuid() == 0, "Can't test permissions as root")
168+
@skipIf(sys.platform.startswith('win'), "Can't test permissions on Windows")
169+
def test_403(self):
175170
with TemporaryDirectory() as td:
176171
cm = FileContentsManager(root_dir=td)
177172
model = cm.new_untitled(type='file')

notebook/tests/test_gateway.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from io import StringIO
77
from unittest.mock import patch
88

9-
import nose.tools as nt
109
from tornado import gen
1110
from tornado.web import HTTPError
1211
from tornado.httpclient import HTTPRequest, HTTPResponse
@@ -72,7 +71,7 @@ def mock_gateway_request(url, **kwargs):
7271
name = json_body.get('name')
7372
env = json_body.get('env')
7473
kspec_name = env.get('KERNEL_KSPEC_NAME')
75-
nt.assert_equal(name, kspec_name) # Ensure that KERNEL_ env values get propagated
74+
assert name == kspec_name # Ensure that KERNEL_ env values get propagated
7675
model = generate_model(name)
7776
running_kernels[model.get('id')] = model # Register model as a running kernel
7877
response_buf = StringIO(json.dumps(model))
@@ -164,19 +163,19 @@ def setUp(self):
164163
super().setUp()
165164

166165
def test_gateway_options(self):
167-
nt.assert_equal(self.notebook.gateway_config.gateway_enabled, True)
168-
nt.assert_equal(self.notebook.gateway_config.url, TestGateway.mock_gateway_url)
169-
nt.assert_equal(self.notebook.gateway_config.http_user, TestGateway.mock_http_user)
170-
nt.assert_equal(self.notebook.gateway_config.connect_timeout, self.notebook.gateway_config.connect_timeout)
171-
nt.assert_equal(self.notebook.gateway_config.connect_timeout, 44.4)
172-
nt.assert_equal(self.notebook.gateway_config.request_timeout, 96.0)
173-
nt.assert_equal(os.environ['KERNEL_LAUNCH_TIMEOUT'], str(96)) # Ensure KLT gets set from request-timeout
166+
assert self.notebook.gateway_config.gateway_enabled == True
167+
assert self.notebook.gateway_config.url == TestGateway.mock_gateway_url
168+
assert self.notebook.gateway_config.http_user == TestGateway.mock_http_user
169+
assert self.notebook.gateway_config.connect_timeout == self.notebook.gateway_config.connect_timeout
170+
assert self.notebook.gateway_config.connect_timeout == 44.4
171+
assert self.notebook.gateway_config.request_timeout == 96.0
172+
assert os.environ['KERNEL_LAUNCH_TIMEOUT'] == str(96) # Ensure KLT gets set from request-timeout
174173

175174
def test_gateway_class_mappings(self):
176175
# Ensure appropriate class mappings are in place.
177-
nt.assert_equal(self.notebook.kernel_manager_class.__name__, 'GatewayKernelManager')
178-
nt.assert_equal(self.notebook.session_manager_class.__name__, 'GatewaySessionManager')
179-
nt.assert_equal(self.notebook.kernel_spec_manager_class.__name__, 'GatewayKernelSpecManager')
176+
assert self.notebook.kernel_manager_class.__name__ == 'GatewayKernelManager'
177+
assert self.notebook.session_manager_class.__name__ == 'GatewaySessionManager'
178+
assert self.notebook.kernel_spec_manager_class.__name__ == 'GatewayKernelSpecManager'
180179

181180
def test_gateway_get_kernelspecs(self):
182181
# Validate that kernelspecs come from gateway.
@@ -185,19 +184,19 @@ def test_gateway_get_kernelspecs(self):
185184
self.assertEqual(response.status_code, 200)
186185
content = json.loads(response.content.decode('utf-8'))
187186
kspecs = content.get('kernelspecs')
188-
self.assertEqual(len(kspecs), 2)
189-
self.assertEqual(kspecs.get('kspec_bar').get('name'), 'kspec_bar')
187+
assert len(kspecs) == 2
188+
assert kspecs.get('kspec_bar').get('name') == 'kspec_bar'
190189

191190
def test_gateway_get_named_kernelspec(self):
192191
# Validate that a specific kernelspec can be retrieved from gateway.
193192
with mocked_gateway:
194193
response = self.request('GET', '/api/kernelspecs/kspec_foo')
195-
self.assertEqual(response.status_code, 200)
194+
assert response.status_code == 200
196195
kspec_foo = json.loads(response.content.decode('utf-8'))
197-
self.assertEqual(kspec_foo.get('name'), 'kspec_foo')
196+
assert kspec_foo.get('name') == 'kspec_foo'
198197

199198
response = self.request('GET', '/api/kernelspecs/no_such_spec')
200-
self.assertEqual(response.status_code, 404)
199+
assert response.status_code == 404
201200

202201
def test_gateway_session_lifecycle(self):
203202
# Validate session lifecycle functions; create and delete.

notebook/tests/test_i18n.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import nose.tools as nt
2-
31
from notebook import i18n
42

53
def test_parse_accept_lang_header():
64
palh = i18n.parse_accept_lang_header
7-
nt.assert_equal(palh(''), [])
8-
nt.assert_equal(palh('zh-CN,en-GB;q=0.7,en;q=0.3'),
9-
['en', 'en_GB', 'zh', 'zh_CN'])
10-
nt.assert_equal(palh('nl,fr;q=0'), ['nl'])
5+
assert palh('') == []
6+
assert palh('zh-CN,en-GB;q=0.7,en;q=0.3') == ['en', 'en_GB', 'zh', 'zh_CN']
7+
assert palh('nl,fr;q=0') == ['nl']

notebook/tests/test_nbextensions.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import glob
77
import os
8+
import pytest
89
import sys
910
import tarfile
1011
import zipfile
@@ -320,7 +321,7 @@ def test_check_nbextension(self):
320321
assert check_nbextension([f], user=True)
321322
assert not check_nbextension([f, pjoin('dne', f)], user=True)
322323

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

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

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

364-
@dec.skip_win32
365+
@pytest.mark.skipif(sys.platform == "win32", reason="do not run on windows")
365366
def test_install_symlink_bad(self):
366367
with self.assertRaises(ValueError):
367368
install_nbextension("http://example.com/foo.js", symlink=True)

0 commit comments

Comments
 (0)