##// END OF EJS Templates
Merge pull request #13206 from sgaist/nose_cleanup_first_step...
Matthias Bussonnier -
r26947:24290cb1 merge
parent child
Show More
@@ -0,0 +1,16
1 # See https://pre-commit.com for more information
2 # See https://pre-commit.com/hooks.html for more hooks
3 repos:
4 - repo: https://github.com/pre-commit/pre-commit-hooks
5 rev: v3.2.0
6 hooks:
7 - id: trailing-whitespace
8 - id: end-of-file-fixer
9 - id: check-yaml
10 - id: check-added-large-files
11
12 - repo: https://github.com/akaihola/darker
13 rev: 1.3.1
14 hooks:
15 - id: darker
16
@@ -4,8 +4,6
4 import os
4 import os
5 import tempfile
5 import tempfile
6
6
7 import nose.tools as nt
8
9 from traitlets import Unicode
7 from traitlets import Unicode
10
8
11 from IPython.core.application import BaseIPythonApplication
9 from IPython.core.application import BaseIPythonApplication
@@ -65,9 +63,8 def test_cli_priority():
65 f.write("c.TestApp.test = 'config file'")
63 f.write("c.TestApp.test = 'config file'")
66
64
67 app = TestApp()
65 app = TestApp()
68 app.initialize(['--profile-dir', td])
66 app.initialize(["--profile-dir", td])
69 nt.assert_equal(app.test, 'config file')
67 assert app.test == "config file"
70 app = TestApp()
68 app = TestApp()
71 app.initialize(['--profile-dir', td, '--TestApp.test=cli'])
69 app.initialize(["--profile-dir", td, "--TestApp.test=cli"])
72 nt.assert_equal(app.test, 'cli')
70 assert app.test == "cli"
73
@@ -4,7 +4,6 Test for async helpers.
4 Should only trigger on python 3.5+ or will have syntax errors.
4 Should only trigger on python 3.5+ or will have syntax errors.
5 """
5 """
6 from itertools import chain, repeat
6 from itertools import chain, repeat
7 import nose.tools as nt
8 from textwrap import dedent, indent
7 from textwrap import dedent, indent
9 from unittest import TestCase
8 from unittest import TestCase
10 from IPython.testing.decorators import skip_without
9 from IPython.testing.decorators import skip_without
@@ -24,10 +23,10 from IPython.core.async_helpers import _should_be_async
24
23
25 class AsyncTest(TestCase):
24 class AsyncTest(TestCase):
26 def test_should_be_async(self):
25 def test_should_be_async(self):
27 nt.assert_false(_should_be_async("False"))
26 self.assertFalse(_should_be_async("False"))
28 nt.assert_true(_should_be_async("await bar()"))
27 self.assertTrue(_should_be_async("await bar()"))
29 nt.assert_true(_should_be_async("x = await bar()"))
28 self.assertTrue(_should_be_async("x = await bar()"))
30 nt.assert_false(
29 self.assertFalse(
31 _should_be_async(
30 _should_be_async(
32 dedent(
31 dedent(
33 """
32 """
@@ -298,7 +297,7 class AsyncTest(TestCase):
298 import asyncio
297 import asyncio
299 await asyncio.sleep(0)
298 await asyncio.sleep(0)
300 """)
299 """)
301 with nt.assert_raises(TypeError):
300 with self.assertRaises(TypeError):
302 res.raise_error()
301 res.raise_error()
303
302
304 @skip_without('trio')
303 @skip_without('trio')
@@ -308,7 +307,7 class AsyncTest(TestCase):
308 import trio
307 import trio
309 await trio.sleep(0)
308 await trio.sleep(0)
310 """)
309 """)
311 with nt.assert_raises(RuntimeError):
310 with self.assertRaises(RuntimeError):
312 res.raise_error()
311 res.raise_error()
313
312
314
313
@@ -11,8 +11,6 import unittest
11
11
12 from contextlib import contextmanager
12 from contextlib import contextmanager
13
13
14 import nose.tools as nt
15
16 from traitlets.config.loader import Config
14 from traitlets.config.loader import Config
17 from IPython import get_ipython
15 from IPython import get_ipython
18 from IPython.core import completer
16 from IPython.core import completer
@@ -27,7 +25,6 from IPython.core.completer import (
27 match_dict_keys,
25 match_dict_keys,
28 _deduplicate_completions,
26 _deduplicate_completions,
29 )
27 )
30 from nose.tools import assert_in, assert_not_in
31
28
32 # -----------------------------------------------------------------------------
29 # -----------------------------------------------------------------------------
33 # Test functions
30 # Test functions
@@ -150,7 +147,7 def test_protect_filename():
150 # run the actual tests
147 # run the actual tests
151 for s1, s2 in pairs:
148 for s1, s2 in pairs:
152 s1p = completer.protect_filename(s1)
149 s1p = completer.protect_filename(s1)
153 nt.assert_equal(s1p, s2)
150 assert s1p == s2
154
151
155
152
156 def check_line_split(splitter, test_specs):
153 def check_line_split(splitter, test_specs):
@@ -158,7 +155,7 def check_line_split(splitter, test_specs):
158 cursor_pos = len(part1)
155 cursor_pos = len(part1)
159 line = part1 + part2
156 line = part1 + part2
160 out = splitter.split_line(line, cursor_pos)
157 out = splitter.split_line(line, cursor_pos)
161 nt.assert_equal(out, split)
158 assert out == split
162
159
163
160
164 def test_line_split():
161 def test_line_split():
@@ -267,8 +264,8 class TestCompleter(unittest.TestCase):
267 # should be thrown and the return value should be a pair of text, list
264 # should be thrown and the return value should be a pair of text, list
268 # values.
265 # values.
269 text, matches = ip.complete(t)
266 text, matches = ip.complete(t)
270 nt.assert_true(isinstance(text, str))
267 self.assertIsInstance(text, str)
271 nt.assert_true(isinstance(matches, list))
268 self.assertIsInstance(matches, list)
272
269
273 def test_latex_completions(self):
270 def test_latex_completions(self):
274 from IPython.core.latex_symbols import latex_symbols
271 from IPython.core.latex_symbols import latex_symbols
@@ -279,16 +276,16 class TestCompleter(unittest.TestCase):
279 keys = random.sample(latex_symbols.keys(), 10)
276 keys = random.sample(latex_symbols.keys(), 10)
280 for k in keys:
277 for k in keys:
281 text, matches = ip.complete(k)
278 text, matches = ip.complete(k)
282 nt.assert_equal(text, k)
279 self.assertEqual(text, k)
283 nt.assert_equal(matches, [latex_symbols[k]])
280 self.assertEqual(matches, [latex_symbols[k]])
284 # Test a more complex line
281 # Test a more complex line
285 text, matches = ip.complete("print(\\alpha")
282 text, matches = ip.complete("print(\\alpha")
286 nt.assert_equal(text, "\\alpha")
283 self.assertEqual(text, "\\alpha")
287 nt.assert_equal(matches[0], latex_symbols["\\alpha"])
284 self.assertEqual(matches[0], latex_symbols["\\alpha"])
288 # Test multiple matching latex symbols
285 # Test multiple matching latex symbols
289 text, matches = ip.complete("\\al")
286 text, matches = ip.complete("\\al")
290 nt.assert_in("\\alpha", matches)
287 self.assertIn("\\alpha", matches)
291 nt.assert_in("\\aleph", matches)
288 self.assertIn("\\aleph", matches)
292
289
293 def test_latex_no_results(self):
290 def test_latex_no_results(self):
294 """
291 """
@@ -296,30 +293,30 class TestCompleter(unittest.TestCase):
296 """
293 """
297 ip = get_ipython()
294 ip = get_ipython()
298 text, matches = ip.Completer.latex_matches("\\really_i_should_match_nothing")
295 text, matches = ip.Completer.latex_matches("\\really_i_should_match_nothing")
299 nt.assert_equal(text, "")
296 self.assertEqual(text, "")
300 nt.assert_equal(matches, ())
297 self.assertEqual(matches, ())
301
298
302 def test_back_latex_completion(self):
299 def test_back_latex_completion(self):
303 ip = get_ipython()
300 ip = get_ipython()
304
301
305 # do not return more than 1 matches for \beta, only the latex one.
302 # do not return more than 1 matches for \beta, only the latex one.
306 name, matches = ip.complete("\\β")
303 name, matches = ip.complete("\\β")
307 nt.assert_equal(matches, ['\\beta'])
304 self.assertEqual(matches, ["\\beta"])
308
305
309 def test_back_unicode_completion(self):
306 def test_back_unicode_completion(self):
310 ip = get_ipython()
307 ip = get_ipython()
311
308
312 name, matches = ip.complete("\\Ⅴ")
309 name, matches = ip.complete("\\Ⅴ")
313 nt.assert_equal(matches, ("\\ROMAN NUMERAL FIVE",))
310 self.assertEqual(matches, ("\\ROMAN NUMERAL FIVE",))
314
311
315 def test_forward_unicode_completion(self):
312 def test_forward_unicode_completion(self):
316 ip = get_ipython()
313 ip = get_ipython()
317
314
318 name, matches = ip.complete("\\ROMAN NUMERAL FIVE")
315 name, matches = ip.complete("\\ROMAN NUMERAL FIVE")
319 nt.assert_equal(matches, ["Ⅴ"] ) # This is not a V
316 self.assertEqual(matches, ["Ⅴ"]) # This is not a V
320 nt.assert_equal(matches, ["\u2164"] ) # same as above but explicit.
317 self.assertEqual(matches, ["\u2164"]) # same as above but explicit.
321
318
322 @nt.nottest # now we have a completion for \jmath
319 @unittest.skip("now we have a completion for \jmath")
323 @decorators.knownfailureif(
320 @decorators.knownfailureif(
324 sys.platform == "win32", "Fails if there is a C:\\j... path"
321 sys.platform == "win32", "Fails if there is a C:\\j... path"
325 )
322 )
@@ -329,7 +326,7 class TestCompleter(unittest.TestCase):
329 # single ascii letter that don't have yet completions
326 # single ascii letter that don't have yet completions
330 for letter in "jJ":
327 for letter in "jJ":
331 name, matches = ip.complete("\\" + letter)
328 name, matches = ip.complete("\\" + letter)
332 nt.assert_equal(matches, [])
329 self.assertEqual(matches, [])
333
330
334 class CompletionSplitterTestCase(unittest.TestCase):
331 class CompletionSplitterTestCase(unittest.TestCase):
335 def setUp(self):
332 def setUp(self):
@@ -337,8 +334,8 class TestCompleter(unittest.TestCase):
337
334
338 def test_delim_setting(self):
335 def test_delim_setting(self):
339 self.sp.delims = " "
336 self.sp.delims = " "
340 nt.assert_equal(self.sp.delims, " ")
337 self.assertEqual(self.sp.delims, " ")
341 nt.assert_equal(self.sp._delim_expr, r"[\ ]")
338 self.assertEqual(self.sp._delim_expr, r"[\ ]")
342
339
343 def test_spaces(self):
340 def test_spaces(self):
344 """Test with only spaces as split chars."""
341 """Test with only spaces as split chars."""
@@ -348,19 +345,19 class TestCompleter(unittest.TestCase):
348
345
349 def test_has_open_quotes1(self):
346 def test_has_open_quotes1(self):
350 for s in ["'", "'''", "'hi' '"]:
347 for s in ["'", "'''", "'hi' '"]:
351 nt.assert_equal(completer.has_open_quotes(s), "'")
348 self.assertEqual(completer.has_open_quotes(s), "'")
352
349
353 def test_has_open_quotes2(self):
350 def test_has_open_quotes2(self):
354 for s in ['"', '"""', '"hi" "']:
351 for s in ['"', '"""', '"hi" "']:
355 nt.assert_equal(completer.has_open_quotes(s), '"')
352 self.assertEqual(completer.has_open_quotes(s), '"')
356
353
357 def test_has_open_quotes3(self):
354 def test_has_open_quotes3(self):
358 for s in ["''", "''' '''", "'hi' 'ipython'"]:
355 for s in ["''", "''' '''", "'hi' 'ipython'"]:
359 nt.assert_false(completer.has_open_quotes(s))
356 self.assertFalse(completer.has_open_quotes(s))
360
357
361 def test_has_open_quotes4(self):
358 def test_has_open_quotes4(self):
362 for s in ['""', '""" """', '"hi" "ipython"']:
359 for s in ['""', '""" """', '"hi" "ipython"']:
363 nt.assert_false(completer.has_open_quotes(s))
360 self.assertFalse(completer.has_open_quotes(s))
364
361
365 @decorators.knownfailureif(
362 @decorators.knownfailureif(
366 sys.platform == "win32", "abspath completions fail on Windows"
363 sys.platform == "win32", "abspath completions fail on Windows"
@@ -376,13 +373,13 class TestCompleter(unittest.TestCase):
376
373
377 # Check simple completion
374 # Check simple completion
378 c = ip.complete(prefix)[1]
375 c = ip.complete(prefix)[1]
379 nt.assert_equal(c, names)
376 self.assertEqual(c, names)
380
377
381 # Now check with a function call
378 # Now check with a function call
382 cmd = 'a = f("%s' % prefix
379 cmd = 'a = f("%s' % prefix
383 c = ip.complete(prefix, cmd)[1]
380 c = ip.complete(prefix, cmd)[1]
384 comp = [prefix + s for s in suffixes]
381 comp = [prefix + s for s in suffixes]
385 nt.assert_equal(c, comp)
382 self.assertEqual(c, comp)
386
383
387 def test_local_file_completions(self):
384 def test_local_file_completions(self):
388 ip = get_ipython()
385 ip = get_ipython()
@@ -395,13 +392,13 class TestCompleter(unittest.TestCase):
395
392
396 # Check simple completion
393 # Check simple completion
397 c = ip.complete(prefix)[1]
394 c = ip.complete(prefix)[1]
398 nt.assert_equal(c, names)
395 self.assertEqual(c, names)
399
396
400 # Now check with a function call
397 # Now check with a function call
401 cmd = 'a = f("%s' % prefix
398 cmd = 'a = f("%s' % prefix
402 c = ip.complete(prefix, cmd)[1]
399 c = ip.complete(prefix, cmd)[1]
403 comp = {prefix + s for s in suffixes}
400 comp = {prefix + s for s in suffixes}
404 nt.assert_true(comp.issubset(set(c)))
401 self.assertTrue(comp.issubset(set(c)))
405
402
406 def test_quoted_file_completions(self):
403 def test_quoted_file_completions(self):
407 ip = get_ipython()
404 ip = get_ipython()
@@ -417,21 +414,21 class TestCompleter(unittest.TestCase):
417 c = ip.Completer._complete(
414 c = ip.Completer._complete(
418 cursor_line=0, cursor_pos=len(text), full_text=text
415 cursor_line=0, cursor_pos=len(text), full_text=text
419 )[1]
416 )[1]
420 nt.assert_equal(c, [escaped])
417 self.assertEqual(c, [escaped])
421
418
422 # Double quote requires no escape
419 # Double quote requires no escape
423 text = 'open("foo'
420 text = 'open("foo'
424 c = ip.Completer._complete(
421 c = ip.Completer._complete(
425 cursor_line=0, cursor_pos=len(text), full_text=text
422 cursor_line=0, cursor_pos=len(text), full_text=text
426 )[1]
423 )[1]
427 nt.assert_equal(c, [name])
424 self.assertEqual(c, [name])
428
425
429 # No quote requires an escape
426 # No quote requires an escape
430 text = "%ls foo"
427 text = "%ls foo"
431 c = ip.Completer._complete(
428 c = ip.Completer._complete(
432 cursor_line=0, cursor_pos=len(text), full_text=text
429 cursor_line=0, cursor_pos=len(text), full_text=text
433 )[1]
430 )[1]
434 nt.assert_equal(c, [escaped])
431 self.assertEqual(c, [escaped])
435
432
436 def test_all_completions_dups(self):
433 def test_all_completions_dups(self):
437 """
434 """
@@ -537,18 +534,18 class TestCompleter(unittest.TestCase):
537 ip = get_ipython()
534 ip = get_ipython()
538 ip.ex("a=list(range(5))")
535 ip.ex("a=list(range(5))")
539 _, c = ip.complete(".", line="a[0].")
536 _, c = ip.complete(".", line="a[0].")
540 nt.assert_false(".real" in c, "Shouldn't have completed on a[0]: %s" % c)
537 self.assertFalse(".real" in c, "Shouldn't have completed on a[0]: %s" % c)
541
538
542 def _(line, cursor_pos, expect, message, completion):
539 def _(line, cursor_pos, expect, message, completion):
543 with greedy_completion(), provisionalcompleter():
540 with greedy_completion(), provisionalcompleter():
544 ip.Completer.use_jedi = False
541 ip.Completer.use_jedi = False
545 _, c = ip.complete(".", line=line, cursor_pos=cursor_pos)
542 _, c = ip.complete(".", line=line, cursor_pos=cursor_pos)
546 nt.assert_in(expect, c, message % c)
543 self.assertIn(expect, c, message % c)
547
544
548 ip.Completer.use_jedi = True
545 ip.Completer.use_jedi = True
549 with provisionalcompleter():
546 with provisionalcompleter():
550 completions = ip.Completer.completions(line, cursor_pos)
547 completions = ip.Completer.completions(line, cursor_pos)
551 nt.assert_in(completion, completions)
548 self.assertIn(completion, completions)
552
549
553 with provisionalcompleter():
550 with provisionalcompleter():
554 yield _, "a[0].", 5, "a[0].real", "Should have completed on a[0].: %s", Completion(
551 yield _, "a[0].", 5, "a[0].real", "Should have completed on a[0].: %s", Completion(
@@ -575,13 +572,13 class TestCompleter(unittest.TestCase):
575 with provisionalcompleter():
572 with provisionalcompleter():
576 c.use_jedi = False
573 c.use_jedi = False
577 s, matches = c.complete("ip.")
574 s, matches = c.complete("ip.")
578 nt.assert_in("ip.__str__", matches)
575 self.assertIn("ip.__str__", matches)
579 nt.assert_in("ip._hidden_attr", matches)
576 self.assertIn("ip._hidden_attr", matches)
580
577
581 # c.use_jedi = True
578 # c.use_jedi = True
582 # completions = set(c.completions('ip.', 3))
579 # completions = set(c.completions('ip.', 3))
583 # nt.assert_in(Completion(3, 3, '__str__'), completions)
580 # self.assertIn(Completion(3, 3, '__str__'), completions)
584 # nt.assert_in(Completion(3,3, "_hidden_attr"), completions)
581 # self.assertIn(Completion(3,3, "_hidden_attr"), completions)
585
582
586 cfg = Config()
583 cfg = Config()
587 cfg.IPCompleter.omit__names = 1
584 cfg.IPCompleter.omit__names = 1
@@ -589,13 +586,13 class TestCompleter(unittest.TestCase):
589 with provisionalcompleter():
586 with provisionalcompleter():
590 c.use_jedi = False
587 c.use_jedi = False
591 s, matches = c.complete("ip.")
588 s, matches = c.complete("ip.")
592 nt.assert_not_in("ip.__str__", matches)
589 self.assertNotIn("ip.__str__", matches)
593 # nt.assert_in('ip._hidden_attr', matches)
590 # self.assertIn('ip._hidden_attr', matches)
594
591
595 # c.use_jedi = True
592 # c.use_jedi = True
596 # completions = set(c.completions('ip.', 3))
593 # completions = set(c.completions('ip.', 3))
597 # nt.assert_not_in(Completion(3,3,'__str__'), completions)
594 # self.assertNotIn(Completion(3,3,'__str__'), completions)
598 # nt.assert_in(Completion(3,3, "_hidden_attr"), completions)
595 # self.assertIn(Completion(3,3, "_hidden_attr"), completions)
599
596
600 cfg = Config()
597 cfg = Config()
601 cfg.IPCompleter.omit__names = 2
598 cfg.IPCompleter.omit__names = 2
@@ -603,22 +600,22 class TestCompleter(unittest.TestCase):
603 with provisionalcompleter():
600 with provisionalcompleter():
604 c.use_jedi = False
601 c.use_jedi = False
605 s, matches = c.complete("ip.")
602 s, matches = c.complete("ip.")
606 nt.assert_not_in("ip.__str__", matches)
603 self.assertNotIn("ip.__str__", matches)
607 nt.assert_not_in("ip._hidden_attr", matches)
604 self.assertNotIn("ip._hidden_attr", matches)
608
605
609 # c.use_jedi = True
606 # c.use_jedi = True
610 # completions = set(c.completions('ip.', 3))
607 # completions = set(c.completions('ip.', 3))
611 # nt.assert_not_in(Completion(3,3,'__str__'), completions)
608 # self.assertNotIn(Completion(3,3,'__str__'), completions)
612 # nt.assert_not_in(Completion(3,3, "_hidden_attr"), completions)
609 # self.assertNotIn(Completion(3,3, "_hidden_attr"), completions)
613
610
614 with provisionalcompleter():
611 with provisionalcompleter():
615 c.use_jedi = False
612 c.use_jedi = False
616 s, matches = c.complete("ip._x.")
613 s, matches = c.complete("ip._x.")
617 nt.assert_in("ip._x.keys", matches)
614 self.assertIn("ip._x.keys", matches)
618
615
619 # c.use_jedi = True
616 # c.use_jedi = True
620 # completions = set(c.completions('ip._x.', 6))
617 # completions = set(c.completions('ip._x.', 6))
621 # nt.assert_in(Completion(6,6, "keys"), completions)
618 # self.assertIn(Completion(6,6, "keys"), completions)
622
619
623 del ip._hidden_attr
620 del ip._hidden_attr
624 del ip._x
621 del ip._x
@@ -636,21 +633,21 class TestCompleter(unittest.TestCase):
636 cfg.IPCompleter.limit_to__all__ = False
633 cfg.IPCompleter.limit_to__all__ = False
637 c.update_config(cfg)
634 c.update_config(cfg)
638 s, matches = c.complete("d.")
635 s, matches = c.complete("d.")
639 nt.assert_in("d.x", matches)
636 self.assertIn("d.x", matches)
640
637
641 def test_get__all__entries_ok(self):
638 def test_get__all__entries_ok(self):
642 class A:
639 class A:
643 __all__ = ["x", 1]
640 __all__ = ["x", 1]
644
641
645 words = completer.get__all__entries(A())
642 words = completer.get__all__entries(A())
646 nt.assert_equal(words, ["x"])
643 self.assertEqual(words, ["x"])
647
644
648 def test_get__all__entries_no__all__ok(self):
645 def test_get__all__entries_no__all__ok(self):
649 class A:
646 class A:
650 pass
647 pass
651
648
652 words = completer.get__all__entries(A())
649 words = completer.get__all__entries(A())
653 nt.assert_equal(words, [])
650 self.assertEqual(words, [])
654
651
655 def test_func_kw_completions(self):
652 def test_func_kw_completions(self):
656 ip = get_ipython()
653 ip = get_ipython()
@@ -658,39 +655,39 class TestCompleter(unittest.TestCase):
658 c.use_jedi = False
655 c.use_jedi = False
659 ip.ex("def myfunc(a=1,b=2): return a+b")
656 ip.ex("def myfunc(a=1,b=2): return a+b")
660 s, matches = c.complete(None, "myfunc(1,b")
657 s, matches = c.complete(None, "myfunc(1,b")
661 nt.assert_in("b=", matches)
658 self.assertIn("b=", matches)
662 # Simulate completing with cursor right after b (pos==10):
659 # Simulate completing with cursor right after b (pos==10):
663 s, matches = c.complete(None, "myfunc(1,b)", 10)
660 s, matches = c.complete(None, "myfunc(1,b)", 10)
664 nt.assert_in("b=", matches)
661 self.assertIn("b=", matches)
665 s, matches = c.complete(None, 'myfunc(a="escaped\\")string",b')
662 s, matches = c.complete(None, 'myfunc(a="escaped\\")string",b')
666 nt.assert_in("b=", matches)
663 self.assertIn("b=", matches)
667 # builtin function
664 # builtin function
668 s, matches = c.complete(None, "min(k, k")
665 s, matches = c.complete(None, "min(k, k")
669 nt.assert_in("key=", matches)
666 self.assertIn("key=", matches)
670
667
671 def test_default_arguments_from_docstring(self):
668 def test_default_arguments_from_docstring(self):
672 ip = get_ipython()
669 ip = get_ipython()
673 c = ip.Completer
670 c = ip.Completer
674 kwd = c._default_arguments_from_docstring("min(iterable[, key=func]) -> value")
671 kwd = c._default_arguments_from_docstring("min(iterable[, key=func]) -> value")
675 nt.assert_equal(kwd, ["key"])
672 self.assertEqual(kwd, ["key"])
676 # with cython type etc
673 # with cython type etc
677 kwd = c._default_arguments_from_docstring(
674 kwd = c._default_arguments_from_docstring(
678 "Minuit.migrad(self, int ncall=10000, resume=True, int nsplit=1)\n"
675 "Minuit.migrad(self, int ncall=10000, resume=True, int nsplit=1)\n"
679 )
676 )
680 nt.assert_equal(kwd, ["ncall", "resume", "nsplit"])
677 self.assertEqual(kwd, ["ncall", "resume", "nsplit"])
681 # white spaces
678 # white spaces
682 kwd = c._default_arguments_from_docstring(
679 kwd = c._default_arguments_from_docstring(
683 "\n Minuit.migrad(self, int ncall=10000, resume=True, int nsplit=1)\n"
680 "\n Minuit.migrad(self, int ncall=10000, resume=True, int nsplit=1)\n"
684 )
681 )
685 nt.assert_equal(kwd, ["ncall", "resume", "nsplit"])
682 self.assertEqual(kwd, ["ncall", "resume", "nsplit"])
686
683
687 def test_line_magics(self):
684 def test_line_magics(self):
688 ip = get_ipython()
685 ip = get_ipython()
689 c = ip.Completer
686 c = ip.Completer
690 s, matches = c.complete(None, "lsmag")
687 s, matches = c.complete(None, "lsmag")
691 nt.assert_in("%lsmagic", matches)
688 self.assertIn("%lsmagic", matches)
692 s, matches = c.complete(None, "%lsmag")
689 s, matches = c.complete(None, "%lsmag")
693 nt.assert_in("%lsmagic", matches)
690 self.assertIn("%lsmagic", matches)
694
691
695 def test_cell_magics(self):
692 def test_cell_magics(self):
696 from IPython.core.magic import register_cell_magic
693 from IPython.core.magic import register_cell_magic
@@ -703,9 +700,9 class TestCompleter(unittest.TestCase):
703 c = ip.Completer
700 c = ip.Completer
704
701
705 s, matches = c.complete(None, "_foo_ce")
702 s, matches = c.complete(None, "_foo_ce")
706 nt.assert_in("%%_foo_cellm", matches)
703 self.assertIn("%%_foo_cellm", matches)
707 s, matches = c.complete(None, "%%_foo_ce")
704 s, matches = c.complete(None, "%%_foo_ce")
708 nt.assert_in("%%_foo_cellm", matches)
705 self.assertIn("%%_foo_cellm", matches)
709
706
710 def test_line_cell_magics(self):
707 def test_line_cell_magics(self):
711 from IPython.core.magic import register_line_cell_magic
708 from IPython.core.magic import register_line_cell_magic
@@ -722,14 +719,14 class TestCompleter(unittest.TestCase):
722 # and this will show a difference if the same name is both a line and cell
719 # and this will show a difference if the same name is both a line and cell
723 # magic.
720 # magic.
724 s, matches = c.complete(None, "_bar_ce")
721 s, matches = c.complete(None, "_bar_ce")
725 nt.assert_in("%_bar_cellm", matches)
722 self.assertIn("%_bar_cellm", matches)
726 nt.assert_in("%%_bar_cellm", matches)
723 self.assertIn("%%_bar_cellm", matches)
727 s, matches = c.complete(None, "%_bar_ce")
724 s, matches = c.complete(None, "%_bar_ce")
728 nt.assert_in("%_bar_cellm", matches)
725 self.assertIn("%_bar_cellm", matches)
729 nt.assert_in("%%_bar_cellm", matches)
726 self.assertIn("%%_bar_cellm", matches)
730 s, matches = c.complete(None, "%%_bar_ce")
727 s, matches = c.complete(None, "%%_bar_ce")
731 nt.assert_not_in("%_bar_cellm", matches)
728 self.assertNotIn("%_bar_cellm", matches)
732 nt.assert_in("%%_bar_cellm", matches)
729 self.assertIn("%%_bar_cellm", matches)
733
730
734 def test_magic_completion_order(self):
731 def test_magic_completion_order(self):
735 ip = get_ipython()
732 ip = get_ipython()
@@ -737,7 +734,7 class TestCompleter(unittest.TestCase):
737
734
738 # Test ordering of line and cell magics.
735 # Test ordering of line and cell magics.
739 text, matches = c.complete("timeit")
736 text, matches = c.complete("timeit")
740 nt.assert_equal(matches, ["%timeit", "%%timeit"])
737 self.assertEqual(matches, ["%timeit", "%%timeit"])
741
738
742 def test_magic_completion_shadowing(self):
739 def test_magic_completion_shadowing(self):
743 ip = get_ipython()
740 ip = get_ipython()
@@ -746,18 +743,18 class TestCompleter(unittest.TestCase):
746
743
747 # Before importing matplotlib, %matplotlib magic should be the only option.
744 # Before importing matplotlib, %matplotlib magic should be the only option.
748 text, matches = c.complete("mat")
745 text, matches = c.complete("mat")
749 nt.assert_equal(matches, ["%matplotlib"])
746 self.assertEqual(matches, ["%matplotlib"])
750
747
751 # The newly introduced name should shadow the magic.
748 # The newly introduced name should shadow the magic.
752 ip.run_cell("matplotlib = 1")
749 ip.run_cell("matplotlib = 1")
753 text, matches = c.complete("mat")
750 text, matches = c.complete("mat")
754 nt.assert_equal(matches, ["matplotlib"])
751 self.assertEqual(matches, ["matplotlib"])
755
752
756 # After removing matplotlib from namespace, the magic should again be
753 # After removing matplotlib from namespace, the magic should again be
757 # the only option.
754 # the only option.
758 del ip.user_ns["matplotlib"]
755 del ip.user_ns["matplotlib"]
759 text, matches = c.complete("mat")
756 text, matches = c.complete("mat")
760 nt.assert_equal(matches, ["%matplotlib"])
757 self.assertEqual(matches, ["%matplotlib"])
761
758
762 def test_magic_completion_shadowing_explicit(self):
759 def test_magic_completion_shadowing_explicit(self):
763 """
760 """
@@ -769,62 +766,62 class TestCompleter(unittest.TestCase):
769
766
770 # Before importing matplotlib, %matplotlib magic should be the only option.
767 # Before importing matplotlib, %matplotlib magic should be the only option.
771 text, matches = c.complete("%mat")
768 text, matches = c.complete("%mat")
772 nt.assert_equal(matches, ["%matplotlib"])
769 self.assertEqual(matches, ["%matplotlib"])
773
770
774 ip.run_cell("matplotlib = 1")
771 ip.run_cell("matplotlib = 1")
775
772
776 # After removing matplotlib from namespace, the magic should still be
773 # After removing matplotlib from namespace, the magic should still be
777 # the only option.
774 # the only option.
778 text, matches = c.complete("%mat")
775 text, matches = c.complete("%mat")
779 nt.assert_equal(matches, ["%matplotlib"])
776 self.assertEqual(matches, ["%matplotlib"])
780
777
781 def test_magic_config(self):
778 def test_magic_config(self):
782 ip = get_ipython()
779 ip = get_ipython()
783 c = ip.Completer
780 c = ip.Completer
784
781
785 s, matches = c.complete(None, "conf")
782 s, matches = c.complete(None, "conf")
786 nt.assert_in("%config", matches)
783 self.assertIn("%config", matches)
787 s, matches = c.complete(None, "conf")
784 s, matches = c.complete(None, "conf")
788 nt.assert_not_in("AliasManager", matches)
785 self.assertNotIn("AliasManager", matches)
789 s, matches = c.complete(None, "config ")
786 s, matches = c.complete(None, "config ")
790 nt.assert_in("AliasManager", matches)
787 self.assertIn("AliasManager", matches)
791 s, matches = c.complete(None, "%config ")
788 s, matches = c.complete(None, "%config ")
792 nt.assert_in("AliasManager", matches)
789 self.assertIn("AliasManager", matches)
793 s, matches = c.complete(None, "config Ali")
790 s, matches = c.complete(None, "config Ali")
794 nt.assert_list_equal(["AliasManager"], matches)
791 self.assertListEqual(["AliasManager"], matches)
795 s, matches = c.complete(None, "%config Ali")
792 s, matches = c.complete(None, "%config Ali")
796 nt.assert_list_equal(["AliasManager"], matches)
793 self.assertListEqual(["AliasManager"], matches)
797 s, matches = c.complete(None, "config AliasManager")
794 s, matches = c.complete(None, "config AliasManager")
798 nt.assert_list_equal(["AliasManager"], matches)
795 self.assertListEqual(["AliasManager"], matches)
799 s, matches = c.complete(None, "%config AliasManager")
796 s, matches = c.complete(None, "%config AliasManager")
800 nt.assert_list_equal(["AliasManager"], matches)
797 self.assertListEqual(["AliasManager"], matches)
801 s, matches = c.complete(None, "config AliasManager.")
798 s, matches = c.complete(None, "config AliasManager.")
802 nt.assert_in("AliasManager.default_aliases", matches)
799 self.assertIn("AliasManager.default_aliases", matches)
803 s, matches = c.complete(None, "%config AliasManager.")
800 s, matches = c.complete(None, "%config AliasManager.")
804 nt.assert_in("AliasManager.default_aliases", matches)
801 self.assertIn("AliasManager.default_aliases", matches)
805 s, matches = c.complete(None, "config AliasManager.de")
802 s, matches = c.complete(None, "config AliasManager.de")
806 nt.assert_list_equal(["AliasManager.default_aliases"], matches)
803 self.assertListEqual(["AliasManager.default_aliases"], matches)
807 s, matches = c.complete(None, "config AliasManager.de")
804 s, matches = c.complete(None, "config AliasManager.de")
808 nt.assert_list_equal(["AliasManager.default_aliases"], matches)
805 self.assertListEqual(["AliasManager.default_aliases"], matches)
809
806
810 def test_magic_color(self):
807 def test_magic_color(self):
811 ip = get_ipython()
808 ip = get_ipython()
812 c = ip.Completer
809 c = ip.Completer
813
810
814 s, matches = c.complete(None, "colo")
811 s, matches = c.complete(None, "colo")
815 nt.assert_in("%colors", matches)
812 self.assertIn("%colors", matches)
816 s, matches = c.complete(None, "colo")
813 s, matches = c.complete(None, "colo")
817 nt.assert_not_in("NoColor", matches)
814 self.assertNotIn("NoColor", matches)
818 s, matches = c.complete(None, "%colors") # No trailing space
815 s, matches = c.complete(None, "%colors") # No trailing space
819 nt.assert_not_in("NoColor", matches)
816 self.assertNotIn("NoColor", matches)
820 s, matches = c.complete(None, "colors ")
817 s, matches = c.complete(None, "colors ")
821 nt.assert_in("NoColor", matches)
818 self.assertIn("NoColor", matches)
822 s, matches = c.complete(None, "%colors ")
819 s, matches = c.complete(None, "%colors ")
823 nt.assert_in("NoColor", matches)
820 self.assertIn("NoColor", matches)
824 s, matches = c.complete(None, "colors NoCo")
821 s, matches = c.complete(None, "colors NoCo")
825 nt.assert_list_equal(["NoColor"], matches)
822 self.assertListEqual(["NoColor"], matches)
826 s, matches = c.complete(None, "%colors NoCo")
823 s, matches = c.complete(None, "%colors NoCo")
827 nt.assert_list_equal(["NoColor"], matches)
824 self.assertListEqual(["NoColor"], matches)
828
825
829 def test_match_dict_keys(self):
826 def test_match_dict_keys(self):
830 """
827 """
@@ -884,34 +881,34 class TestCompleter(unittest.TestCase):
884
881
885 # check completion at different stages
882 # check completion at different stages
886 _, matches = complete(line_buffer="d[")
883 _, matches = complete(line_buffer="d[")
887 nt.assert_in("'abc'", matches)
884 self.assertIn("'abc'", matches)
888 nt.assert_not_in("'abc']", matches)
885 self.assertNotIn("'abc']", matches)
889
886
890 _, matches = complete(line_buffer="d['")
887 _, matches = complete(line_buffer="d['")
891 nt.assert_in("abc", matches)
888 self.assertIn("abc", matches)
892 nt.assert_not_in("abc']", matches)
889 self.assertNotIn("abc']", matches)
893
890
894 _, matches = complete(line_buffer="d['a")
891 _, matches = complete(line_buffer="d['a")
895 nt.assert_in("abc", matches)
892 self.assertIn("abc", matches)
896 nt.assert_not_in("abc']", matches)
893 self.assertNotIn("abc']", matches)
897
894
898 # check use of different quoting
895 # check use of different quoting
899 _, matches = complete(line_buffer='d["')
896 _, matches = complete(line_buffer='d["')
900 nt.assert_in("abc", matches)
897 self.assertIn("abc", matches)
901 nt.assert_not_in('abc"]', matches)
898 self.assertNotIn('abc"]', matches)
902
899
903 _, matches = complete(line_buffer='d["a')
900 _, matches = complete(line_buffer='d["a')
904 nt.assert_in("abc", matches)
901 self.assertIn("abc", matches)
905 nt.assert_not_in('abc"]', matches)
902 self.assertNotIn('abc"]', matches)
906
903
907 # check sensitivity to following context
904 # check sensitivity to following context
908 _, matches = complete(line_buffer="d[]", cursor_pos=2)
905 _, matches = complete(line_buffer="d[]", cursor_pos=2)
909 nt.assert_in("'abc'", matches)
906 self.assertIn("'abc'", matches)
910
907
911 _, matches = complete(line_buffer="d['']", cursor_pos=3)
908 _, matches = complete(line_buffer="d['']", cursor_pos=3)
912 nt.assert_in("abc", matches)
909 self.assertIn("abc", matches)
913 nt.assert_not_in("abc'", matches)
910 self.assertNotIn("abc'", matches)
914 nt.assert_not_in("abc']", matches)
911 self.assertNotIn("abc']", matches)
915
912
916 # check multiple solutions are correctly returned and that noise is not
913 # check multiple solutions are correctly returned and that noise is not
917 ip.user_ns["d"] = {
914 ip.user_ns["d"] = {
@@ -925,111 +922,110 class TestCompleter(unittest.TestCase):
925 }
922 }
926
923
927 _, matches = complete(line_buffer="d['a")
924 _, matches = complete(line_buffer="d['a")
928 nt.assert_in("abc", matches)
925 self.assertIn("abc", matches)
929 nt.assert_in("abd", matches)
926 self.assertIn("abd", matches)
930 nt.assert_not_in("bad", matches)
927 self.assertNotIn("bad", matches)
931 nt.assert_not_in("abe", matches)
928 self.assertNotIn("abe", matches)
932 nt.assert_not_in("abf", matches)
929 self.assertNotIn("abf", matches)
933 assert not any(m.endswith(("]", '"', "'")) for m in matches), matches
930 assert not any(m.endswith(("]", '"', "'")) for m in matches), matches
934
931
935 # check escaping and whitespace
932 # check escaping and whitespace
936 ip.user_ns["d"] = {"a\nb": None, "a'b": None, 'a"b': None, "a word": None}
933 ip.user_ns["d"] = {"a\nb": None, "a'b": None, 'a"b': None, "a word": None}
937 _, matches = complete(line_buffer="d['a")
934 _, matches = complete(line_buffer="d['a")
938 nt.assert_in("a\\nb", matches)
935 self.assertIn("a\\nb", matches)
939 nt.assert_in("a\\'b", matches)
936 self.assertIn("a\\'b", matches)
940 nt.assert_in('a"b', matches)
937 self.assertIn('a"b', matches)
941 nt.assert_in("a word", matches)
938 self.assertIn("a word", matches)
942 assert not any(m.endswith(("]", '"', "'")) for m in matches), matches
939 assert not any(m.endswith(("]", '"', "'")) for m in matches), matches
943
940
944 # - can complete on non-initial word of the string
941 # - can complete on non-initial word of the string
945 _, matches = complete(line_buffer="d['a w")
942 _, matches = complete(line_buffer="d['a w")
946 nt.assert_in("word", matches)
943 self.assertIn("word", matches)
947
944
948 # - understands quote escaping
945 # - understands quote escaping
949 _, matches = complete(line_buffer="d['a\\'")
946 _, matches = complete(line_buffer="d['a\\'")
950 nt.assert_in("b", matches)
947 self.assertIn("b", matches)
951
948
952 # - default quoting should work like repr
949 # - default quoting should work like repr
953 _, matches = complete(line_buffer="d[")
950 _, matches = complete(line_buffer="d[")
954 nt.assert_in('"a\'b"', matches)
951 self.assertIn('"a\'b"', matches)
955
952
956 # - when opening quote with ", possible to match with unescaped apostrophe
953 # - when opening quote with ", possible to match with unescaped apostrophe
957 _, matches = complete(line_buffer="d[\"a'")
954 _, matches = complete(line_buffer="d[\"a'")
958 nt.assert_in("b", matches)
955 self.assertIn("b", matches)
959
956
960 # need to not split at delims that readline won't split at
957 # need to not split at delims that readline won't split at
961 if "-" not in ip.Completer.splitter.delims:
958 if "-" not in ip.Completer.splitter.delims:
962 ip.user_ns["d"] = {"before-after": None}
959 ip.user_ns["d"] = {"before-after": None}
963 _, matches = complete(line_buffer="d['before-af")
960 _, matches = complete(line_buffer="d['before-af")
964 nt.assert_in("before-after", matches)
961 self.assertIn("before-after", matches)
965
962
966 # check completion on tuple-of-string keys at different stage - on first key
963 # check completion on tuple-of-string keys at different stage - on first key
967 ip.user_ns["d"] = {('foo', 'bar'): None}
964 ip.user_ns["d"] = {('foo', 'bar'): None}
968 _, matches = complete(line_buffer="d[")
965 _, matches = complete