@@ -872,3 +872,37 @@ def test_find_editor_not_specified():
872
872
with mock .patch .dict (os .environ , {'PATH' : 'fake_dir' }, clear = True ):
873
873
editor = cu .find_editor ()
874
874
assert editor is None
875
+
876
+
877
+ def test_similarity ():
878
+ suggested_command = cu .suggest_similar ("comand" , ["command" , "UNRELATED" , "NOT_SIMILAR" ])
879
+ assert suggested_command == "command"
880
+ suggested_command = cu .suggest_similar ("command" , ["COMMAND" , "acommands" ])
881
+ assert suggested_command == "COMMAND"
882
+
883
+
884
+ def test_similarity_without_good_canididates ():
885
+ suggested_command = cu .suggest_similar ("comand" , ["UNRELATED" , "NOT_SIMILAR" ])
886
+ assert suggested_command is None
887
+ suggested_command = cu .suggest_similar ("comand" , [])
888
+ assert suggested_command is None
889
+
890
+
891
+ def test_similarity_overwrite_function ():
892
+ suggested_command = cu .suggest_similar ("test" , ["history" , "test" ])
893
+ assert suggested_command == 'test'
894
+
895
+ def custom_similarity_function (s1 , s2 ):
896
+ return 1.0 if 'history' in (s1 , s2 ) else 0.0
897
+
898
+ suggested_command = cu .suggest_similar ("test" , ["history" , "test" ],
899
+ similarity_function_to_use = custom_similarity_function )
900
+ assert suggested_command == 'history'
901
+
902
+ suggested_command = cu .suggest_similar ("history" , ["history" , "test" ],
903
+ similarity_function_to_use = custom_similarity_function )
904
+ assert suggested_command == 'history'
905
+
906
+ suggested_command = cu .suggest_similar ("test" , ["test" ],
907
+ similarity_function_to_use = custom_similarity_function )
908
+ assert suggested_command is None
0 commit comments