Skip to content

Conversation

@sgn4sangar
Copy link
Collaborator

fixes #7

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):
Copy link

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: ...
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link

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,
Copy link

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

Comment on lines +35 to +36
logger = StdLogger()
monkeypatch.setattr(CommandExecutor, "execute", mock_execute)
Copy link

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):
Copy link

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()
Copy link

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()
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement install command for APT

3 participants