|
35 | 35 | from easybuild.tools.build_log import EasyBuildError |
36 | 36 | from easybuild.tools.config import build_option, get_output_style, update_build_option |
37 | 37 | from easybuild.tools.output import PROGRESS_BAR_EXTENSIONS, PROGRESS_BAR_TYPES |
38 | | -from easybuild.tools.output import DummyRich, colorize, get_progress_bar, show_progress_bars |
| 38 | +from easybuild.tools.output import DummyRich, colorize, get_progress_bar, print_error, show_progress_bars |
39 | 39 | from easybuild.tools.output import start_progress_bar, status_bar, stop_progress_bar, update_progress_bar, use_rich |
40 | 40 |
|
41 | 41 | try: |
@@ -139,6 +139,26 @@ def test_colorize(self): |
139 | 139 |
|
140 | 140 | self.assertErrorRegex(EasyBuildError, "Unknown color: nosuchcolor", colorize, 'test', 'nosuchcolor') |
141 | 141 |
|
| 142 | + def test_print_error(self): |
| 143 | + """ |
| 144 | + Test print_error function |
| 145 | + """ |
| 146 | + msg = "This is yellow: " + colorize("a banana", color='yellow') |
| 147 | + self.mock_stderr(True) |
| 148 | + self.mock_stdout(True) |
| 149 | + print_error(msg) |
| 150 | + stderr = self.get_stderr() |
| 151 | + stdout = self.get_stdout() |
| 152 | + self.mock_stderr(False) |
| 153 | + self.mock_stdout(False) |
| 154 | + self.assertEqual(stdout, '') |
| 155 | + if HAVE_RICH: |
| 156 | + # when using Rich, message printed to stderr won't have funny terminal escape characters for the color |
| 157 | + expected = '\n\nThis is yellow: a banana\n\n' |
| 158 | + else: |
| 159 | + expected = '\nThis is yellow: \x1b[1;33ma banana\x1b[0m\n\n' |
| 160 | + self.assertEqual(stderr, expected) |
| 161 | + |
142 | 162 | def test_get_progress_bar(self): |
143 | 163 | """ |
144 | 164 | Test get_progress_bar. |
|
0 commit comments