From 70222fb5ff255299d33ca4b94941567bae3b1d28 Mon Sep 17 00:00:00 2001 From: Jun Komoda <45822440+junkmd@users.noreply.github.com> Date: Wed, 25 Dec 2024 01:07:59 +0000 Subject: [PATCH] Update doctest. --- .github/workflows/autotest.yml | 4 ++++ docs/source/conf.py | 17 ++++++++++++--- docs/source/server.rst | 38 +++++++++++++++++----------------- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/.github/workflows/autotest.yml b/.github/workflows/autotest.yml index 3da62e5d..a995788b 100644 --- a/.github/workflows/autotest.yml +++ b/.github/workflows/autotest.yml @@ -73,6 +73,10 @@ jobs: run: | python -m pip install --upgrade pip pip install -r docs/requirements.txt + - name: Set up MSVC + uses: ilammy/msvc-dev-cmd@v1 + - name: Compile IDL + run: midl /out docs\source docs\source\mytypelib.idl - name: Run doctest run: sphinx-build -b doctest -d docs/build/doctrees docs/source docs/build/doctest working-directory: ./ diff --git a/docs/source/conf.py b/docs/source/conf.py index ea9efc19..02898181 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -250,18 +250,29 @@ # A string containing Python code that will be run before each test. Useful # for initializing objects or setting up specific conditions. -doctest_global_setup = """ +LIBID_EXCEL = "{00020813-0000-0000-C000-000000000046}" +MYTYPELIB_PATH = os.path.join(os.path.dirname(__file__), "mytypelib.tlb") + +doctest_global_setup = f""" global NO_EXCEL +import os + import comtypes.client try: - comtypes.client.GetModule(('{00020813-0000-0000-C000-000000000046}',)) - + comtypes.client.GetModule(('{LIBID_EXCEL}',)) NO_EXCEL = False except (ImportError, FileNotFoundError): NO_EXCEL = True + +try: + comtypes.client.GetModule('{MYTYPELIB_PATH}') + NO_MYTYPELIB = False +except (ImportError, FileNotFoundError): + NO_MYTYPELIB = True + """ # A string containing Python code that will be run after each test. Useful diff --git a/docs/source/server.rst b/docs/source/server.rst index 810ceb4a..e8e7367b 100644 --- a/docs/source/server.rst +++ b/docs/source/server.rst @@ -77,26 +77,26 @@ Most required class attributes are already defined in the typelib wrapper file. You must at least add attributes for registration that are not in the type library. -.. sourcecode:: python - - import comtypes - import comtypes.server.localserver - - from comtypes.client import GetModule - # generate wrapper code for the type library, this needs - # to be done only once (but also each time the IDL file changes) - GetModule("mytypelib.tlb") +.. doctest:: + :skipif: NO_MYTYPELIB + + >>> import comtypes + >>> import comtypes.server.localserver + >>> from comtypes.client import GetModule + >>> # generate wrapper code for the type library, this needs + >>> # to be done only once (but also each time the IDL file changes) + >>> GetModule("mytypelib.tlb") + >>> from comtypes.gen.MyTypeLib import MyObject + >>> class MyObjectImpl(MyObject): + ... # registry entries + ... _reg_threading_ = "Both" + ... _reg_progid_ = "MyTypeLib.MyObject.1" + ... _reg_novers_progid_ = "MyTypeLib.MyObject" + ... _reg_desc_ = "Simple COM server for testing" + ... _reg_clsctx_ = comtypes.CLSCTX_INPROC_SERVER | comtypes.CLSCTX_LOCAL_SERVER + ... _regcls_ = comtypes.server.localserver.REGCLS_MULTIPLEUSE + ... - from comtypes.gen.MyTypeLib import MyObject - - class MyObjectImpl(MyObject): - # registry entries - _reg_threading_ = "Both" - _reg_progid_ = "MyTypeLib.MyObject.1" - _reg_novers_progid_ = "MyTypeLib.MyObject" - _reg_desc_ = "Simple COM server for testing" - _reg_clsctx_ = comtypes.CLSCTX_INPROC_SERVER | comtypes.CLSCTX_LOCAL_SERVER - _regcls_ = comtypes.server.localserver.REGCLS_MULTIPLEUSE The meaning of the attributes: