Skip to content

Commit 1d4f237

Browse files
committed
Maybe actually fix tests
1 parent 0a28275 commit 1d4f237

File tree

3 files changed

+33
-32
lines changed

3 files changed

+33
-32
lines changed

com/win32com/test/testArrays.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# Originally contributed by Stefan Schukat as part of this arbitrary-sized
22
# arrays patch.
3+
from __future__ import annotations
4+
5+
import platform
6+
import unittest
37

48
from win32com.client import gencache
59
from win32com.test import util
610

711
ZeroD = 0
8-
OneDEmpty = []
12+
OneDEmpty: list[int] = []
913
OneD = [1, 2, 3]
1014
TwoD = [[1, 2, 3], [1, 2, 3], [1, 2, 3]]
1115

@@ -48,7 +52,12 @@ def _normalize_array(a):
4852
ret.append(_normalize_array(i))
4953
return ret
5054

51-
55+
@unittest.skipIf(
56+
platform.machine() == "ARM64",
57+
"PyCOMTest.ArrayTest cannot currently be run on ARM64 "
58+
+ "due to lacking win32com.universal implementation "
59+
+ "in com/win32com/src/univgw.cpp",
60+
)
5261
class ArrayTest(util.TestCase):
5362
def setUp(self):
5463
self.arr = gencache.EnsureDispatch("PyCOMTest.ArrayTest", bForDemand=False)

com/win32com/test/testPyComTest.py

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@
77
import datetime
88
import decimal
99
import os
10-
import platform
1110
import time
12-
from unittest import SkipTest
1311

