-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(CLI): logging verbosity control
- Loading branch information
1 parent
e522d12
commit f9c2194
Showing
18 changed files
with
184 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"""CommandBase mixin to provide configured running state.""" | ||
|
||
import logging | ||
|
||
from pi_portal.modules.configuration import state | ||
|
||
|
||
class CommandManagedStateMixin: | ||
"""Provide configured state to a CLI command.""" | ||
|
||
def load_state(self, debug: bool) -> None: | ||
"""Load and configure state. | ||
:param debug: Enable or disable debug logs. | ||
""" | ||
running_state = state.State() | ||
running_state.load() | ||
if debug: | ||
running_state.log_level = logging.DEBUG |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Test the CommandManagedStateMixin class.""" | ||
|
||
import logging | ||
from unittest import TestCase, mock | ||
|
||
from .. import state | ||
|
||
|
||
class TestLoadStateCommand(TestCase): | ||
"""Test the CommandManagedStateMixin class.""" | ||
|
||
def setUp(self) -> None: | ||
self.instance = state.CommandManagedStateMixin() | ||
|
||
@mock.patch(state.__name__ + ".state") | ||
def test_load_state(self, m_state: mock.Mock) -> None: | ||
self.instance.load_state(False) | ||
m_state.State.assert_called_once_with() | ||
m_state.State.return_value.load.assert_called_once_with() | ||
self.assertNotEqual( | ||
m_state.State.return_value.log_level, | ||
logging.DEBUG, | ||
) | ||
|
||
@mock.patch(state.__name__ + ".state") | ||
def test_load_state_debug_logging(self, m_state: mock.Mock) -> None: | ||
self.instance.load_state(True) | ||
m_state.State.assert_called_once_with() | ||
m_state.State.return_value.load.assert_called_once_with() | ||
self.assertEqual( | ||
m_state.State.return_value.log_level, | ||
logging.DEBUG, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.