1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
#-----------------------------------------------------------------------------
# Copyright (c) 2021-2023, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License (version 2
# or later) with exception for distributing the bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#
# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
#-----------------------------------------------------------------------------
import pytest
from PyInstaller.utils.tests import importorskip, onedir_only
from PyInstaller.utils.hooks import can_import_module
# pywin32 provides several modules that can be imported on their own, such as win32api or win32com.
# They are located in three directories, which are added to search path via pywin32.pth:
# - win32
# - win32/lib
# - pythonwin
@importorskip('win32api') # Use win32api to check for presence of pywin32.
@pytest.mark.parametrize(
'module',
(
# Binary extensions from win32
'mmapfile',
'odbc',
'perfmon',
'servicemanager',
'timer',
'win32api',
'win32clipboard',
'win32console',
'win32cred',
'win32crypt',
'win32event',
'win32evtlog',
'win32file',
'win32gui',
'win32help',
'win32inet',
'win32job',
'win32lz',
'win32net',
'win32pdh',
'win32pipe',
'win32print',
'win32process',
'win32profile',
'win32ras',
'win32security',
'win32service',
'_win32sysloader',
'win32trace',
'win32transaction',
'win32ts',
'win32wnet',
'_winxptheme',
# Python modules from win32/lib
'afxres',
'commctrl',
'dbi',
'mmsystem',
'netbios',
'ntsecuritycon',
'pywin32_bootstrap',
'pywin32_testutil',
'pywintypes',
'rasutil',
'regcheck',
'regutil',
'sspicon',
'sspi',
'win2kras',
'win32con',
'win32cryptcon',
'win32evtlogutil',
'win32gui_struct',
'win32inetcon',
'win32netcon',
'win32pdhquery',
'win32pdhutil',
'win32rcparser',
'win32serviceutil',
'win32timezone',
'win32traceutil',
'win32verstamp',
'winerror',
'winioctlcon',
'winnt',
'winperf',
'winxptheme',
# Binary extensions from pythonwin
'dde',
'win32uiole',
'win32ui',
# Python package from pythonwin
'pywin',
# Packages/modules in top-level directory
'adodbapi',
'isapi',
'win32com',
'win32comext',
'pythoncom',
)
)
@onedir_only
def test_pywin32_imports(pyi_builder, module):
if not can_import_module(module):
pytest.skip(f"Module '{module}' cannot be imported.")
# Basic import test
pyi_builder.test_source(f"""
import {module}
""")
@importorskip('win32com')
def test_pywin32_win32com(pyi_builder):
pyi_builder.test_source(
"""
# Test importing some modules from pywin32 package.
# All modules from pywin32 depens on module pywintypes.
# This module should be also included.
import win32com
import win32com.client
import win32com.server
"""
)
@importorskip('win32com')
def test_pywin32_comext(pyi_builder):
pyi_builder.test_source(
"""
# Test importing modules from win32com that are actually present in
# win32comext, and made available by __path__ changes in win32com.
from win32com.shell import shell
from win32com.propsys import propsys
from win32com.bits import bits
"""
)
@importorskip('win32ui')
def test_pywin32_win32ui(pyi_builder):
pyi_builder.test_source(
"""
# Test importing some modules from pywin32 package.
# All modules from pywin32 depens on module pywintypes.
# This module should be also included.
import win32ui
from pywin.mfc.dialog import Dialog
d = Dialog(win32ui.IDD_SIMPLE_INPUT)
"""
)
|