diff --git a/IPython/core/tests/test_alias.py b/IPython/core/tests/test_alias.py index 6ec8278..90971de 100644 --- a/IPython/core/tests/test_alias.py +++ b/IPython/core/tests/test_alias.py @@ -38,7 +38,8 @@ def test_alias_args_error(): with capture_output() as cap: _ip.run_cell('parts 1') - assert cap.stderr.split(':')[0] == 'UsageError' + assert cap.stderr.split(":")[0] == "UsageError" + def test_alias_args_commented(): """Check that alias correctly ignores 'commented out' args""" diff --git a/IPython/core/tests/test_compilerop.py b/IPython/core/tests/test_compilerop.py index ba039fe..aa531b8 100644 --- a/IPython/core/tests/test_compilerop.py +++ b/IPython/core/tests/test_compilerop.py @@ -30,13 +30,13 @@ from IPython.core import compilerop def test_code_name(): code = 'x=1' name = compilerop.code_name(code) - assert name.startswith('>> for a in range(5): @@ -40,8 +41,9 @@ for a in range(5): def test_classic_prompt(): for sample, expected in [CLASSIC_PROMPT, CLASSIC_PROMPT_L2]: - assert (ipt2.classic_prompt(sample.splitlines(keepends=True)) == - expected.splitlines(keepends=True)) + assert ipt2.classic_prompt( + sample.splitlines(keepends=True) + ) == expected.splitlines(keepends=True) IPYTHON_PROMPT = ("""\ In [1]: for a in range(5): @@ -100,9 +102,9 @@ def test_ipython_prompt(): IPYTHON_PROMPT_VI_INS, IPYTHON_PROMPT_VI_NAV, ]: - assert ( - ipt2.ipython_prompt(sample.splitlines(keepends=True)) == - expected.splitlines(keepends=True)) + assert ipt2.ipython_prompt( + sample.splitlines(keepends=True) + ) == expected.splitlines(keepends=True) INDENT_SPACES = ("""\ @@ -123,8 +125,9 @@ if True: def test_leading_indent(): for sample, expected in [INDENT_SPACES, INDENT_TABS]: - assert (ipt2.leading_indent(sample.splitlines(keepends=True)) == - expected.splitlines(keepends=True)) + assert ipt2.leading_indent( + sample.splitlines(keepends=True) + ) == expected.splitlines(keepends=True) LEADING_EMPTY_LINES = ("""\ \t @@ -150,9 +153,9 @@ ONLY_EMPTY_LINES = ("""\ def test_leading_empty_lines(): for sample, expected in [LEADING_EMPTY_LINES, ONLY_EMPTY_LINES]: - assert ( - ipt2.leading_empty_lines(sample.splitlines(keepends=True)) == - expected.splitlines(keepends=True)) + assert ipt2.leading_empty_lines( + sample.splitlines(keepends=True) + ) == expected.splitlines(keepends=True) CRLF_MAGIC = ([ "%%ls\r\n" diff --git a/IPython/core/tests/test_iplib.py b/IPython/core/tests/test_iplib.py index 5e1fc85..6804c2b 100644 --- a/IPython/core/tests/test_iplib.py +++ b/IPython/core/tests/test_iplib.py @@ -87,35 +87,36 @@ ZeroDivisionError: ... def doctest_tb_verbose(): """ -In [5]: xmode verbose -Exception reporting mode: Verbose + In [5]: xmode verbose + Exception reporting mode: Verbose + + In [6]: run simpleerr.py + --------------------------------------------------------------------------- + ZeroDivisionError Traceback (most recent call last) + + ... in + 29 except IndexError: + 30 mode = 'div' + ---> 32 bar(mode) + mode = 'div' + + ... in bar(mode='div') + 14 "bar" + 15 if mode=='div': + ---> 16 div0() + 17 elif mode=='exit': + 18 try: + + ... in div0() + 6 x = 1 + 7 y = 0 + ----> 8 x/y + x = 1 + y = 0 + + ZeroDivisionError: ... + """ -In [6]: run simpleerr.py ---------------------------------------------------------------------------- -ZeroDivisionError Traceback (most recent call last) - -... in - 29 except IndexError: - 30 mode = 'div' ----> 32 bar(mode) - mode = 'div' - -... in bar(mode='div') - 14 "bar" - 15 if mode=='div': ----> 16 div0() - 17 elif mode=='exit': - 18 try: - -... in div0() - 6 x = 1 - 7 y = 0 -----> 8 x/y - x = 1 - y = 0 - -ZeroDivisionError: ... - """ # TODO : Marc 2021 – this seem to fail due # to upstream changes in CI for whatever reason. @@ -206,11 +207,13 @@ ZeroDivisionError: ... def test_run_cell(): import textwrap - ip.run_cell('a = 10\na+=1') - ip.run_cell('assert a == 11\nassert 1') - assert ip.user_ns['a'] == 11 - complex = textwrap.dedent(""" + ip.run_cell("a = 10\na+=1") + ip.run_cell("assert a == 11\nassert 1") + + assert ip.user_ns["a"] == 11 + complex = textwrap.dedent( + """ if 1: print "hello" if 1: @@ -232,7 +235,7 @@ def test_run_cell(): def test_db(): """Test the internal database used for variable persistence.""" - ip.db['__unittest_'] = 12 - assert ip.db['__unittest_'] == 12 - del ip.db['__unittest_'] - assert '__unittest_' not in ip.db + ip.db["__unittest_"] = 12 + assert ip.db["__unittest_"] == 12 + del ip.db["__unittest_"] + assert "__unittest_" not in ip.db diff --git a/IPython/core/tests/test_logger.py b/IPython/core/tests/test_logger.py index 66d7ed7..e53385f 100644 --- a/IPython/core/tests/test_logger.py +++ b/IPython/core/tests/test_logger.py @@ -12,8 +12,8 @@ def test_logstart_inaccessible_file(): except IOError: pass else: - assert False # The try block should never pass. - + assert False # The try block should never pass. + try: _ip.run_cell("a=1") # Check it doesn't try to log this finally: diff --git a/IPython/core/tests/test_magic_arguments.py b/IPython/core/tests/test_magic_arguments.py index 66989cd..62946dc 100644 --- a/IPython/core/tests/test_magic_arguments.py +++ b/IPython/core/tests/test_magic_arguments.py @@ -74,45 +74,62 @@ def foo(self, args): def test_magic_arguments(): - assert magic_foo1.__doc__ == '::\n\n %foo1 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n' - assert getattr(magic_foo1, 'argcmd_name', None) == None - assert real_name(magic_foo1) == 'foo1' - assert magic_foo1(None, '') == argparse.Namespace(foo=None) - assert hasattr(magic_foo1, 'has_arguments') - - assert magic_foo2.__doc__ == '::\n\n %foo2\n\n A docstring.\n' - assert getattr(magic_foo2, 'argcmd_name', None) == None - assert real_name(magic_foo2) == 'foo2' - assert magic_foo2(None, '') == argparse.Namespace() - assert hasattr(magic_foo2, 'has_arguments') - - assert magic_foo3.__doc__ == '::\n\n %foo3 [-f FOO] [-b BAR] [-z BAZ]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n\nGroup:\n -b BAR, --bar BAR a grouped argument\n\nSecond Group:\n -z BAZ, --baz BAZ another grouped argument\n' - assert getattr(magic_foo3, 'argcmd_name', None) == None - assert real_name(magic_foo3) == 'foo3' - assert (magic_foo3(None, '') == - argparse.Namespace(bar=None, baz=None, foo=None)) - assert hasattr(magic_foo3, 'has_arguments') - - assert magic_foo4.__doc__ == '::\n\n %foo4 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n' - assert getattr(magic_foo4, 'argcmd_name', None) == None - assert real_name(magic_foo4) == 'foo4' - assert magic_foo4(None, '') == argparse.Namespace() - assert hasattr(magic_foo4, 'has_arguments') - - assert magic_foo5.__doc__ == '::\n\n %frobnicate [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n' - assert getattr(magic_foo5, 'argcmd_name', None) == 'frobnicate' - assert real_name(magic_foo5) == 'frobnicate' - assert magic_foo5(None, '') == argparse.Namespace(foo=None) - assert hasattr(magic_foo5, 'has_arguments') - - assert magic_magic_foo.__doc__ == '::\n\n %magic_foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n' - assert getattr(magic_magic_foo, 'argcmd_name', None) == None - assert real_name(magic_magic_foo) == 'magic_foo' - assert magic_magic_foo(None, '') == argparse.Namespace(foo=None) - assert hasattr(magic_magic_foo, 'has_arguments') - - assert foo.__doc__ == '::\n\n %foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n' - assert getattr(foo, 'argcmd_name', None) == None - assert real_name(foo) == 'foo' - assert foo(None, '') == argparse.Namespace(foo=None) - assert hasattr(foo, 'has_arguments') + assert ( + magic_foo1.__doc__ + == "::\n\n %foo1 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n" + ) + assert getattr(magic_foo1, "argcmd_name", None) == None + assert real_name(magic_foo1) == "foo1" + assert magic_foo1(None, "") == argparse.Namespace(foo=None) + assert hasattr(magic_foo1, "has_arguments") + + assert magic_foo2.__doc__ == "::\n\n %foo2\n\n A docstring.\n" + assert getattr(magic_foo2, "argcmd_name", None) == None + assert real_name(magic_foo2) == "foo2" + assert magic_foo2(None, "") == argparse.Namespace() + assert hasattr(magic_foo2, "has_arguments") + + assert ( + magic_foo3.__doc__ + == "::\n\n %foo3 [-f FOO] [-b BAR] [-z BAZ]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n\nGroup:\n -b BAR, --bar BAR a grouped argument\n\nSecond Group:\n -z BAZ, --baz BAZ another grouped argument\n" + ) + assert getattr(magic_foo3, "argcmd_name", None) == None + assert real_name(magic_foo3) == "foo3" + assert magic_foo3(None, "") == argparse.Namespace(bar=None, baz=None, foo=None) + assert hasattr(magic_foo3, "has_arguments") + + assert ( + magic_foo4.__doc__ + == "::\n\n %foo4 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n" + ) + assert getattr(magic_foo4, "argcmd_name", None) == None + assert real_name(magic_foo4) == "foo4" + assert magic_foo4(None, "") == argparse.Namespace() + assert hasattr(magic_foo4, "has_arguments") + + assert ( + magic_foo5.__doc__ + == "::\n\n %frobnicate [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n" + ) + assert getattr(magic_foo5, "argcmd_name", None) == "frobnicate" + assert real_name(magic_foo5) == "frobnicate" + assert magic_foo5(None, "") == argparse.Namespace(foo=None) + assert hasattr(magic_foo5, "has_arguments") + + assert ( + magic_magic_foo.__doc__ + == "::\n\n %magic_foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n" + ) + assert getattr(magic_magic_foo, "argcmd_name", None) == None + assert real_name(magic_magic_foo) == "magic_foo" + assert magic_magic_foo(None, "") == argparse.Namespace(foo=None) + assert hasattr(magic_magic_foo, "has_arguments") + + assert ( + foo.__doc__ + == "::\n\n %foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n" + ) + assert getattr(foo, "argcmd_name", None) == None + assert real_name(foo) == "foo" + assert foo(None, "") == argparse.Namespace(foo=None) + assert hasattr(foo, "has_arguments") diff --git a/IPython/core/tests/test_prefilter.py b/IPython/core/tests/test_prefilter.py index 7f9a0af..91c3c86 100644 --- a/IPython/core/tests/test_prefilter.py +++ b/IPython/core/tests/test_prefilter.py @@ -32,16 +32,16 @@ def test_prefilter_shadowed(): # These should not be transformed - they are shadowed by other names for name in ['if', 'zip', 'get_ipython']: # keyword, builtin, global ip.register_magic_function(dummy_magic, magic_name=name) - res = ip.prefilter(name+' foo') - assert res == name+' foo' - del ip.magics_manager.magics['line'][name] + res = ip.prefilter(name + " foo") + assert res == name + " foo" + del ip.magics_manager.magics["line"][name] # These should be transformed for name in ['fi', 'piz', 'nohtypi_teg']: ip.register_magic_function(dummy_magic, magic_name=name) - res = ip.prefilter(name+' foo') - assert res != name+' foo' - del ip.magics_manager.magics['line'][name] + res = ip.prefilter(name + " foo") + assert res != name + " foo" + del ip.magics_manager.magics["line"][name] finally: ip.automagic = prev_automagic_state @@ -52,8 +52,8 @@ def test_autocall_binops(): f = lambda x: x ip.user_ns['f'] = f try: - assert ip.prefilter('f 1') =='f(1)' - for t in ['f +1', 'f -1']: + assert ip.prefilter("f 1") == "f(1)" + for t in ["f +1", "f -1"]: assert ip.prefilter(t) == t # Run tests again with a more permissive exclude_regexp, which will @@ -66,8 +66,8 @@ def test_autocall_binops(): ac.exclude_regexp = r'^[,&^\|\*/]|^is |^not |^in |^and |^or ' pm.sort_checkers() - assert ip.prefilter('f -1') == 'f(-1)' - assert ip.prefilter('f +1') == 'f(+1)' + assert ip.prefilter("f -1") == "f(-1)" + assert ip.prefilter("f +1") == "f(+1)" finally: pm.unregister_checker(ac) finally: @@ -121,7 +121,7 @@ def test_autocall_should_support_unicode(): ip.magic('autocall 2') ip.user_ns['π'] = lambda x: x try: - assert ip.prefilter('π 3') =='π(3)' + assert ip.prefilter("π 3") == "π(3)" finally: ip.magic('autocall 0') del ip.user_ns['π']