Explorar o código

add a unit test, fix isort and black

Isaac %!s(int64=2) %!d(string=hai) anos
pai
achega
9ff5ea5240

+ 34 - 13
borgmatic/commands/completion.py

@@ -1,6 +1,8 @@
+import shlex
 from argparse import Action
 from argparse import Action
+
 from borgmatic.commands import arguments
 from borgmatic.commands import arguments
-import shlex
+
 
 
 def upgrade_message(language: str, upgrade_command: str, completion_file: str):
 def upgrade_message(language: str, upgrade_command: str, completion_file: str):
     return f'''
     return f'''
@@ -37,7 +39,13 @@ def bash_completion():
             '    local this_script="$(cat "$BASH_SOURCE" 2> /dev/null)"',
             '    local this_script="$(cat "$BASH_SOURCE" 2> /dev/null)"',
             '    local installed_script="$(borgmatic --bash-completion 2> /dev/null)"',
             '    local installed_script="$(borgmatic --bash-completion 2> /dev/null)"',
             '    if [ "$this_script" != "$installed_script" ] && [ "$installed_script" != "" ];'
             '    if [ "$this_script" != "$installed_script" ] && [ "$installed_script" != "" ];'
-            '        then cat << EOF\n{}\nEOF'.format(upgrade_message('bash', 'sudo sh -c "borgmatic --bash-completion > $BASH_SOURCE"', '$BASH_SOURCE')),
+            '        then cat << EOF\n{}\nEOF'.format(
+                upgrade_message(
+                    'bash',
+                    'sudo sh -c "borgmatic --bash-completion > $BASH_SOURCE"',
+                    '$BASH_SOURCE',
+                )
+            ),
             '    fi',
             '    fi',
             '}',
             '}',
             'complete_borgmatic() {',
             'complete_borgmatic() {',
@@ -59,6 +67,7 @@ def bash_completion():
         )
         )
     )
     )
 
 
+
 def build_fish_flags(action: Action):
 def build_fish_flags(action: Action):
     '''
     '''
     Given an argparse.Action instance, return a string containing the fish flags for that action.
     Given an argparse.Action instance, return a string containing the fish flags for that action.
@@ -68,6 +77,7 @@ def build_fish_flags(action: Action):
     else:
     else:
         return '-f'
         return '-f'
 
 
+
 def fish_completion():
 def fish_completion():
     '''
     '''
     Return a fish completion script for the borgmatic command. Produce this by introspecting
     Return a fish completion script for the borgmatic command. Produce this by introspecting
@@ -85,27 +95,38 @@ def fish_completion():
             '    set this_script (cat $this_filename 2> /dev/null)',
             '    set this_script (cat $this_filename 2> /dev/null)',
             '    set installed_script (borgmatic --fish-completion 2> /dev/null)',
             '    set installed_script (borgmatic --fish-completion 2> /dev/null)',
             '    if [ "$this_script" != "$installed_script" ] && [ "$installed_script" != "" ]',
             '    if [ "$this_script" != "$installed_script" ] && [ "$installed_script" != "" ]',
-            '        echo "{}"'.format(upgrade_message('fish', 'borgmatic --fish-completion | sudo tee $this_filename', '$this_filename')),
+            '        echo "{}"'.format(
+                upgrade_message(
+                    'fish',
+                    'borgmatic --fish-completion | sudo tee $this_filename',
+                    '$this_filename',
+                )
+            ),
             '    end',
             '    end',
             'end',
             'end',
             '__borgmatic_check_version &',
             '__borgmatic_check_version &',
-        ) + (
-            '\n# subparser completions',
-        ) + tuple(
+        )
+        + ('\n# subparser completions',)
+        + tuple(
             '''complete -c borgmatic -a '%s' -d %s -f -n "not __fish_seen_subcommand_from %s"'''
             '''complete -c borgmatic -a '%s' -d %s -f -n "not __fish_seen_subcommand_from %s"'''
             % (actionStr, shlex.quote(subparser.description), all_subparsers)
             % (actionStr, shlex.quote(subparser.description), all_subparsers)
             for actionStr, subparser in subparsers.choices.items()
             for actionStr, subparser in subparsers.choices.items()
-        ) + (
-            '\n# global flags',
-        ) + tuple(
+        )
+        + ('\n# global flags',)
+        + tuple(
             '''complete -c borgmatic -a '%s' -d %s %s'''
             '''complete -c borgmatic -a '%s' -d %s %s'''
             % (' '.join(action.option_strings), shlex.quote(action.help), build_fish_flags(action))
             % (' '.join(action.option_strings), shlex.quote(action.help), build_fish_flags(action))
             for action in top_level_parser._actions
             for action in top_level_parser._actions
-        ) + (
-            '\n# subparser flags',
-        ) + tuple(
+        )
+        + ('\n# subparser flags',)
+        + tuple(
             '''complete -c borgmatic -a '%s' -d %s -n "__fish_seen_subcommand_from %s" %s'''
             '''complete -c borgmatic -a '%s' -d %s -n "__fish_seen_subcommand_from %s" %s'''
-            % (' '.join(action.option_strings), shlex.quote(action.help), actionStr, build_fish_flags(action))
+            % (
+                ' '.join(action.option_strings),
+                shlex.quote(action.help),
+                actionStr,
+                build_fish_flags(action),
+            )
             for actionStr, subparser in subparsers.choices.items()
             for actionStr, subparser in subparsers.choices.items()
             for action in subparser._actions
             for action in subparser._actions
         )
         )

+ 4 - 0
tests/integration/commands/test_completion.py

@@ -3,3 +3,7 @@ from borgmatic.commands import completion as module
 
 
 def test_bash_completion_does_not_raise():
 def test_bash_completion_does_not_raise():
     assert module.bash_completion()
     assert module.bash_completion()
+
+
+def test_fish_completion_does_not_raise():
+    assert module.fish_completion()