-
Notifications
You must be signed in to change notification settings - Fork 0
#7: Implemented apt install command #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Torsten Kilias <tkilias@users.noreply.github.com>
Co-authored-by: Torsten Kilias <tkilias@users.noreply.github.com>
Co-authored-by: Torsten Kilias <tkilias@users.noreply.github.com>
| assert "stderr" in result_str | ||
|
|
||
|
|
||
| def test_command_executor(monkeypatch, mock_command_result): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test doesn't test the CommandExecutor because, you mocked its most important function. Part of this test could be used for testing CommandResult
|
|
||
|
|
||
| class CommandLogger(Protocol): | ||
| def info(self, msg: str) -> None: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def info(self, msg: str) -> None: ... | |
| def info(self, msg: str, **kwargs) -> None: ... |
We probably should add to all methods the kwargs, then we can format the result if we want.
| self._last_msg = msg | ||
| sys.stderr.write(msg) | ||
|
|
||
| def get_last_msg(self) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this?
| class CommandResult: | ||
| def __init__( | ||
| self, | ||
| logger: CommandLogger, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move this to the end of the parameter list
| logger = StdLogger() | ||
| monkeypatch.setattr(CommandExecutor, "execute", mock_execute) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you not using the Mock or MagicMock objects for Logger and CommandExecutor? This would remove the requirement for get_last_msg from the Logger which I don't like and the other test uses them as well.
| def mock_execute(_, cmd_strs): | ||
| return mock_command_result | ||
|
|
||
| def stdout_results(result_str: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have time left we should change this function to actually collect the strings in a list and assert in the end the strings. And, we probably should only use a single function, such that we see if the stdout and stderr are used alternatingly.
|
|
||
| @pytest.fixture | ||
| def mock_command_result(): | ||
| logger = StdLogger() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use a Mock object for this, such that we can check if print_results calls the Logger as expected.
| if len(apt_packages.packages) > 0: | ||
| update_cmd = prepare_update_command() | ||
| cmd_res = executor.execute(update_cmd) | ||
| cmd_res.print_results() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After we printed the results, we need to check the return_code if the command was successful. This is needed for each command.
fixes #7