-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'rich-mode-s390x' into test
- Loading branch information
Showing
2 changed files
with
113 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Copyright 2023 Canonical, Ltd. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import json | ||
import pathlib | ||
import tempfile | ||
import unittest | ||
from unittest.mock import Mock, patch | ||
|
||
from subiquitycore.tui import TuiApplication | ||
|
||
|
||
class TestTuiApplication(unittest.TestCase): | ||
def setUp(self): | ||
with patch("subiquitycore.tui.Application.__init__", return_value=None): | ||
opts = Mock() | ||
opts.answers = None | ||
opts.dry_run = True | ||
self.tui = TuiApplication(opts) | ||
# Usually, the below are assigned by Application.__init__() | ||
self.tui.opts = opts | ||
tmpdir = tempfile.TemporaryDirectory() | ||
self.tui.state_dir = tmpdir.name | ||
self.addCleanup(tmpdir.cleanup) | ||
|
||
def test_get_initial_rich_mode_normal(self): | ||
self.tui.opts.run_on_serial = False | ||
self.assertTrue(self.tui.get_initial_rich_mode()) | ||
|
||
# With a state file. | ||
with (pathlib.Path(self.tui.state_dir) / "rich-mode-tty").open("w") as fh: | ||
fh.write(json.dumps(True)) | ||
self.assertTrue(self.tui.get_initial_rich_mode()) | ||
with (pathlib.Path(self.tui.state_dir) / "rich-mode-tty").open("w") as fh: | ||
fh.write(json.dumps(False)) | ||
self.assertFalse(self.tui.get_initial_rich_mode()) | ||
|
||
def test_get_initial_rich_mode_serial(self): | ||
self.tui.opts.run_on_serial = True | ||
self.assertFalse(self.tui.get_initial_rich_mode()) | ||
|
||
# With a state file. | ||
with (pathlib.Path(self.tui.state_dir) / "rich-mode-serial").open("w") as fh: | ||
fh.write(json.dumps(True)) | ||
self.assertTrue(self.tui.get_initial_rich_mode()) | ||
with (pathlib.Path(self.tui.state_dir) / "rich-mode-serial").open("w") as fh: | ||
fh.write(json.dumps(False)) | ||
self.assertFalse(self.tui.get_initial_rich_mode()) | ||
|
||
def test_get_initial_rich_mode_legacy_state_file(self): | ||
# Make sure if an old rich-mode state file is present, it is honored - | ||
# but the new format takes precedence. | ||
self.tui.opts.run_on_serial = True | ||
with (pathlib.Path(self.tui.state_dir) / "rich-mode").open("w") as fh: | ||
fh.write(json.dumps(True)) | ||
self.assertTrue(self.tui.get_initial_rich_mode()) | ||
with (pathlib.Path(self.tui.state_dir) / "rich-mode-serial").open("w") as fh: | ||
fh.write(json.dumps(False)) | ||
self.assertFalse(self.tui.get_initial_rich_mode()) | ||
|
||
self.tui.opts.run_on_serial = False | ||
with (pathlib.Path(self.tui.state_dir) / "rich-mode").open("w") as fh: | ||
fh.write(json.dumps(False)) | ||
self.assertFalse(self.tui.get_initial_rich_mode()) | ||
with (pathlib.Path(self.tui.state_dir) / "rich-mode-tty").open("w") as fh: | ||
fh.write(json.dumps(True)) | ||
self.assertTrue(self.tui.get_initial_rich_mode()) |
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