Skip to content

Commit

Permalink
Merge pull request #2085 from Chris-Peterson444/journal-parsing-unpac…
Browse files Browse the repository at this point in the history
…k-error

ui: fix journal parsing in ProgressView
  • Loading branch information
Chris-Peterson444 authored Sep 17, 2024
2 parents be25d93 + 6c743d0 commit ccd71d5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion subiquity/ui/views/installprogress.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def event_other(self, message: str, event_type: str) -> None:
#
# and we want to insert the event type between the colon and the
# event description
context, text = message.split(":")
context, text = message.split(":", maxsplit=1)
text = text.lstrip()
message = f"{context}: {event_type.upper()}: {text}"

Expand Down
27 changes: 27 additions & 0 deletions subiquity/ui/views/tests/test_installprogress.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
from unittest import mock
from unittest.mock import patch

from subiquity.client.controllers.progress import ProgressController
from subiquity.common.types import ApplicationState
Expand Down Expand Up @@ -53,3 +54,29 @@ def test_error_disambiguation(self):
self.assertIsNone(btn)
btn = view_helpers.find_button_matching(view, "^Restart Installer$")
self.assertIsNotNone(btn)

@patch("subiquity.ui.views.installprogress.Columns")
@patch("subiquity.ui.views.installprogress.Text")
def test_event_other_formatting(self, text_mock, columns_mock):
"""Test formatting of the other_event function."""
view = self.make_view()
text_mock.return_value = "mock text"
view.event_other("MOCK CONTEXT: message", "mock")
text_mock.assert_called_with("MOCK CONTEXT: MOCK: message")
columns_mock.assert_called_with(
[
("pack", "mock text"),
],
dividechars=1,
)

@patch("subiquity.ui.views.installprogress.Text")
def test_event_other_robust_splitting(self, text_mock):
"""Test that messages containing a colon don't fail to split.
event_other uses str.split(":"), make sure it doesn't cause an
error if more than one colon is present in the message.
"""
view = self.make_view()
view.event_other("MOCK CONTEXT: bad keys: 1, 2, 3", "mock")
text_mock.assert_called_with("MOCK CONTEXT: MOCK: bad keys: 1, 2, 3")

0 comments on commit ccd71d5

Please sign in to comment.