##// END OF EJS Templates
Compactify assertions spaghettified by black
krassowski -
Show More
@@ -853,31 +853,38 class TestCompleter(unittest.TestCase):
853 delims = " \t\n`!@#$^&*()=+[{]}\\|;:'\",<>?"
853 delims = " \t\n`!@#$^&*()=+[{]}\\|;:'\",<>?"
854
854
855 def match(*args, **kwargs):
855 def match(*args, **kwargs):
856 quote, offset, matches = match_dict_keys(*args, **kwargs)
856 quote, offset, matches = match_dict_keys(*args, delims=delims, **kwargs)
857 return quote, offset, list(matches)
857 return quote, offset, list(matches)
858
858
859 keys = ["foo", b"far"]
859 keys = ["foo", b"far"]
860 assert match(keys, "b'", delims=delims) == ("'", 2, ["far"])
860 assert match(keys, "b'") == ("'", 2, ["far"])
861 assert match(keys, "b'f", delims=delims) == ("'", 2, ["far"])
861 assert match(keys, "b'f") == ("'", 2, ["far"])
862 assert match(keys, 'b"', delims=delims) == ('"', 2, ["far"])
862 assert match(keys, 'b"') == ('"', 2, ["far"])
863 assert match(keys, 'b"f', delims=delims) == ('"', 2, ["far"])
863 assert match(keys, 'b"f') == ('"', 2, ["far"])
864
864
865 assert match(keys, "'", delims=delims) == ("'", 1, ["foo"])
865 assert match(keys, "'") == ("'", 1, ["foo"])
866 assert match(keys, "'f", delims=delims) == ("'", 1, ["foo"])
866 assert match(keys, "'f") == ("'", 1, ["foo"])
867 assert match(keys, '"', delims=delims) == ('"', 1, ["foo"])
867 assert match(keys, '"') == ('"', 1, ["foo"])
868 assert match(keys, '"f', delims=delims) == ('"', 1, ["foo"])
868 assert match(keys, '"f') == ('"', 1, ["foo"])
869
869
870 # Completion on first item of tuple
870 # Completion on first item of tuple
871 keys = [("foo", 1111), ("foo", 2222), (3333, "bar"), (3333, "test")]
871 keys = [("foo", 1111), ("foo", 2222), (3333, "bar"), (3333, "test")]
872 assert match(keys, "'f", delims=delims) == ("'", 1, ["foo"])
872 assert match(keys, "'f") == ("'", 1, ["foo"])
873 assert match(keys, "33", delims=delims) == ("", 0, ["3333"])
873 assert match(keys, "33") == ("", 0, ["3333"])
874
874
875 # Completion on numbers
875 # Completion on numbers
876 keys = [0xDEADBEEF, 1111, 1234, "1999", 0b10101, 22] # 3735928559 # 21
876 keys = [
877 assert match(keys, "0xdead", delims=delims) == ("", 0, ["0xdeadbeef"])
877 0xDEADBEEF,
878 assert match(keys, "1", delims=delims) == ("", 0, ["1111", "1234"])
878 1111,
879 assert match(keys, "2", delims=delims) == ("", 0, ["21", "22"])
879 1234,
880 assert match(keys, "0b101", delims=delims) == ("", 0, ["0b10101", "0b10110"])
880 "1999",
881 0b10101,
882 22,
883 ] # 0xDEADBEEF = 3735928559; 0b10101 = 21
884 assert match(keys, "0xdead") == ("", 0, ["0xdeadbeef"])
885 assert match(keys, "1") == ("", 0, ["1111", "1234"])
886 assert match(keys, "2") == ("", 0, ["21", "22"])
887 assert match(keys, "0b101") == ("", 0, ["0b10101", "0b10110"])
881
888
882 def test_match_dict_keys_tuple(self):
889 def test_match_dict_keys_tuple(self):
883 """
890 """
@@ -888,97 +895,43 class TestCompleter(unittest.TestCase):
888
895
889 keys = [("foo", "bar"), ("foo", "oof"), ("foo", b"bar"), ('other', 'test')]
896 keys = [("foo", "bar"), ("foo", "oof"), ("foo", b"bar"), ('other', 'test')]
890
897
891 def match(*args, **kwargs):
898 def match(*args, extra=None, **kwargs):
892 quote, offset, matches = match_dict_keys(*args, **kwargs)
899 quote, offset, matches = match_dict_keys(
900 *args, delims=delims, extra_prefix=extra, **kwargs
901 )
893 return quote, offset, list(matches)
902 return quote, offset, list(matches)
894
903
895 # Completion on first key == "foo"
904 # Completion on first key == "foo"
896 assert match(keys, "'", delims=delims, extra_prefix=("foo",)) == (
905 assert match(keys, "'", extra=("foo",)) == ("'", 1, ["bar", "oof"])
897 "'",
906 assert match(keys, '"', extra=("foo",)) == ('"', 1, ["bar", "oof"])
898 1,
907 assert match(keys, "'o", extra=("foo",)) == ("'", 1, ["oof"])
899 ["bar", "oof"],
908 assert match(keys, '"o', extra=("foo",)) == ('"', 1, ["oof"])
900 )
909 assert match(keys, "b'", extra=("foo",)) == ("'", 2, ["bar"])
901 assert match(keys, '"', delims=delims, extra_prefix=("foo",)) == (
910 assert match(keys, 'b"', extra=("foo",)) == ('"', 2, ["bar"])
902 '"',
911 assert match(keys, "b'b", extra=("foo",)) == ("'", 2, ["bar"])
903 1,
912 assert match(keys, 'b"b', extra=("foo",)) == ('"', 2, ["bar"])
904 ["bar", "oof"],
905 )
906 assert match(keys, "'o", delims=delims, extra_prefix=("foo",)) == (
907 "'",
908 1,
909 ["oof"],
910 )
911 assert match(keys, '"o', delims=delims, extra_prefix=("foo",)) == (
912 '"',
913 1,
914 ["oof"],
915 )
916 assert match(keys, "b'", delims=delims, extra_prefix=("foo",)) == (
917 "'",
918 2,
919 ["bar"],
920 )
921 assert match(keys, 'b"', delims=delims, extra_prefix=("foo",)) == (
922 '"',
923 2,
924 ["bar"],
925 )
926 assert match(keys, "b'b", delims=delims, extra_prefix=("foo",)) == (
927 "'",
928 2,
929 ["bar"],
930 )
931 assert match(keys, 'b"b', delims=delims, extra_prefix=("foo",)) == (
932 '"',
933 2,
934 ["bar"],
935 )
936
913
937 # No Completion
914 # No Completion
938 assert match(keys, "'", delims=delims, extra_prefix=("no_foo",)) == ("'", 1, [])
915 assert match(keys, "'", extra=("no_foo",)) == ("'", 1, [])
939 assert match(keys, "'", delims=delims, extra_prefix=("fo",)) == ("'", 1, [])
916 assert match(keys, "'", extra=("fo",)) == ("'", 1, [])
940
917
941 keys = [("foo1", "foo2", "foo3", "foo4"), ("foo1", "foo2", "bar", "foo4")]
918 keys = [("foo1", "foo2", "foo3", "foo4"), ("foo1", "foo2", "bar", "foo4")]
942 assert match(keys, "'foo", delims=delims, extra_prefix=("foo1",)) == (
919 assert match(keys, "'foo", extra=("foo1",)) == ("'", 1, ["foo2"])
920 assert match(keys, "'foo", extra=("foo1", "foo2")) == ("'", 1, ["foo3"])
921 assert match(keys, "'foo", extra=("foo1", "foo2", "foo3")) == ("'", 1, ["foo4"])
922 assert match(keys, "'foo", extra=("foo1", "foo2", "foo3", "foo4")) == (
943 "'",
923 "'",
944 1,
924 1,
945 ["foo2"],
925 [],
946 )
926 )
947 assert match(keys, "'foo", delims=delims, extra_prefix=("foo1", "foo2")) == (
948 "'",
949 1,
950 ["foo3"],
951 )
952 assert match(
953 keys, "'foo", delims=delims, extra_prefix=("foo1", "foo2", "foo3")
954 ) == ("'", 1, ["foo4"])
955 assert match(
956 keys, "'foo", delims=delims, extra_prefix=("foo1", "foo2", "foo3", "foo4")
957 ) == ("'", 1, [])
958
927
959 keys = [("foo", 1111), ("foo", "2222"), (3333, "bar"), (3333, 4444)]
928 keys = [("foo", 1111), ("foo", "2222"), (3333, "bar"), (3333, 4444)]
960 assert match(keys, "'", delims=delims, extra_prefix=("foo",)) == (
929 assert match(keys, "'", extra=("foo",)) == ("'", 1, ["2222"])
961 "'",
930 assert match(keys, "", extra=("foo",)) == ("", 0, ["1111", "'2222'"])
962 1,
931 assert match(keys, "'", extra=(3333,)) == ("'", 1, ["bar"])
963 ["2222"],
932 assert match(keys, "", extra=(3333,)) == ("", 0, ["'bar'", "4444"])
964 )
933 assert match(keys, "'", extra=("3333",)) == ("'", 1, [])
965 assert match(keys, "", delims=delims, extra_prefix=("foo",)) == (
934 assert match(keys, "33") == ("", 0, ["3333"])
966 "",
967 0,
968 ["1111", "'2222'"],
969 )
970 assert match(keys, "'", delims=delims, extra_prefix=(3333,)) == (
971 "'",
972 1,
973 ["bar"],
974 )
975 assert match(keys, "", delims=delims, extra_prefix=(3333,)) == (
976 "",
977 0,
978 ["'bar'", "4444"],
979 )
980 assert match(keys, "'", delims=delims, extra_prefix=("3333",)) == ("'", 1, [])
981 assert match(keys, "33", delims=delims) == ("", 0, ["3333"])
982
935
983 def test_dict_key_completion_closures(self):
936 def test_dict_key_completion_closures(self):
984 ip = get_ipython()
937 ip = get_ipython()
General Comments 0
You need to be logged in to leave comments. Login now