Functional test for the automatic reloader using either '%autoreload 1' or '%autoreload 2'
(self, use_aimport=True)
| 655 | assert lo.output == [f"INFO:autoreload:Reloading '{mod_name}'."] |
| 656 | |
| 657 | def _check_smoketest(self, use_aimport=True): |
| 658 | """ |
| 659 | Functional test for the automatic reloader using either |
| 660 | '%autoreload 1' or '%autoreload 2' |
| 661 | """ |
| 662 | |
| 663 | mod_name, mod_fn = self.new_module( |
| 664 | """ |
| 665 | x = 9 |
| 666 | |
| 667 | z = 123 # this item will be deleted |
| 668 | |
| 669 | def foo(y): |
| 670 | return y + 3 |
| 671 | |
| 672 | class Baz(object): |
| 673 | def __init__(self, x): |
| 674 | self.x = x |
| 675 | def bar(self, y): |
| 676 | return self.x + y |
| 677 | @property |
| 678 | def quux(self): |
| 679 | return 42 |
| 680 | def zzz(self): |
| 681 | '''This method will be deleted below''' |
| 682 | return 99 |
| 683 | |
| 684 | class Bar: # old-style class: weakref doesn't work for it on Python < 2.7 |
| 685 | def foo(self): |
| 686 | return 1 |
| 687 | """ |
| 688 | ) |
| 689 | |
| 690 | # |
| 691 | # Import module, and mark for reloading |
| 692 | # |
| 693 | if use_aimport: |
| 694 | self.shell.magic_autoreload("1") |
| 695 | self.shell.magic_aimport(mod_name) |
| 696 | stream = StringIO() |
| 697 | self.shell.magic_aimport("", stream=stream) |
| 698 | self.assertIn(("Modules to reload:\n%s" % mod_name), stream.getvalue()) |
| 699 | |
| 700 | with self.assertRaises(ImportError): |
| 701 | self.shell.magic_aimport("tmpmod_as318989e89ds") |
| 702 | else: |
| 703 | self.shell.magic_autoreload("2") |
| 704 | self.shell.run_code("import %s" % mod_name) |
| 705 | stream = StringIO() |
| 706 | self.shell.magic_aimport("", stream=stream) |
| 707 | self.assertTrue( |
| 708 | "Modules to reload:\nall-except-skipped" in stream.getvalue() |
| 709 | ) |
| 710 | self.assertIn(mod_name, self.shell.ns) |
| 711 | |
| 712 | mod = sys.modules[mod_name] |
| 713 | |
| 714 | # |
no test coverage detected