diff options
| author | 2024-01-18 14:37:28 +0800 | |
|---|---|---|
| committer | 2024-01-18 14:37:28 +0800 | |
| commit | 63d2d92a0e8e559f25b3cd81542e9317fe72057f (patch) | |
| tree | 0c3a693e82c61e3dacafd62b291c5cc505f789b2 /tests/test_cli.py | |
| parent | 08c13ddd0bffd2fc08282afccc73980bdbbdab0d (diff) | |
| parent | 55623b0cb2e0cb49f5ff4f456121b07c2376659c (diff) | |
| download | ipm-63d2d92a0e8e559f25b3cd81542e9317fe72057f.tar.gz ipm-63d2d92a0e8e559f25b3cd81542e9317fe72057f.zip | |
:sparkles: feat(ci): use pdm run python instead
Diffstat (limited to 'tests/test_cli.py')
| -rw-r--r-- | tests/test_cli.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..8b22848 --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,64 @@ +# import pytest +# from ipm.__main__ import main +# from unittest.mock import patch, MagicMock + +# # Test IDs for parametrization +# HAPPY_PATH_INSTALL = "happy_install" +# HAPPY_PATH_EXTRACT = "happy_extract" +# HAPPY_PATH_BUILD = "happy_build" +# EDGE_CASE_NO_ARGS = "edge_no_args" +# ERROR_CASE_UNKNOWN_COMMAND = "error_unknown_command" + +# # Mock the sys.argv to simulate command line arguments +# @pytest.fixture +# def mock_sys_argv(monkeypatch): +# def _mock_sys_argv(args): +# monkeypatch.setattr("sys.argv", ["ipm"] + args) +# return _mock_sys_argv + +# # Mock the api functions to prevent actual execution +# @pytest.fixture +# def mock_api_functions(monkeypatch): +# install_mock = MagicMock() +# extract_mock = MagicMock() +# build_mock = MagicMock() +# monkeypatch.setattr("ipm.__main__.install", install_mock) +# monkeypatch.setattr("ipm.__main__.extract", extract_mock) +# monkeypatch.setattr("ipm.__main__.build", build_mock) +# return install_mock, extract_mock, build_mock + +# @pytest.mark.parametrize("test_id, args, expected_call", [ +# # Happy path tests +# (HAPPY_PATH_INSTALL, ["install", "http://ipm.hydroroll.team/package.ipk"], ("install", ["http://ipm.hydroroll.team/package.ipk", None])), +# (HAPPY_PATH_EXTRACT, ["extract", "package.ipk", "--dist", "dist_folder"], ("extract", ["package.ipk", "dist_folder"])), +# (HAPPY_PATH_BUILD, ["build", "source_folder"], ("build", ["source_folder"])), + +# # Edge case tests +# (EDGE_CASE_NO_ARGS, [], ("help", [])), + +# # Error case tests +# (ERROR_CASE_UNKNOWN_COMMAND, ["unknown", "arg"], ("error", ["unknown"])), +# ]) +# def test_main_commands(test_id, args, expected_call, mock_sys_argv, mock_api_functions, capsys): +# mock_sys_argv(args) +# install_mock, extract_mock, build_mock = mock_api_functions + +# # Act +# with pytest.raises(SystemExit): # argparse exits the program when -h is called or on error +# main() + +# # Assert +# if expected_call[0] == "install": +# install_mock.assert_called_once_with(*expected_call[1], echo=True) +# elif expected_call[0] == "extract": +# extract_mock.assert_called_once_with(*expected_call[1]) +# elif expected_call[0] == "build": +# build_mock.assert_called_once_with(*expected_call[1]) +# elif expected_call[0] == "help": +# captured = capsys.readouterr() +# assert "Infini 包管理器" in captured.out +# elif expected_call[0] == "error": +# captured = capsys.readouterr() +# assert "error: unrecognized arguments" in captured.err + +# pytest.main()
\ No newline at end of file |