1412
import pythoncom
1513
import win32com
1614
import win32com.test.util
1715
import win32timezone
1816
import winerror
1917
from win32api import CloseHandle, GetCurrentProcessId, OpenProcess
20-
from win32com import universal
2118
from win32com.client import (
2219
VARIANT,
2320
CastTo,
@@ -174,7 +171,7 @@ def _DumpFireds(self):
174171
if not self.fireds:
175172
print("ERROR: Nothing was received!")
176173
for firedId, no in self.fireds.items():
177-
progress("ID %d fired %d times" % (firedId, no))
174+
progress(f"ID {firedId} fired {no} times")
178175

179176

180177
# Test everything which can be tested using both the "dynamic" and "generated"
@@ -890,36 +887,29 @@ def TestVTableMI():
890887
pass
891888

892889

893-
def TestQueryInterface(long_lived_server=0, iterations=5):
890+
def TestQueryInterface(long_lived_server: bool = False, iterations=5):
894891
tester = win32com.client.Dispatch("PyCOMTest.PyCOMTest")
895892
if long_lived_server:
896893
# Create a local server
897894
t0 = win32com.client.Dispatch(
898895
"Python.Test.PyCOMTest", clsctx=pythoncom.CLSCTX_LOCAL_SERVER
899896
)
900-
# Request custom interfaces a number of times
901-
prompt = [
902-
"Testing QueryInterface without long-lived local-server #%d of %d...",
903-
"Testing QueryInterface with long-lived local-server #%d of %d...",
904-
]
897+
# Request custom interfaces a number of time
905898

906899
for i in range(iterations):
907-
progress(prompt[long_lived_server != 0] % (i + 1, iterations))
900+
progress(
901+
f"Testing QueryInterface "
902+
+ ("with" if long_lived_server else "without")
903+
+ f" long-lived local-server #{i + 1} of {iterations}..."
904+
)
908905
tester.TestQueryInterface()
909906

910907

911908
class Tester(win32com.test.util.TestCase):
912909
def testRegisterInterfacesAfterGencache(self) -> None:
913910
# We had a bug where RegisterInterfaces would fail if gencache had
914911
# already been run - exercise that here
915-
try:
916-
RegisterInterfaces("{6BCDCB60-5605-11D0-AE5F-CADD4C000000}", 0, 1, 1)
917-
except NotImplementedError:
918-
if platform.machine() == "ARM64":
919-
raise SkipTest(
920-
"`win32com.universal.RegisterInterfaces` doesn't support ARM64 yet"
921-
)
922-
raise
912+
RegisterInterfaces("{6BCDCB60-5605-11D0-AE5F-CADD4C000000}", 0, 1, 1)
923913

924914
def testVTableInProc(self) -> None:
925915
# We used to crash running this the second time - do it a few times
@@ -941,15 +931,15 @@ def testVTableMI(self):
941931
TestVTableMI()
942932

943933
def testMultiQueryInterface(self):
944-
TestQueryInterface(0, 6)
934+
TestQueryInterface(False, 6)
945935
# When we use the custom interface in the presence of a long-lived
946936
# local server, i.e. a local server that is already running when
947937
# we request an instance of our COM object, and remains afterwards,
948938
# then after repeated requests to create an instance of our object
949939
# the custom interface disappears -- i.e. QueryInterface fails with
950940
# E_NOINTERFACE. Set the upper range of the following test to 2 to
951-
# pass this test, i.e. TestQueryInterface(1,2)
952-
TestQueryInterface(1, 6)
941+
# pass this test, i.e. TestQueryInterface(True, 2)
942+
TestQueryInterface(True, 6)
953943

954944
def testDynamic(self):
955945
TestDynamic()

com/win32com/test/testall.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def CleanGenerated():
5252

5353
if os.path.isdir(win32com.__gen_path__):
5454
if verbosity > 1:
55-
print("Deleting files from %s" % (win32com.__gen_path__))
55+
print(f"Deleting files from", win32com.__gen_path__)
5656
shutil.rmtree(win32com.__gen_path__)
5757
import win32com.client.gencache
5858

@@ -78,17 +78,20 @@ def ExecuteSilentlyIfOK(cmd, testcase):
7878
rc = f.close()
7979
if rc:
8080
print(data)
81-
testcase.fail("Executing '%s' failed (%d)" % (cmd, rc))
81+
testcase.fail(f"Executing '{cmd}' failed ({rc})")
8282
# for "_d" builds, strip the '[xxx refs]' line
8383
return RemoveRefCountOutput(data)
8484

8585

86+
@unittest.skipIf(
87+
platform.machine() == "ARM64",
88+
"PyCOMTest cannot currently be run on ARM64 "
89+
+ "due to lacking win32com.universal implementation "
90+
+ "in com/win32com/src/univgw.cpp",
91+
)
8692
class PyCOMTest(TestCase):
8793
no_leak_tests = True # done by the test itself
8894

89-
@unittest.skipIf(
90-
platform.machine() == "ARM64", "PyCOMTest cannot currently be run on ARM64"
91-
)
9295
def testit(self):
9396
# Check that the item is registered, so we get the correct
9497
# 'skipped' behaviour (and recorded as such) rather than either
@@ -294,8 +297,7 @@ def usage(why):
294297
print("These tests may take *many* minutes to run - be patient!")
295298
print("(running from python.exe will avoid these leak tests)")
296299
print(
297-
"Executing level %d tests - %d test cases will be run"
298-
% (testLevel, suite.countTestCases())
300+
f"Executing level {testLevel} tests - {suite.countTestCases()} test cases will be run"
299301
)
300302
if verbosity == 1 and suite.countTestCases() < 70:
301303
# A little row of markers so the dots show how close to finished
@@ -310,7 +312,7 @@ def usage(why):
310312
desc = "\n".join(traceback.format_exception_only(exc_type, exc_val))
311313
testResult.stream.write(f"{mod_name}: {desc}")
312314
testResult.stream.writeln(
313-
"*** %d test(s) could not be run ***" % len(import_failures)
315+
f"*** {len(import_failures)} test(s) could not be run ***"
314316
)
315317

316318
# re-print unit-test error here so it is noticed

0 commit comments

Comments
 (0)