Skip to content

Commit df40782

Browse files
committed
use raw asserts instead of nose.tools
in preparation for switch to pytest leave unittest `self.assert` methods alone to avoid too much churn
1 parent 6567670 commit df40782

File tree

6 files changed

+36
-43
lines changed

6 files changed

+36
-43
lines changed

jupyter_client/tests/test_adapter.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import copy
77
import json
88
from unittest import TestCase
9-
import nose.tools as nt
109

1110
from jupyter_client.adapter import adapt, V4toV5, V5toV4, code_to_line
1211
from jupyter_client.session import Session
@@ -18,12 +17,12 @@ def test_default_version():
1817
msg['header'].pop('version')
1918
original = copy.deepcopy(msg)
2019
adapted = adapt(original)
21-
nt.assert_equal(adapted['header']['version'], V4toV5.version)
20+
assert adapted['header']['version'] == V4toV5.version
2221

2322
def test_code_to_line_no_code():
2423
line, pos = code_to_line("", 0)
25-
nt.assert_equal(line, "")
26-
nt.assert_equal(pos, 0)
24+
assert line == ""
25+
assert pos == 0
2726

2827
class AdapterTest(TestCase):
2928

@@ -263,7 +262,7 @@ def test_rename_type(self):
263262
msg = self.msg(v5_type, {'key' : 'value'})
264263
v5, v4 = self.adapt(msg)
265264
self.assertEqual(v4['header']['msg_type'], v4_type)
266-
nt.assert_not_in('version', v4['header'])
265+
assert 'version' not in v4['header']
267266
self.assertEqual(v4['content'], v5['content'])
268267

269268
def test_execute_request(self):

jupyter_client/tests/test_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
pjoin = os.path.join
99
from unittest import TestCase
1010

11-
from nose import SkipTest
12-
1311
from jupyter_client.kernelspec import KernelSpecManager, NoSuchKernel, NATIVE_KERNEL_NAME
1412
from ..manager import start_new_kernel
1513
from .utils import test_env
1614

15+
import pytest
16+
1717
from ipython_genutils.py3compat import string_types
1818
from IPython.utils.capture import capture_output
1919

@@ -27,7 +27,7 @@ def setUp(self):
2727
try:
2828
KernelSpecManager().get_kernel_spec(NATIVE_KERNEL_NAME)
2929
except NoSuchKernel:
30-
raise SkipTest()
30+
pytest.skip()
3131
self.km, self.kc = start_new_kernel(kernel_name=NATIVE_KERNEL_NAME)
3232
self.addCleanup(self.kc.stop_channels)
3333
self.addCleanup(self.km.shutdown_kernel)

jupyter_client/tests/test_connect.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import json
77
import os
88

9-
import nose.tools as nt
10-
119
from traitlets.config import Config
1210
from jupyter_core.application import JupyterApp
1311
from ipython_genutils.tempdir import TemporaryDirectory, TemporaryWorkingDirectory
@@ -36,11 +34,11 @@ def test_write_connection_file():
3634
with TemporaryDirectory() as d:
3735
cf = os.path.join(d, 'kernel.json')
3836
connect.write_connection_file(cf, **sample_info)
39-
nt.assert_true(os.path.exists(cf))
37+
assert os.path.exists(cf)
4038
with open(cf, 'r') as f:
4139
info = json.load(f)
4240
info['key'] = str_to_bytes(info['key'])
43-
nt.assert_equal(info, sample_info)
41+
assert info == sample_info
4442

4543

4644
def test_load_connection_file_session():
@@ -56,8 +54,8 @@ def test_load_connection_file_session():
5654
app.connection_file = cf
5755
app.load_connection_file()
5856

59-
nt.assert_equal(session.key, sample_info['key'])
60-
nt.assert_equal(session.signature_scheme, sample_info['signature_scheme'])
57+
assert session.key == sample_info['key']
58+
assert session.signature_scheme == sample_info['signature_scheme']
6159

6260

6361
def test_load_connection_file_session_with_kn():
@@ -73,8 +71,8 @@ def test_load_connection_file_session_with_kn():
7371
app.connection_file = cf
7472
app.load_connection_file()
7573

76-
nt.assert_equal(session.key, sample_info_kn['key'])
77-
nt.assert_equal(session.signature_scheme, sample_info_kn['signature_scheme'])
74+
assert session.key == sample_info_kn['key']
75+
assert session.signature_scheme == sample_info_kn['signature_scheme']
7876

7977

8078
def test_app_load_connection_file():
@@ -89,7 +87,7 @@ def test_app_load_connection_file():
8987
if attr in ('key', 'signature_scheme'):
9088
continue
9189
value = getattr(app, attr)
92-
nt.assert_equal(value, expected, "app.%s = %s != %s" % (attr, value, expected))
90+
assert value == expected, "app.%s = %s != %s" % (attr, value, expected)
9391

9492

9593
def test_load_connection_info():
@@ -131,7 +129,7 @@ def test_find_connection_file():
131129
'*ernel*',
132130
'k*',
133131
):
134-
nt.assert_equal(connect.find_connection_file(query, path=security_dir), profile_cf)
132+
assert connect.find_connection_file(query, path=security_dir) == profile_cf
135133

136134
JupyterApp._instance = None
137135

jupyter_client/tests/test_jsonutil.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
# py2
1515
import mock
1616

