From e8f658b168ac5348aff55c45ccda233e710ac921 Mon Sep 17 00:00:00 2001 From: Jun Komoda <45822440+junkmd@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:39:35 +0000 Subject: [PATCH 1/5] Revert temporarily renaming modules. --- comtypes/server/{_w_getopt.py => w_getopt.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename comtypes/server/{_w_getopt.py => w_getopt.py} (100%) diff --git a/comtypes/server/_w_getopt.py b/comtypes/server/w_getopt.py similarity index 100% rename from comtypes/server/_w_getopt.py rename to comtypes/server/w_getopt.py From ef969e8f983c86e7dc97e1d754a2c7ac7337431c Mon Sep 17 00:00:00 2001 From: Jun Komoda <45822440+junkmd@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:39:35 +0000 Subject: [PATCH 2/5] Revert temporarily renaming modules. --- comtypes/server/register.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/comtypes/server/register.py b/comtypes/server/register.py index e48fb1a24..41c6ffc74 100644 --- a/comtypes/server/register.py +++ b/comtypes/server/register.py @@ -44,7 +44,7 @@ import comtypes from comtypes.typeinfo import LoadTypeLibEx, UnRegisterTypeLib, REGKIND_REGISTER from comtypes.hresult import * -from comtypes.server import _w_getopt as w_getopt +from comtypes.server import w_getopt import comtypes.server.inprocserver from ctypes import windll, c_ulong, c_wchar_p, WinError, sizeof, create_string_buffer From b47957da1dbb369f47eaf5566376c30cf6c96f90 Mon Sep 17 00:00:00 2001 From: Jun Komoda <45822440+junkmd@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:39:35 +0000 Subject: [PATCH 3/5] Update test section. --- comtypes/test/test_w_getopt.py | 48 +++------------------------------- 1 file changed, 3 insertions(+), 45 deletions(-) diff --git a/comtypes/test/test_w_getopt.py b/comtypes/test/test_w_getopt.py index b0ae0b9e4..1822b4474 100644 --- a/comtypes/test/test_w_getopt.py +++ b/comtypes/test/test_w_getopt.py @@ -1,50 +1,8 @@ -class GetoptError(Exception): - pass +from comtypes.server.w_getopt import GetoptError, w_getopt -def w_getopt(args, options): - """A getopt for Windows. - - Options may start with either '-' or '/', the option names may - have more than one letter (/tlb or -RegServer), and option names - are case insensitive. - - Returns two elements, just as getopt.getopt. The first is a list - of (option, value) pairs in the same way getopt.getopt does, but - there is no '-' or '/' prefix to the option name, and the option - name is always lower case. The second is the list of arguments - which do not belong to an option. - - Different from getopt.getopt, a single argument not belonging to an option - does not terminate parsing. - """ - opts = [] - arguments = [] - while args: - if args[0][:1] in "/-": - arg = args[0][1:] # strip the '-' or '/' - arg = arg.lower() - - if arg + ":" in options: - try: - opts.append((arg, args[1])) - except IndexError: - raise GetoptError(f"option '{args[0]}' requires an argument") - args = args[1:] - elif arg in options: - opts.append((arg, "")) - else: - raise GetoptError(f"invalid option '{args[0]}'") - args = args[1:] - else: - arguments.append(args[0]) - args = args[1:] - - return opts, arguments - - -if __debug__: - if __name__ == "__main__": +if True: + if True: import unittest class TestCase(unittest.TestCase): From d6b38e57dfb3d80e915e2db80916c3fa7194ab41 Mon Sep 17 00:00:00 2001 From: Jun Komoda <45822440+junkmd@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:39:35 +0000 Subject: [PATCH 4/5] Remove test section. --- comtypes/server/w_getopt.py | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/comtypes/server/w_getopt.py b/comtypes/server/w_getopt.py index b0ae0b9e4..6b0efac12 100644 --- a/comtypes/server/w_getopt.py +++ b/comtypes/server/w_getopt.py @@ -41,35 +41,3 @@ def w_getopt(args, options): args = args[1:] return opts, arguments - - -if __debug__: - if __name__ == "__main__": - import unittest - - class TestCase(unittest.TestCase): - def test_1(self): - args = "-embedding spam /RegServer foo /UnregSERVER blabla".split() - opts, args = w_getopt(args, "regserver unregserver embedding".split()) - self.assertEqual( - opts, [("embedding", ""), ("regserver", ""), ("unregserver", "")] - ) - self.assertEqual(args, ["spam", "foo", "blabla"]) - - def test_2(self): - args = "/TLB Hello.Tlb HELLO.idl".split() - opts, args = w_getopt(args, ["tlb:"]) - self.assertEqual(opts, [("tlb", "Hello.Tlb")]) - self.assertEqual(args, ["HELLO.idl"]) - - def test_3(self): - # Invalid option - self.assertRaises( - GetoptError, w_getopt, "/TLIB hello.tlb hello.idl".split(), ["tlb:"] - ) - - def test_4(self): - # Missing argument - self.assertRaises(GetoptError, w_getopt, "/TLB".split(), ["tlb:"]) - - unittest.main() From 0018a6a952160d463bdbc49a2ad05d513f8ecda7 Mon Sep 17 00:00:00 2001 From: Jun Komoda <45822440+junkmd@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:39:35 +0000 Subject: [PATCH 5/5] Update `test_w_getopt.py`. --- comtypes/test/test_w_getopt.py | 50 ++++++++++++++++------------------ 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/comtypes/test/test_w_getopt.py b/comtypes/test/test_w_getopt.py index 1822b4474..63cee25b1 100644 --- a/comtypes/test/test_w_getopt.py +++ b/comtypes/test/test_w_getopt.py @@ -1,33 +1,29 @@ -from comtypes.server.w_getopt import GetoptError, w_getopt - +import unittest -if True: - if True: - import unittest +from comtypes.server.w_getopt import GetoptError, w_getopt - class TestCase(unittest.TestCase): - def test_1(self): - args = "-embedding spam /RegServer foo /UnregSERVER blabla".split() - opts, args = w_getopt(args, "regserver unregserver embedding".split()) - self.assertEqual( - opts, [("embedding", ""), ("regserver", ""), ("unregserver", "")] - ) - self.assertEqual(args, ["spam", "foo", "blabla"]) - def test_2(self): - args = "/TLB Hello.Tlb HELLO.idl".split() - opts, args = w_getopt(args, ["tlb:"]) - self.assertEqual(opts, [("tlb", "Hello.Tlb")]) - self.assertEqual(args, ["HELLO.idl"]) +class TestCase(unittest.TestCase): + def test_1(self): + args = "-embedding spam /RegServer foo /UnregSERVER blabla".split() + opts, args = w_getopt(args, "regserver unregserver embedding".split()) + self.assertEqual( + opts, [("embedding", ""), ("regserver", ""), ("unregserver", "")] + ) + self.assertEqual(args, ["spam", "foo", "blabla"]) - def test_3(self): - # Invalid option - self.assertRaises( - GetoptError, w_getopt, "/TLIB hello.tlb hello.idl".split(), ["tlb:"] - ) + def test_2(self): + args = "/TLB Hello.Tlb HELLO.idl".split() + opts, args = w_getopt(args, ["tlb:"]) + self.assertEqual(opts, [("tlb", "Hello.Tlb")]) + self.assertEqual(args, ["HELLO.idl"]) - def test_4(self): - # Missing argument - self.assertRaises(GetoptError, w_getopt, "/TLB".split(), ["tlb:"]) + def test_3(self): + # Invalid option + self.assertRaises( + GetoptError, w_getopt, "/TLIB hello.tlb hello.idl".split(), ["tlb:"] + ) - unittest.main() + def test_4(self): + # Missing argument + self.assertRaises(GetoptError, w_getopt, "/TLB".split(), ["tlb:"])