From cf762a5685effaeed94a03a45927b87be5085175 2021-10-23 12:01:15 From: Samuel Gaist Date: 2021-10-23 12:01:15 Subject: [PATCH] [core][tests][history] Remove nose --- diff --git a/IPython/core/tests/test_history.py b/IPython/core/tests/test_history.py index 824ba1e..4cc43ca 100644 --- a/IPython/core/tests/test_history.py +++ b/IPython/core/tests/test_history.py @@ -13,9 +13,6 @@ import tempfile from datetime import datetime import sqlite3 -# third party -import nose.tools as nt - # our own packages from traitlets.config.loader import Config from IPython.utils.tempdir import TemporaryDirectory @@ -23,7 +20,7 @@ from IPython.core.history import HistoryManager, extract_hist_ranges from IPython.testing.decorators import skipif def test_proper_default_encoding(): - nt.assert_equal(sys.getdefaultencoding(), "utf-8") + assert sys.getdefaultencoding() == "utf-8" @skipif(sqlite3.sqlite_version_info > (3,24,0)) def test_history(): @@ -34,7 +31,7 @@ def test_history(): hist_file = tmp_path / "history.sqlite" try: ip.history_manager = HistoryManager(shell=ip, hist_file=hist_file) - hist = [u'a=1', u'def f():\n test = 1\n return test', u"b='€Æ¾÷ß'"] + hist = ["a=1", "def f():\n test = 1\n return test", "b='€Æ¾÷ß'"] for i, h in enumerate(hist, start=1): ip.history_manager.store_inputs(i, h) @@ -43,13 +40,15 @@ def test_history(): ip.history_manager.output_hist_reprs[3] = "spam" ip.history_manager.store_output(3) - nt.assert_equal(ip.history_manager.input_hist_raw, [''] + hist) + assert ip.history_manager.input_hist_raw == [""] + hist # Detailed tests for _get_range_session grs = ip.history_manager._get_range_session - nt.assert_equal(list(grs(start=2,stop=-1)), list(zip([0], [2], hist[1:-1]))) - nt.assert_equal(list(grs(start=-2)), list(zip([0,0], [2,3], hist[-2:]))) - nt.assert_equal(list(grs(output=True)), list(zip([0,0,0], [1,2,3], zip(hist, [None,None,'spam'])))) + assert list(grs(start=2, stop=-1)) == list(zip([0], [2], hist[1:-1])) + assert list(grs(start=-2)) == list(zip([0, 0], [2, 3], hist[-2:])) + assert list(grs(output=True)) == list( + zip([0, 0, 0], [1, 2, 3], zip(hist, [None, None, "spam"])) + ) # Check whether specifying a range beyond the end of the current # session results in an error (gh-804) @@ -63,17 +62,14 @@ def test_history(): # New session ip.history_manager.reset() - newcmds = [u"z=5", - u"class X(object):\n pass", - u"k='p'", - u"z=5"] + newcmds = ["z=5", "class X(object):\n pass", "k='p'", "z=5"] for i, cmd in enumerate(newcmds, start=1): ip.history_manager.store_inputs(i, cmd) gothist = ip.history_manager.get_range(start=1, stop=4) - nt.assert_equal(list(gothist), list(zip([0,0,0],[1,2,3], newcmds))) + assert list(gothist) == list(zip([0, 0, 0], [1, 2, 3], newcmds)) # Previous session: gothist = ip.history_manager.get_range(-1, 1, 4) - nt.assert_equal(list(gothist), list(zip([1,1,1],[1,2,3], hist))) + assert list(gothist) == list(zip([1, 1, 1], [1, 2, 3], hist)) newhist = [(2, i, c) for (i, c) in enumerate(newcmds, 1)] @@ -82,62 +78,61 @@ def test_history(): include_latest=True) expected = [(1, 3, (hist[-1], "spam"))] \ + [(s, n, (c, None)) for (s, n, c) in newhist] - nt.assert_equal(list(gothist), expected) + assert list(gothist) == expected gothist = ip.history_manager.get_tail(2) expected = newhist[-3:-1] - nt.assert_equal(list(gothist), expected) + assert list(gothist) == expected # Check get_hist_search gothist = ip.history_manager.search("*test*") - nt.assert_equal(list(gothist), [(1,2,hist[1])] ) + assert list(gothist) == [(1, 2, hist[1])] gothist = ip.history_manager.search("*=*") - nt.assert_equal(list(gothist), - [(1, 1, hist[0]), - (1, 2, hist[1]), - (1, 3, hist[2]), - newhist[0], - newhist[2], - newhist[3]]) + assert list(gothist) == [ + (1, 1, hist[0]), + (1, 2, hist[1]), + (1, 3, hist[2]), + newhist[0], + newhist[2], + newhist[3], + ] gothist = ip.history_manager.search("*=*", n=4) - nt.assert_equal(list(gothist), - [(1, 3, hist[2]), - newhist[0], - newhist[2], - newhist[3]]) + assert list(gothist) == [ + (1, 3, hist[2]), + newhist[0], + newhist[2], + newhist[3], + ] gothist = ip.history_manager.search("*=*", unique=True) - nt.assert_equal(list(gothist), - [(1, 1, hist[0]), - (1, 2, hist[1]), - (1, 3, hist[2]), - newhist[2], - newhist[3]]) + assert list(gothist) == [ + (1, 1, hist[0]), + (1, 2, hist[1]), + (1, 3, hist[2]), + newhist[2], + newhist[3], + ] gothist = ip.history_manager.search("*=*", unique=True, n=3) - nt.assert_equal(list(gothist), - [(1, 3, hist[2]), - newhist[2], - newhist[3]]) + assert list(gothist) == [(1, 3, hist[2]), newhist[2], newhist[3]] gothist = ip.history_manager.search("b*", output=True) - nt.assert_equal(list(gothist), [(1,3,(hist[2],"spam"))] ) + assert list(gothist) == [(1, 3, (hist[2], "spam"))] # Cross testing: check that magic %save can get previous session. testfilename = (tmp_path / "test.py").resolve() ip.magic("save " + str(testfilename) + " ~1/1-3") - with io.open(testfilename, encoding='utf-8') as testfile: - nt.assert_equal(testfile.read(), - u"# coding: utf-8\n" + u"\n".join(hist)+u"\n") + with io.open(testfilename, encoding="utf-8") as testfile: + assert testfile.read() == "# coding: utf-8\n" + "\n".join(hist) + "\n" # Duplicate line numbers - check that it doesn't crash, and # gets a new session ip.history_manager.store_inputs(1, "rogue") ip.history_manager.writeout_cache() - nt.assert_equal(ip.history_manager.session_number, 3) + assert ip.history_manager.session_number == 3 finally: # Ensure saving thread is shut down before we try to clean up the files ip.history_manager.save_thread.stop() @@ -158,14 +153,14 @@ def test_extract_hist_ranges(): (-7, 1, 6), (-10, 1, None)] actual = list(extract_hist_ranges(instr)) - nt.assert_equal(actual, expected) + assert actual == expected def test_extract_hist_ranges_empty_str(): instr = "" expected = [(0, 1, None)] # 0 == current session, None == to end actual = list(extract_hist_ranges(instr)) - nt.assert_equal(actual, expected) + assert actual == expected def test_magic_rerun(): @@ -173,14 +168,14 @@ def test_magic_rerun(): ip = get_ipython() ip.run_cell("a = 10", store_history=True) ip.run_cell("a += 1", store_history=True) - nt.assert_equal(ip.user_ns["a"], 11) + assert ip.user_ns["a"] == 11 ip.run_cell("%rerun", store_history=True) - nt.assert_equal(ip.user_ns["a"], 12) + assert ip.user_ns["a"] == 12 def test_timestamp_type(): ip = get_ipython() info = ip.history_manager.get_session_info() - nt.assert_true(isinstance(info[1], datetime)) + assert isinstance(info[1], datetime) def test_hist_file_config(): cfg = Config() @@ -188,7 +183,7 @@ def test_hist_file_config(): cfg.HistoryManager.hist_file = Path(tfile.name) try: hm = HistoryManager(shell=get_ipython(), config=cfg) - nt.assert_equal(hm.hist_file, cfg.HistoryManager.hist_file) + assert hm.hist_file == cfg.HistoryManager.hist_file finally: try: Path(tfile.name).unlink() @@ -210,14 +205,14 @@ def test_histmanager_disabled(): cfg.HistoryManager.hist_file = hist_file try: ip.history_manager = HistoryManager(shell=ip, config=cfg) - hist = [u'a=1', u'def f():\n test = 1\n return test', u"b='€Æ¾÷ß'"] + hist = ["a=1", "def f():\n test = 1\n return test", "b='€Æ¾÷ß'"] for i, h in enumerate(hist, start=1): ip.history_manager.store_inputs(i, h) - nt.assert_equal(ip.history_manager.input_hist_raw, [''] + hist) + assert ip.history_manager.input_hist_raw == [""] + hist ip.history_manager.reset() ip.history_manager.end_session() finally: ip.history_manager = hist_manager_ori # hist_file should not be created - nt.assert_false(hist_file.exists()) + assert hist_file.exists() is False