17-
import nose.tools as nt
18-
1917
from dateutil.tz import tzlocal, tzoffset
2018
from jupyter_client import jsonutil
2119
from jupyter_client.session import utcnow
@@ -33,29 +31,29 @@ def test_extract_dates():
3331
extracted = jsonutil.extract_dates(timestamps)
3432
ref = extracted[0]
3533
for dt in extracted:
36-
nt.assert_true(isinstance(dt, datetime.datetime))
37-
nt.assert_not_equal(dt.tzinfo, None)
34+
assert isinstance(dt, datetime.datetime)
35+
assert dt.tzinfo != None
3836

39-
nt.assert_equal(extracted[0].tzinfo.utcoffset(ref), tzlocal().utcoffset(ref))
40-
nt.assert_equal(extracted[1].tzinfo.utcoffset(ref), timedelta(0))
41-
nt.assert_equal(extracted[2].tzinfo.utcoffset(ref), timedelta(hours=-8))
42-
nt.assert_equal(extracted[3].tzinfo.utcoffset(ref), timedelta(hours=8))
43-
nt.assert_equal(extracted[4].tzinfo.utcoffset(ref), timedelta(hours=-8))
44-
nt.assert_equal(extracted[5].tzinfo.utcoffset(ref), timedelta(hours=8))
37+
assert extracted[0].tzinfo.utcoffset(ref) == tzlocal().utcoffset(ref)
38+
assert extracted[1].tzinfo.utcoffset(ref) == timedelta(0)
39+
assert extracted[2].tzinfo.utcoffset(ref) == timedelta(hours=-8)
40+
assert extracted[3].tzinfo.utcoffset(ref) == timedelta(hours=8)
41+
assert extracted[4].tzinfo.utcoffset(ref) == timedelta(hours=-8)
42+
assert extracted[5].tzinfo.utcoffset(ref) == timedelta(hours=8)
4543

4644
def test_parse_ms_precision():
4745
base = '2013-07-03T16:34:52'
4846
digits = '1234567890'
4947

5048
parsed = jsonutil.parse_date(base)
51-
nt.assert_is_instance(parsed, datetime.datetime)
49+
assert isinstance(parsed, datetime.datetime)
5250
for i in range(len(digits)):
5351
ts = base + '.' + digits[:i]
5452
parsed = jsonutil.parse_date(ts)
5553
if i >= 1 and i <= 6:
56-
nt.assert_is_instance(parsed, datetime.datetime)
54+
assert isinstance(parsed, datetime.datetime)
5755
else:
58-
nt.assert_is_instance(parsed, str)
56+
assert isinstance(parsed, str)
5957

6058

6159

@@ -66,10 +64,10 @@ def test_date_default():
6664
data = dict(naive=naive, utc=utcnow(), withtz=naive.replace(tzinfo=other))
6765
with mock.patch.object(jsonutil, 'tzlocal', lambda : local):
6866
jsondata = json.dumps(data, default=jsonutil.date_default)
69-
nt.assert_in("Z", jsondata)
70-
nt.assert_equal(jsondata.count("Z"), 1)
67+
assert "Z" in jsondata
68+
assert jsondata.count("Z") == 1
7169
extracted = jsonutil.extract_dates(json.loads(jsondata))
7270
for dt in extracted.values():
73-
nt.assert_is_instance(dt, datetime.datetime)
74-
nt.assert_not_equal(dt.tzinfo, None)
71+
assert isinstance(dt, datetime.datetime)
72+
assert dt.tzinfo != None
7573

jupyter_client/tests/test_public_api.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,24 @@
44
# Copyright (c) Jupyter Development Team.
55
# Distributed under the terms of the Modified BSD License.
66

7-
import nose.tools as nt
8-
97
from jupyter_client import launcher, connect
108
import jupyter_client
119

1210

1311
def test_kms():
1412
for base in ("", "Multi"):
1513
KM = base + "KernelManager"
16-
nt.assert_in(KM, dir(jupyter_client))
14+
assert KM in dir(jupyter_client)
1715

1816
def test_kcs():
1917
for base in ("", "Blocking"):
2018
KM = base + "KernelClient"
21-
nt.assert_in(KM, dir(jupyter_client))
19+
assert KM in dir(jupyter_client)
2220

2321
def test_launcher():
2422
for name in launcher.__all__:
25-
nt.assert_in(name, dir(jupyter_client))
23+
assert name in dir(jupyter_client)
2624

2725
def test_connect():
2826
for name in connect.__all__:
29-
nt.assert_in(name, dir(jupyter_client))
27+
assert name in dir(jupyter_client)

jupyter_client/tests/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ def execute(code='', kc=None, **kwargs):
4646
validate_message(reply, 'execute_reply', msg_id)
4747
busy = kc.get_iopub_msg(timeout=TIMEOUT)
4848
validate_message(busy, 'status', msg_id)
49-
nt.assert_equal(busy['content']['execution_state'], 'busy')
49+
assert busy['content']['execution_state'] == 'busy'
5050

5151
if not kwargs.get('silent'):
5252
execute_input = kc.get_iopub_msg(timeout=TIMEOUT)
5353
validate_message(execute_input, 'execute_input', msg_id)
54-
nt.assert_equal(execute_input['content']['code'], code)
54+
assert execute_input['content']['code'] == code
5555

5656
return msg_id, reply['content']

0 commit comments

Comments
 (0)