Skip to content

Commit

Permalink
changes based on formatter and doc jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
Federico Martinez committed Aug 2, 2023
1 parent f0b0580 commit 49cdd85
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
5 changes: 3 additions & 2 deletions cmd2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1274,8 +1274,9 @@ def similarity_function(s1: str, s2: str) -> float:
MIN_SIMIL_TO_CONSIDER = 0.7


def suggest_similar(requested_command: str, options: Iterable[str],
similarity_function_to_use: Optional[Callable[[str, str], float]] = None) -> Optional[str]:
def suggest_similar(
requested_command: str, options: Iterable[str], similarity_function_to_use: Optional[Callable[[str, str], float]] = None
) -> Optional[str]:
"""
Given a requested command and an iterable of possible options
returns the most similar (if any is similar)
Expand Down
1 change: 1 addition & 0 deletions docs/api/utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,4 @@ Miscellaneous
.. autofunction:: cmd2.utils.natural_sort

.. autofunction:: cmd2.utils.suggest_similar

12 changes: 5 additions & 7 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,20 +889,18 @@ def test_similarity_without_good_canididates():


def test_similarity_overwrite_function():
suggested_command = cu.suggest_similar("test", ["history", "test"])
options = ["history", "test"]
suggested_command = cu.suggest_similar("test", options)
assert suggested_command == 'test'

def custom_similarity_function(s1, s2):
return 1.0 if 'history' in (s1, s2) else 0.0

suggested_command = cu.suggest_similar("test", ["history", "test"],
similarity_function_to_use=custom_similarity_function)
suggested_command = cu.suggest_similar("test", options, similarity_function_to_use=custom_similarity_function)
assert suggested_command == 'history'

suggested_command = cu.suggest_similar("history", ["history", "test"],
similarity_function_to_use=custom_similarity_function)
suggested_command = cu.suggest_similar("history", options, similarity_function_to_use=custom_similarity_function)
assert suggested_command == 'history'

suggested_command = cu.suggest_similar("test", ["test"],
similarity_function_to_use=custom_similarity_function)
suggested_command = cu.suggest_similar("test", ["test"], similarity_function_to_use=custom_similarity_function)
assert suggested_command is None

0 comments on commit 49cdd85

Please sign in to comment.