Skip to content

Commit

Permalink
Update doctest.
Browse files Browse the repository at this point in the history
  • Loading branch information
junkmd committed Dec 25, 2024
1 parent 76f7e5d commit 70222fb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/autotest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ./
17 changes: 14 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 19 additions & 19 deletions docs/source/server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit 70222fb

Please sign in to comment.