|
| 1 | +import pytest |
| 2 | +import warnings |
| 3 | + |
| 4 | +import reframe.core.runtime as rt |
| 5 | +import reframe.core.warnings as warn |
| 6 | +import reframe.utility.color as color |
| 7 | +import unittests.fixtures as fixtures |
| 8 | + |
| 9 | + |
| 10 | +@pytest.fixture(params=['colors', 'nocolors']) |
| 11 | +def with_colors(request): |
| 12 | + with rt.temp_runtime(fixtures.BUILTIN_CONFIG_FILE, 'generic', |
| 13 | + {'general/colorize': request.param == 'colors'}): |
| 14 | + yield request.param == 'colors' |
| 15 | + |
| 16 | + |
| 17 | +def test_deprecation_warning(): |
| 18 | + with pytest.warns(warn.ReframeDeprecationWarning): |
| 19 | + warn.user_deprecation_warning('deprecated') |
| 20 | + |
| 21 | + |
| 22 | +def test_deprecation_warning_formatting(with_colors): |
| 23 | + message = warnings.formatwarning( |
| 24 | + 'deprecated', warn.ReframeDeprecationWarning, 'file', 10, 'a = 1' |
| 25 | + ) |
| 26 | + expected = 'file:10: WARNING: deprecated\na = 1\n' |
| 27 | + if with_colors: |
| 28 | + expected = color.colorize(expected, color.YELLOW) |
| 29 | + |
| 30 | + assert message == expected |
| 31 | + |
| 32 | + |
| 33 | +def test_deprecation_warning_formatting_noline(tmp_path, with_colors): |
| 34 | + srcfile = tmp_path / 'file' |
| 35 | + srcfile.touch() |
| 36 | + |
| 37 | + message = warnings.formatwarning( |
| 38 | + 'deprecated', warn.ReframeDeprecationWarning, srcfile, 10 |
| 39 | + ) |
| 40 | + expected = f'{srcfile}:10: WARNING: deprecated\n<no line information>\n' |
| 41 | + if with_colors: |
| 42 | + expected = color.colorize(expected, color.YELLOW) |
| 43 | + |
| 44 | + assert message == expected |
| 45 | + |
| 46 | + |
| 47 | +def test_random_warning_formatting(): |
| 48 | + message = warnings.formatwarning( |
| 49 | + 'deprecated', UserWarning, 'file', 10, 'a = 1' |
| 50 | + ) |
| 51 | + assert message == f'file:10: UserWarning: deprecated\n a = 1\n' |
0 commit comments