##// END OF EJS Templates
[extensions][tests][autoreload] Remove nose
Samuel Gaist -
Show More
@@ -21,7 +21,6 b' import random'
21 21 import time
22 22 from io import StringIO
23 23
24 import nose.tools as nt
25 24 import IPython.testing.tools as tt
26 25
27 26 from unittest import TestCase
@@ -227,12 +226,12 b' class TestAutoreload(Fixture):'
227 226 self.shell.run_code("from %s import MyClass" % mod_name)
228 227 self.shell.run_code("first = MyClass(5)")
229 228 self.shell.run_code("first.square()")
230 with nt.assert_raises(AttributeError):
229 with self.assertRaises(AttributeError):
231 230 self.shell.run_code("first.cube()")
232 with nt.assert_raises(AttributeError):
231 with self.assertRaises(AttributeError):
233 232 self.shell.run_code("first.power(5)")
234 233 self.shell.run_code("first.b")
235 with nt.assert_raises(AttributeError):
234 with self.assertRaises(AttributeError):
236 235 self.shell.run_code("first.toto")
237 236
238 237 # remove square, add power
@@ -258,13 +257,13 b' class TestAutoreload(Fixture):'
258 257
259 258 for object_name in {"first", "second"}:
260 259 self.shell.run_code(f"{object_name}.power(5)")
261 with nt.assert_raises(AttributeError):
260 with self.assertRaises(AttributeError):
262 261 self.shell.run_code(f"{object_name}.cube()")
263 with nt.assert_raises(AttributeError):
262 with self.assertRaises(AttributeError):
264 263 self.shell.run_code(f"{object_name}.square()")
265 264 self.shell.run_code(f"{object_name}.b")
266 265 self.shell.run_code(f"{object_name}.a")
267 with nt.assert_raises(AttributeError):
266 with self.assertRaises(AttributeError):
268 267 self.shell.run_code(f"{object_name}.toto")
269 268
270 269 def test_autoload_newly_added_objects(self):
@@ -275,11 +274,11 b' class TestAutoreload(Fixture):'
275 274 mod_name, mod_fn = self.new_module(textwrap.dedent(mod_code))
276 275 self.shell.run_code(f"from {mod_name} import *")
277 276 self.shell.run_code("func1()")
278 with nt.assert_raises(NameError):
277 with self.assertRaises(NameError):
279 278 self.shell.run_code("func2()")
280 with nt.assert_raises(NameError):
279 with self.assertRaises(NameError):
281 280 self.shell.run_code("t = Test()")
282 with nt.assert_raises(NameError):
281 with self.assertRaises(NameError):
283 282 self.shell.run_code("number")
284 283
285 284 # ----------- TEST NEW OBJ LOADED --------------------------
@@ -391,19 +390,19 b" class Bar: # old-style class: weakref doesn't work for it on Python < 2.7"
391 390 self.shell.magic_aimport(mod_name)
392 391 stream = StringIO()
393 392 self.shell.magic_aimport("", stream=stream)
394 nt.assert_in(("Modules to reload:\n%s" % mod_name), stream.getvalue())
393 self.assertIn(("Modules to reload:\n%s" % mod_name), stream.getvalue())
395 394
396 with nt.assert_raises(ImportError):
395 with self.assertRaises(ImportError):
397 396 self.shell.magic_aimport("tmpmod_as318989e89ds")
398 397 else:
399 398 self.shell.magic_autoreload("2")
400 399 self.shell.run_code("import %s" % mod_name)
401 400 stream = StringIO()
402 401 self.shell.magic_aimport("", stream=stream)
403 nt.assert_true(
402 self.assertTrue(
404 403 "Modules to reload:\nall-except-skipped" in stream.getvalue()
405 404 )
406 nt.assert_in(mod_name, self.shell.ns)
405 self.assertIn(mod_name, self.shell.ns)
407 406
408 407 mod = sys.modules[mod_name]
409 408
@@ -415,21 +414,21 b" class Bar: # old-style class: weakref doesn't work for it on Python < 2.7"
415 414 old_obj2 = mod.Bar()
416 415
417 416 def check_module_contents():
418 nt.assert_equal(mod.x, 9)
419 nt.assert_equal(mod.z, 123)
417 self.assertEqual(mod.x, 9)
418 self.assertEqual(mod.z, 123)
420 419
421 nt.assert_equal(old_foo(0), 3)
422 nt.assert_equal(mod.foo(0), 3)
420 self.assertEqual(old_foo(0), 3)
421 self.assertEqual(mod.foo(0), 3)
423 422
424 423 obj = mod.Baz(9)
425 nt.assert_equal(old_obj.bar(1), 10)
426 nt.assert_equal(obj.bar(1), 10)
427 nt.assert_equal(obj.quux, 42)
428 nt.assert_equal(obj.zzz(), 99)
424 self.assertEqual(old_obj.bar(1), 10)
425 self.assertEqual(obj.bar(1), 10)
426 self.assertEqual(obj.quux, 42)
427 self.assertEqual(obj.zzz(), 99)
429 428
430 429 obj2 = mod.Bar()
431 nt.assert_equal(old_obj2.foo(), 1)
432 nt.assert_equal(obj2.foo(), 1)
430 self.assertEqual(old_obj2.foo(), 1)
431 self.assertEqual(obj2.foo(), 1)
433 432
434 433 check_module_contents()
435 434
@@ -481,25 +480,25 b' class Bar: # old-style class'
481 480 )
482 481
483 482 def check_module_contents():
484 nt.assert_equal(mod.x, 10)
485 nt.assert_false(hasattr(mod, "z"))
483 self.assertEqual(mod.x, 10)
484 self.assertFalse(hasattr(mod, "z"))
486 485
487 nt.assert_equal(old_foo(0), 4) # superreload magic!
488 nt.assert_equal(mod.foo(0), 4)
486 self.assertEqual(old_foo(0), 4) # superreload magic!
487 self.assertEqual(mod.foo(0), 4)
489 488
490 489 obj = mod.Baz(9)
491 nt.assert_equal(old_obj.bar(1), 11) # superreload magic!
492 nt.assert_equal(obj.bar(1), 11)
490 self.assertEqual(old_obj.bar(1), 11) # superreload magic!
491 self.assertEqual(obj.bar(1), 11)
493 492
494 nt.assert_equal(old_obj.quux, 43)
495 nt.assert_equal(obj.quux, 43)
493 self.assertEqual(old_obj.quux, 43)
494 self.assertEqual(obj.quux, 43)
496 495
497 nt.assert_false(hasattr(old_obj, "zzz"))
498 nt.assert_false(hasattr(obj, "zzz"))
496 self.assertFalse(hasattr(old_obj, "zzz"))
497 self.assertFalse(hasattr(obj, "zzz"))
499 498
500 499 obj2 = mod.Bar()
501 nt.assert_equal(old_obj2.foo(), 2)
502 nt.assert_equal(obj2.foo(), 2)
500 self.assertEqual(old_obj2.foo(), 2)
501 self.assertEqual(obj2.foo(), 2)
503 502
504 503 self.shell.run_code("pass") # trigger reload
505 504 check_module_contents()
@@ -519,7 +518,7 b' class Bar: # old-style class'
519 518 self.shell.magic_aimport("-" + mod_name)
520 519 stream = StringIO()
521 520 self.shell.magic_aimport("", stream=stream)
522 nt.assert_true(("Modules to skip:\n%s" % mod_name) in stream.getvalue())
521 self.assertTrue(("Modules to skip:\n%s" % mod_name) in stream.getvalue())
523 522
524 523 # This should succeed, although no such module exists
525 524 self.shell.magic_aimport("-tmpmod_as318989e89ds")
@@ -546,7 +545,7 b' x = -99'
546 545 self.shell.magic_autoreload("")
547 546
548 547 self.shell.run_code("pass") # trigger reload
549 nt.assert_equal(mod.x, -99)
548 self.assertEqual(mod.x, -99)
550 549
551 550 def test_smoketest_aimport(self):
552 551 self._check_smoketest(use_aimport=True)
General Comments 0
You need to be logged in to leave comments. Login now