Show More
@@ -534,7 +534,7 b' def test_dict_key_completion_bytes():' | |||||
534 |
|
534 | |||
535 |
|
535 | |||
536 | @dec.onlyif(sys.version_info[0] < 3, 'This test only applies in Py<3') |
|
536 | @dec.onlyif(sys.version_info[0] < 3, 'This test only applies in Py<3') | |
537 | def test_dict_key_completion_unicode(): |
|
537 | def test_dict_key_completion_unicode_py2(): | |
538 | """Test handling of unicode in dict key completion""" |
|
538 | """Test handling of unicode in dict key completion""" | |
539 | ip = get_ipython() |
|
539 | ip = get_ipython() | |
540 | complete = ip.Completer.complete |
|
540 | complete = ip.Completer.complete | |
@@ -558,6 +558,31 b' def test_dict_key_completion_unicode():' | |||||
558 | nt.assert_in("abc']", matches) |
|
558 | nt.assert_in("abc']", matches) | |
559 | nt.assert_in("a\\u05d0']", matches) |
|
559 | nt.assert_in("a\\u05d0']", matches) | |
560 |
|
560 | |||
|
561 | # query using escape | |||
|
562 | _, matches = complete(line_buffer="d[u'a\\u05d0") | |||
|
563 | nt.assert_in("u05d0']", matches) # tokenized after \\ | |||
|
564 | ||||
|
565 | # query using character | |||
|
566 | _, matches = complete(line_buffer=unicode_type("d[u'a\xd7\x90", 'utf8')) | |||
|
567 | nt.assert_in("']", matches) | |||
|
568 | ||||
|
569 | ||||
|
570 | @dec.onlyif(sys.version_info[0] >= 3, 'This test only applies in Py>=3') | |||
|
571 | def test_dict_key_completion_unicode_py3(): | |||
|
572 | """Test handling of unicode in dict key completion""" | |||
|
573 | ip = get_ipython() | |||
|
574 | complete = ip.Completer.complete | |||
|
575 | ||||
|
576 | ip.user_ns['d'] = {unicode_type(b'a\xd7\x90', 'utf8'): None} | |||
|
577 | ||||
|
578 | # query using escape | |||
|
579 | _, matches = complete(line_buffer="d['a\\u05d0") | |||
|
580 | nt.assert_in("u05d0']", matches) # tokenized after \\ | |||
|
581 | ||||
|
582 | # query using character | |||
|
583 | _, matches = complete(line_buffer=unicode_type(b"d['a\xd7\x90", 'utf8')) | |||
|
584 | nt.assert_in(unicode_type(b"a\xd7\x90']", 'utf8'), matches) | |||
|
585 | ||||
561 |
|
586 | |||
562 | def test_dict_like_key_completion(): |
|
587 | def test_dict_like_key_completion(): | |
563 | """Test dict key completion applies where __getitem__ and keys exist""" |
|
588 | """Test dict key completion applies where __getitem__ and keys exist""" | |
@@ -596,3 +621,22 b' def test_dataframe_key_completion():' | |||||
596 | _, matches = complete(line_buffer="d['") |
|
621 | _, matches = complete(line_buffer="d['") | |
597 | nt.assert_in("hello']", matches) |
|
622 | nt.assert_in("hello']", matches) | |
598 | nt.assert_in("world']", matches) |
|
623 | nt.assert_in("world']", matches) | |
|
624 | ||||
|
625 | ||||
|
626 | def test_dict_key_completion_invalids(): | |||
|
627 | """Smoke test cases dict key completion can't handle""" | |||
|
628 | ip = get_ipython() | |||
|
629 | complete = ip.Completer.complete | |||
|
630 | ||||
|
631 | ip.user_ns['no_getitem'] = None | |||
|
632 | ip.user_ns['no_keys'] = [] | |||
|
633 | ip.user_ns['cant_call_keys'] = dict | |||
|
634 | ip.user_ns['empty'] = {} | |||
|
635 | ip.user_ns['d'] = {'abc': 5} | |||
|
636 | ||||
|
637 | _, matches = complete(line_buffer="no_getitem['") | |||
|
638 | _, matches = complete(line_buffer="no_keys['") | |||
|
639 | _, matches = complete(line_buffer="cant_call_keys['") | |||
|
640 | _, matches = complete(line_buffer="empty['") | |||
|
641 | _, matches = complete(line_buffer="name_error['") | |||
|
642 | _, matches = complete(line_buffer="d['\\") # incomplete escape |
General Comments 0
You need to be logged in to leave comments.
Login now