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