|
| 1 | +import pytest |
| 2 | +import importlib |
| 3 | +from subprocess import CalledProcessError |
| 4 | +script = importlib.import_module("aci-preupgrade-validation-script") |
| 5 | + |
| 6 | + |
| 7 | +@pytest.mark.parametrize( |
| 8 | + "cmd, splitlines, expected_output", |
| 9 | + [ |
| 10 | + (["echo", "$'hello\nworld'"], True, ["hello", "world"]), |
| 11 | + ("echo $'hello\nworld'", True, ["hello", "world"]), |
| 12 | + (["echo", "$'hello\nworld'"], False, "hello\nworld\n"), |
| 13 | + ("echo $'hello\nworld'", False, "hello\nworld\n"), |
| 14 | + ], |
| 15 | +) |
| 16 | +def test_run_cmds(cmd, splitlines, expected_output): |
| 17 | + result = script.run_cmd(cmd, splitlines) |
| 18 | + assert result == expected_output |
| 19 | + |
| 20 | + |
| 21 | +@pytest.mark.parametrize( |
| 22 | + "cmd, splitlines, expected_output", |
| 23 | + [ |
| 24 | + ("fake_command", True, ""), |
| 25 | + (["fake_command"], False, ""), |
| 26 | + ] |
| 27 | +) |
| 28 | +def test_non_existing_command(cmd, splitlines, expected_output): |
| 29 | + with pytest.raises(CalledProcessError): |
| 30 | + script.run_cmd(cmd, splitlines) |
0 commit comments