diff --git a/pyproject.toml b/pyproject.toml index 9b9c85b..8f77d0c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,6 +12,7 @@ pydantic = ">=1.9.0,<3.0" pydantic-core = ">=2.14.6" cachetools = ">=4.2.2" pyjwt = "~=2.8.0" +sniffio = ">=1.3.0" [tool.poetry.group.test.dependencies] diff --git a/tests/installation/README.md b/tests/installation/README.md new file mode 100644 index 0000000..605902f --- /dev/null +++ b/tests/installation/README.md @@ -0,0 +1,15 @@ +# Installed-package smoke tests + +Run these checks in a fresh environment after building and installing the wheel, +without installing test or development extras. This catches runtime dependencies +that an existing development environment can accidentally provide. + +```sh +python -m pip wheel . --no-deps --wheel-dir dist +python -m venv /tmp/zhipuai-install-test +/tmp/zhipuai-install-test/bin/python -m pip install dist/zhipuai-*.whl +/tmp/zhipuai-install-test/bin/python -I tests/installation/test_installed_sdk.py -v +``` + +The isolated interpreter imports the installed package rather than the source +checkout. The tests create no API requests and require only runtime dependencies. diff --git a/tests/installation/test_installed_sdk.py b/tests/installation/test_installed_sdk.py new file mode 100644 index 0000000..e586b89 --- /dev/null +++ b/tests/installation/test_installed_sdk.py @@ -0,0 +1,27 @@ +"""Run with ``python -I`` after installing a wheel in a clean environment.""" + +import asyncio +import unittest + + +class InstalledSDKTests(unittest.TestCase): + def test_public_sdk_import(self): + from zhipuai import ZhipuAI + + with ZhipuAI(api_key='test-key') as client: + self.assertFalse(client.is_closed()) + self.assertTrue(client.is_closed()) + + def test_async_library_detection(self): + from zhipuai.core._utils import get_async_library + + self.assertEqual(get_async_library(), 'false') + + async def detect(): + return get_async_library() + + self.assertEqual(asyncio.run(detect()), 'asyncio') + + +if __name__ == '__main__': + unittest.main()