diff --git a/lib/rift/Controller.py b/lib/rift/Controller.py index 6a466fce..f37e9b83 100644 --- a/lib/rift/Controller.py +++ b/lib/rift/Controller.py @@ -58,20 +58,9 @@ from rift.TextTable import TextTable from rift.VM import VM from rift.sync import RepoSyncFactory +from rift.utils import message, banner -def message(msg): - """ - helper function to print a log message - """ - print(f"> {msg}") - -def banner(title): - """ - helper function to print a banner - """ - print(f"** {title} **") - def make_parser(): """Create command line parser""" diff --git a/lib/rift/utils.py b/lib/rift/utils.py index 3a0430c1..b1c6e9b0 100644 --- a/lib/rift/utils.py +++ b/lib/rift/utils.py @@ -38,6 +38,18 @@ from rift import RiftError +def message(msg): + """ + helper function to print a log message + """ + print(f"> {msg}") + +def banner(title): + """ + helper function to print a banner + """ + print(f"** {title} **") + def download_file(url, output): """ Download file pointed by url and save it in output path. Convert diff --git a/tests/utils.py b/tests/utils.py new file mode 100644 index 00000000..133ac6e1 --- /dev/null +++ b/tests/utils.py @@ -0,0 +1,21 @@ +# +# Copyright (C) 2025 CEA +# + +from io import StringIO +from unittest.mock import patch + +from TestUtils import RiftTestCase +from rift.utils import message, banner + +class UtilsTest(RiftTestCase): + + @patch('sys.stdout', new_callable=StringIO) + def test_message(self, mock_stdout): + message("foo") + self.assertEqual(mock_stdout.getvalue(), "> foo\n") + + @patch('sys.stdout', new_callable=StringIO) + def test_banner(self, mock_stdout): + banner("bar") + self.assertEqual(mock_stdout.getvalue(), "** bar **\n")