|
| 1 | +#!/usr/bin/env python3 |
| 2 | +# |
| 3 | +# sonar-migration tests |
| 4 | +# Copyright (C) 2024 Olivier Korach |
| 5 | +# mailto:olivier.korach AT gmail DOT com |
| 6 | +# |
| 7 | +# This program is free software; you can redistribute it and/or |
| 8 | +# modify it under the terms of the GNU Lesser General Public |
| 9 | +# License as published by the Free Software Foundation; either |
| 10 | +# version 3 of the License, or (at your option) any later version. |
| 11 | +# |
| 12 | +# This program is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | +# Lesser General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU Lesser General Public License |
| 18 | +# along with this program; if not, write to the Free Software Foundation, |
| 19 | +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | +# |
| 21 | + |
| 22 | +""" sonar-migration tests """ |
| 23 | + |
| 24 | +import os |
| 25 | +import sys |
| 26 | +import json |
| 27 | +from unittest.mock import patch |
| 28 | +import pytest |
| 29 | + |
| 30 | +import utilities as util |
| 31 | +from sonar import errcodes |
| 32 | +import cli.options as opt |
| 33 | +from cli import migration |
| 34 | + |
| 35 | +CMD = "migration.py" |
| 36 | +OPTS = [CMD] + util.STD_OPTS + [f"-{opt.REPORT_FILE_SHORT}", util.JSON_FILE] |
| 37 | + |
| 38 | + |
| 39 | +def __test_config_cmd(arguments: list[str]) -> None: |
| 40 | + """Runs a test command""" |
| 41 | + outputfile = arguments[arguments.index(f"-{opt.REPORT_FILE_SHORT}") + 1] |
| 42 | + util.clean(outputfile) |
| 43 | + with pytest.raises(SystemExit) as e: |
| 44 | + with patch.object(sys, "argv", arguments): |
| 45 | + migration.main() |
| 46 | + assert int(str(e.value)) == errcodes.OK |
| 47 | + assert util.file_not_empty(outputfile) |
| 48 | + util.clean(outputfile) |
| 49 | + |
| 50 | +def test_migration_help() -> None: |
| 51 | + """test_migration_help""" |
| 52 | + util.clean(util.JSON_FILE) |
| 53 | + with pytest.raises(SystemExit) as e: |
| 54 | + with patch.object(sys, "argv", OPTS + ["-h"]): |
| 55 | + migration.main() |
| 56 | + assert int(str(e.value)) == 10 |
| 57 | + assert not os.path.isfile(util.JSON_FILE) |
| 58 | + |
| 59 | + |
| 60 | +def test_migration_basic() -> None: |
| 61 | + """test_config_export""" |
| 62 | + __test_config_cmd(OPTS) |
0 commit comments