Skip to content

Commit

Permalink
add coverage to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-stuerz committed Dec 27, 2023
1 parent 6e70df6 commit 6a97a68
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions opnsense_cli/autoloader/click_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def autoload(self, module_name=None):
opnsense_cli/commands
├── core
│ ├── firewall
│ │ ├── __init__.py (Main @click.group firewall
│ │ ├── alias.py (subgroup alias with commmands from firewall)
│ │ └── rule.py (subgroup rule with commmands from firewall)
│ │ ├── __init__.py (main @click.group firewall)
│ │ ├── alias.py (subgroup alias with commands from firewall)
│ │ └── rule.py (subgroup rule with commands from firewall)
:param module_name: python module name e.g. opnsense_cli.commands.core
:return: click.core.Group
Expand Down
Empty file.
23 changes: 23 additions & 0 deletions opnsense_cli/tests/autoloader/test_click_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from unittest import TestCase
from click.core import Command as ClickCommand
from opnsense_cli.autoloader.click_command import ClickCommandAutoloader
from opnsense_cli.cli import cli
from unittest.mock import patch
import os


class TestClickCommandAutoloader(TestCase):
def setUp(self):
self._autoloader = ClickCommandAutoloader(cli)
self._script_dir = os.path.dirname(os.path.realpath(__file__))
self._commands_dir = f"{self._script_dir}/../../opnsense_cli/commands"

@patch("opnsense_cli.autoloader.click_command.os.walk")
def test_autoload_commands(self, os_walk_mock):
os_walk_mock.return_value = [
(f"{self._commands_dir}/version", ["__pycache__"], ["__init__.py"]),
(f"{self._commands_dir}/version/__pycache__", [], ["__init__"]),
]
result = self._autoloader.autoload("opnsense_cli.commands.version")

self.assertIsInstance(result, ClickCommand)

0 comments on commit 6a97a68

Please sign in to comment.