aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/test.yml30
-rw-r--r--pdm.lock23
-rw-r--r--pyproject.toml5
-rw-r--r--src/ipm/api.py2
-rw-r--r--test/infini.toml9
-rw-r--r--test/src/__init__.py1
-rw-r--r--tests/test_cli.py64
7 files changed, 126 insertions, 8 deletions
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000..f0c1b6c
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,30 @@
+on:
+ push:
+ workflow_dispatch:
+
+jobs:
+ tests:
+ name: Test IPM
+ runs-on: ubuntu-latest
+ permissions:
+ id-token: write
+ contents: write
+
+ steps:
+ - uses: actions/checkout@v4
+
+ - uses: actions/setup-python@v5
+ with:
+ python-version: "3.9"
+
+ - name: Setup PDM
+ run: |
+ pip install pdm
+ pdm add pytest
+
+ - name: Install IPM
+ run: pdm install
+
+ - name: Test API
+ run: |
+ pdm run python -m pytest tests/
diff --git a/pdm.lock b/pdm.lock
index a58f550..7233b29 100644
--- a/pdm.lock
+++ b/pdm.lock
@@ -2,10 +2,14 @@
# It is not intended for manual editing.
[metadata]
-groups = ["default"]
+groups = ["default", "test"]
strategy = ["cross_platform", "inherit_metadata"]
lock_version = "4.4.1"
+<<<<<<< HEAD
content_hash = "sha256:9470f87391867615509911906fda898fd0fc55d1edecca94597578d34f5713ab"
+=======
+content_hash = "sha256:7e92b84c2b52abef8bf2cca785657bbd0686221a6d3174500294332114b6df90"
+>>>>>>> 55623b0cb2e0cb49f5ff4f456121b07c2376659c
[[package]]
name = "certifi"
@@ -93,8 +97,13 @@ name = "colorama"
version = "0.4.6"
requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
summary = "Cross-platform colored terminal text."
+<<<<<<< HEAD
groups = ["default"]
marker = "sys_platform == \"win32\" or platform_system == \"Windows\""
+=======
+groups = ["default", "test"]
+marker = "sys_platform == \"win32\""
+>>>>>>> 55623b0cb2e0cb49f5ff4f456121b07c2376659c
files = [
{file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"},
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
@@ -105,7 +114,7 @@ name = "exceptiongroup"
version = "1.2.0"
requires_python = ">=3.7"
summary = "Backport of PEP 654 (exception groups)"
-groups = ["default"]
+groups = ["default", "test"]
marker = "python_version < \"3.11\""
files = [
{file = "exceptiongroup-1.2.0-py3-none-any.whl", hash = "sha256:4bfd3996ac73b41e9b9628b04e079f193850720ea5945fc96a08633c66912f14"},
@@ -128,7 +137,7 @@ name = "iniconfig"
version = "2.0.0"
requires_python = ">=3.7"
summary = "brain-dead simple config-ini parsing"
-groups = ["default"]
+groups = ["default", "test"]
files = [
{file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"},
{file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"},
@@ -168,7 +177,7 @@ name = "packaging"
version = "23.2"
requires_python = ">=3.7"
summary = "Core utilities for Python packages"
-groups = ["default"]
+groups = ["default", "test"]
files = [
{file = "packaging-23.2-py3-none-any.whl", hash = "sha256:8c491190033a9af7e1d931d0b5dacc2ef47509b34dd0de67ed209b5203fc88c7"},
{file = "packaging-23.2.tar.gz", hash = "sha256:048fb0e9405036518eaaf48a55953c750c11e1a1b68e0dd1a9d62ed0c092cfc5"},
@@ -179,7 +188,7 @@ name = "pluggy"
version = "1.3.0"
requires_python = ">=3.8"
summary = "plugin and hook calling mechanisms for python"
-groups = ["default"]
+groups = ["default", "test"]
files = [
{file = "pluggy-1.3.0-py3-none-any.whl", hash = "sha256:d89c696a773f8bd377d18e5ecda92b7a3793cbe66c87060a6fb58c7b6e1061f7"},
{file = "pluggy-1.3.0.tar.gz", hash = "sha256:cf61ae8f126ac6f7c451172cf30e3e43d3ca77615509771b3a984a0730651e12"},
@@ -190,7 +199,7 @@ name = "pytest"
version = "7.4.4"
requires_python = ">=3.7"
summary = "pytest: simple powerful testing with Python"
-groups = ["default"]
+groups = ["default", "test"]
dependencies = [
"colorama; sys_platform == \"win32\"",
"exceptiongroup>=1.0.0rc8; python_version < \"3.11\"",
@@ -237,7 +246,7 @@ name = "tomli"
version = "2.0.1"
requires_python = ">=3.7"
summary = "A lil' TOML parser"
-groups = ["default"]
+groups = ["default", "test"]
marker = "python_version < \"3.11\""
files = [
{file = "tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"},
diff --git a/pyproject.toml b/pyproject.toml
index 7b2c1e2..d10bb74 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -26,3 +26,8 @@ ipm = "ipm.__main__:main"
[tool.pdm]
package-type = "library"
+
+[tool.pdm.dev-dependencies]
+test = [
+ "pytest>=7.4.4",
+]
diff --git a/src/ipm/api.py b/src/ipm/api.py
index caeca6d..2cb6eee 100644
--- a/src/ipm/api.py
+++ b/src/ipm/api.py
@@ -68,7 +68,7 @@ def install(uri: str, index: str = "", echo: bool = False) -> None:
info("正在初始化 IPM 环境...", echo)
HOME.mkdir(parents=True, exist_ok=True)
- index = index if index else INDEX
+ index = index or INDEX
if uri.isalpha():
...
diff --git a/test/infini.toml b/test/infini.toml
new file mode 100644
index 0000000..cc0f720
--- /dev/null
+++ b/test/infini.toml
@@ -0,0 +1,9 @@
+[infini]
+name = "test"
+version = "0.1.0"
+description = "COC 规则包"
+license = "MIT"
+
+[requirements]
+
+[dependencies]
diff --git a/test/src/__init__.py b/test/src/__init__.py
new file mode 100644
index 0000000..d93492e
--- /dev/null
+++ b/test/src/__init__.py
@@ -0,0 +1 @@
+# Initialized `__init__.py` generated by ipm. \ No newline at end of file
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