From 12d08a51494137e81dc0cd631eef5afdc46ae07f 2021-10-23 12:01:15 From: Samuel Gaist Date: 2021-10-23 12:01:15 Subject: [PATCH] [extensions][tests][autoreload] Remove nose --- diff --git a/IPython/extensions/tests/test_autoreload.py b/IPython/extensions/tests/test_autoreload.py index 4bccd40..e03a08e 100644 --- a/IPython/extensions/tests/test_autoreload.py +++ b/IPython/extensions/tests/test_autoreload.py @@ -21,7 +21,6 @@ import random import time from io import StringIO -import nose.tools as nt import IPython.testing.tools as tt from unittest import TestCase @@ -227,12 +226,12 @@ class TestAutoreload(Fixture): self.shell.run_code("from %s import MyClass" % mod_name) self.shell.run_code("first = MyClass(5)") self.shell.run_code("first.square()") - with nt.assert_raises(AttributeError): + with self.assertRaises(AttributeError): self.shell.run_code("first.cube()") - with nt.assert_raises(AttributeError): + with self.assertRaises(AttributeError): self.shell.run_code("first.power(5)") self.shell.run_code("first.b") - with nt.assert_raises(AttributeError): + with self.assertRaises(AttributeError): self.shell.run_code("first.toto") # remove square, add power @@ -258,13 +257,13 @@ class TestAutoreload(Fixture): for object_name in {"first", "second"}: self.shell.run_code(f"{object_name}.power(5)") - with nt.assert_raises(AttributeError): + with self.assertRaises(AttributeError): self.shell.run_code(f"{object_name}.cube()") - with nt.assert_raises(AttributeError): + with self.assertRaises(AttributeError): self.shell.run_code(f"{object_name}.square()") self.shell.run_code(f"{object_name}.b") self.shell.run_code(f"{object_name}.a") - with nt.assert_raises(AttributeError): + with self.assertRaises(AttributeError): self.shell.run_code(f"{object_name}.toto") def test_autoload_newly_added_objects(self): @@ -275,11 +274,11 @@ class TestAutoreload(Fixture): mod_name, mod_fn = self.new_module(textwrap.dedent(mod_code)) self.shell.run_code(f"from {mod_name} import *") self.shell.run_code("func1()") - with nt.assert_raises(NameError): + with self.assertRaises(NameError): self.shell.run_code("func2()") - with nt.assert_raises(NameError): + with self.assertRaises(NameError): self.shell.run_code("t = Test()") - with nt.assert_raises(NameError): + with self.assertRaises(NameError): self.shell.run_code("number") # ----------- TEST NEW OBJ LOADED -------------------------- @@ -391,19 +390,19 @@ class Bar: # old-style class: weakref doesn't work for it on Python < 2.7 self.shell.magic_aimport(mod_name) stream = StringIO() self.shell.magic_aimport("", stream=stream) - nt.assert_in(("Modules to reload:\n%s" % mod_name), stream.getvalue()) + self.assertIn(("Modules to reload:\n%s" % mod_name), stream.getvalue()) - with nt.assert_raises(ImportError): + with self.assertRaises(ImportError): self.shell.magic_aimport("tmpmod_as318989e89ds") else: self.shell.magic_autoreload("2") self.shell.run_code("import %s" % mod_name) stream = StringIO() self.shell.magic_aimport("", stream=stream) - nt.assert_true( + self.assertTrue( "Modules to reload:\nall-except-skipped" in stream.getvalue() ) - nt.assert_in(mod_name, self.shell.ns) + self.assertIn(mod_name, self.shell.ns) mod = sys.modules[mod_name] @@ -415,21 +414,21 @@ class Bar: # old-style class: weakref doesn't work for it on Python < 2.7 old_obj2 = mod.Bar() def check_module_contents(): - nt.assert_equal(mod.x, 9) - nt.assert_equal(mod.z, 123) + self.assertEqual(mod.x, 9) + self.assertEqual(mod.z, 123) - nt.assert_equal(old_foo(0), 3) - nt.assert_equal(mod.foo(0), 3) + self.assertEqual(old_foo(0), 3) + self.assertEqual(mod.foo(0), 3) obj = mod.Baz(9) - nt.assert_equal(old_obj.bar(1), 10) - nt.assert_equal(obj.bar(1), 10) - nt.assert_equal(obj.quux, 42) - nt.assert_equal(obj.zzz(), 99) + self.assertEqual(old_obj.bar(1), 10) + self.assertEqual(obj.bar(1), 10) + self.assertEqual(obj.quux, 42) + self.assertEqual(obj.zzz(), 99) obj2 = mod.Bar() - nt.assert_equal(old_obj2.foo(), 1) - nt.assert_equal(obj2.foo(), 1) + self.assertEqual(old_obj2.foo(), 1) + self.assertEqual(obj2.foo(), 1) check_module_contents() @@ -481,25 +480,25 @@ class Bar: # old-style class ) def check_module_contents(): - nt.assert_equal(mod.x, 10) - nt.assert_false(hasattr(mod, "z")) + self.assertEqual(mod.x, 10) + self.assertFalse(hasattr(mod, "z")) - nt.assert_equal(old_foo(0), 4) # superreload magic! - nt.assert_equal(mod.foo(0), 4) + self.assertEqual(old_foo(0), 4) # superreload magic! + self.assertEqual(mod.foo(0), 4) obj = mod.Baz(9) - nt.assert_equal(old_obj.bar(1), 11) # superreload magic! - nt.assert_equal(obj.bar(1), 11) + self.assertEqual(old_obj.bar(1), 11) # superreload magic! + self.assertEqual(obj.bar(1), 11) - nt.assert_equal(old_obj.quux, 43) - nt.assert_equal(obj.quux, 43) + self.assertEqual(old_obj.quux, 43) + self.assertEqual(obj.quux, 43) - nt.assert_false(hasattr(old_obj, "zzz")) - nt.assert_false(hasattr(obj, "zzz")) + self.assertFalse(hasattr(old_obj, "zzz")) + self.assertFalse(hasattr(obj, "zzz")) obj2 = mod.Bar() - nt.assert_equal(old_obj2.foo(), 2) - nt.assert_equal(obj2.foo(), 2) + self.assertEqual(old_obj2.foo(), 2) + self.assertEqual(obj2.foo(), 2) self.shell.run_code("pass") # trigger reload check_module_contents() @@ -519,7 +518,7 @@ class Bar: # old-style class self.shell.magic_aimport("-" + mod_name) stream = StringIO() self.shell.magic_aimport("", stream=stream) - nt.assert_true(("Modules to skip:\n%s" % mod_name) in stream.getvalue()) + self.assertTrue(("Modules to skip:\n%s" % mod_name) in stream.getvalue()) # This should succeed, although no such module exists self.shell.magic_aimport("-tmpmod_as318989e89ds") @@ -546,7 +545,7 @@ x = -99 self.shell.magic_autoreload("") self.shell.run_code("pass") # trigger reload - nt.assert_equal(mod.x, -99) + self.assertEqual(mod.x, -99) def test_smoketest_aimport(self): self._check_smoketest(use_aimport=True)