Show More
@@ -963,6 +963,74 b' class TestCompleter(unittest.TestCase):' | |||||
963 | _, matches = complete(line_buffer="d['before-af") |
|
963 | _, matches = complete(line_buffer="d['before-af") | |
964 | nt.assert_in("before-after", matches) |
|
964 | nt.assert_in("before-after", matches) | |
965 |
|
965 | |||
|
966 | # check completion on tuple-of-string keys at different stage - on first key | |||
|
967 | ip.user_ns["d"] = {('foo', 'bar'): None} | |||
|
968 | _, matches = complete(line_buffer="d[") | |||
|
969 | nt.assert_in("'foo'", matches) | |||
|
970 | nt.assert_not_in("'foo']", matches) | |||
|
971 | nt.assert_not_in("'bar'", matches) | |||
|
972 | nt.assert_not_in("foo", matches) | |||
|
973 | nt.assert_not_in("bar", matches) | |||
|
974 | ||||
|
975 | # - match the prefix | |||
|
976 | _, matches = complete(line_buffer="d['f") | |||
|
977 | nt.assert_in("foo", matches) | |||
|
978 | nt.assert_not_in("foo']", matches) | |||
|
979 | nt.assert_not_in("foo\"]", matches) | |||
|
980 | _, matches = complete(line_buffer="d['foo") | |||
|
981 | nt.assert_in("foo", matches) | |||
|
982 | ||||
|
983 | # - can complete on second key | |||
|
984 | _, matches = complete(line_buffer="d['foo', ") | |||
|
985 | nt.assert_in("'bar'", matches) | |||
|
986 | _, matches = complete(line_buffer="d['foo', 'b") | |||
|
987 | nt.assert_in("bar", matches) | |||
|
988 | nt.assert_not_in("foo", matches) | |||
|
989 | ||||
|
990 | # - does not propose missing keys | |||
|
991 | _, matches = complete(line_buffer="d['foo', 'f") | |||
|
992 | nt.assert_not_in("bar", matches) | |||
|
993 | nt.assert_not_in("foo", matches) | |||
|
994 | ||||
|
995 | # check sensitivity to following context | |||
|
996 | _, matches = complete(line_buffer="d['foo',]", cursor_pos=8) | |||
|
997 | nt.assert_in("'bar'", matches) | |||
|
998 | nt.assert_not_in("bar", matches) | |||
|
999 | nt.assert_not_in("'foo'", matches) | |||
|
1000 | nt.assert_not_in("foo", matches) | |||
|
1001 | ||||
|
1002 | _, matches = complete(line_buffer="d['']", cursor_pos=3) | |||
|
1003 | nt.assert_in("foo", matches) | |||
|
1004 | assert not any(m.endswith(("]", '"', "'")) for m in matches), matches | |||
|
1005 | ||||
|
1006 | _, matches = complete(line_buffer='d[""]', cursor_pos=3) | |||
|
1007 | nt.assert_in("foo", matches) | |||
|
1008 | assert not any(m.endswith(("]", '"', "'")) for m in matches), matches | |||
|
1009 | ||||
|
1010 | _, matches = complete(line_buffer='d["foo","]', cursor_pos=9) | |||
|
1011 | nt.assert_in("bar", matches) | |||
|
1012 | assert not any(m.endswith(("]", '"', "'")) for m in matches), matches | |||
|
1013 | ||||
|
1014 | _, matches = complete(line_buffer='d["foo",]', cursor_pos=8) | |||
|
1015 | nt.assert_in("'bar'", matches) | |||
|
1016 | nt.assert_not_in("bar", matches) | |||
|
1017 | ||||
|
1018 | # Can complete with longer tuple keys | |||
|
1019 | ip.user_ns["d"] = {('foo', 'bar', 'foobar'): None} | |||
|
1020 | ||||
|
1021 | # - can complete second key | |||
|
1022 | _, matches = complete(line_buffer="d['foo', 'b") | |||
|
1023 | nt.assert_in('bar', matches) | |||
|
1024 | nt.assert_not_in('foo', matches) | |||
|
1025 | nt.assert_not_in('foobar', matches) | |||
|
1026 | ||||
|
1027 | # - can complete third key | |||
|
1028 | _, matches = complete(line_buffer="d['foo', 'bar', 'fo") | |||
|
1029 | nt.assert_in('foobar', matches) | |||
|
1030 | nt.assert_not_in('foo', matches) | |||
|
1031 | nt.assert_not_in('bar', matches) | |||
|
1032 | ||||
|
1033 | ||||
966 | def test_dict_key_completion_contexts(self): |
|
1034 | def test_dict_key_completion_contexts(self): | |
967 | """Test expression contexts in which dict key completion occurs""" |
|
1035 | """Test expression contexts in which dict key completion occurs""" | |
968 | ip = get_ipython() |
|
1036 | ip = get_ipython() |
General Comments 0
You need to be logged in to leave comments.
Login now