summaryrefslogtreecommitdiffstats
path: root/scripts/external_libs/pyzmq-14.5.0/python3/ucs4/32bit/zmq/tests/test_win32_shim.py
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2017-02-28 14:21:30 +0200
committerYaroslav Brustinov <ybrustin@cisco.com>2017-02-28 14:21:30 +0200
commitd3907f0dcac6c6e0d7b3c3abe69c64fe4e9dcaa6 (patch)
tree526e0d5300550f0c43a6638f80950c253cf141cf /scripts/external_libs/pyzmq-14.5.0/python3/ucs4/32bit/zmq/tests/test_win32_shim.py
parent2ba80c6a96d3b7af496428a68e59391daad34c86 (diff)
PyZMQ restore removed by accident version of Python3/32 bits
Change-Id: Ie8a54015a02bdcc5cd0a50faff7b82cf0ad8de93 Signed-off-by: Yaroslav Brustinov <ybrustin@cisco.com>
Diffstat (limited to 'scripts/external_libs/pyzmq-14.5.0/python3/ucs4/32bit/zmq/tests/test_win32_shim.py')
-rw-r--r--scripts/external_libs/pyzmq-14.5.0/python3/ucs4/32bit/zmq/tests/test_win32_shim.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/scripts/external_libs/pyzmq-14.5.0/python3/ucs4/32bit/zmq/tests/test_win32_shim.py b/scripts/external_libs/pyzmq-14.5.0/python3/ucs4/32bit/zmq/tests/test_win32_shim.py
new file mode 100644
index 00000000..55657bda
--- /dev/null
+++ b/scripts/external_libs/pyzmq-14.5.0/python3/ucs4/32bit/zmq/tests/test_win32_shim.py
@@ -0,0 +1,56 @@
+from __future__ import print_function
+
+import os
+
+from functools import wraps
+from zmq.tests import BaseZMQTestCase
+from zmq.utils.win32 import allow_interrupt
+
+
+def count_calls(f):
+ @wraps(f)
+ def _(*args, **kwds):
+ try:
+ return f(*args, **kwds)
+ finally:
+ _.__calls__ += 1
+ _.__calls__ = 0
+ return _
+
+
+class TestWindowsConsoleControlHandler(BaseZMQTestCase):
+
+ def test_handler(self):
+ @count_calls
+ def interrupt_polling():
+ print('Caught CTRL-C!')
+
+ if os.name == 'nt':
+ from ctypes import windll
+ from ctypes.wintypes import BOOL, DWORD
+
+ kernel32 = windll.LoadLibrary('kernel32')
+
+ # <http://msdn.microsoft.com/en-us/library/ms683155.aspx>
+ GenerateConsoleCtrlEvent = kernel32.GenerateConsoleCtrlEvent
+ GenerateConsoleCtrlEvent.argtypes = (DWORD, DWORD)
+ GenerateConsoleCtrlEvent.restype = BOOL
+
+ try:
+ # Simulate CTRL-C event while handler is active.
+ with allow_interrupt(interrupt_polling):
+ result = GenerateConsoleCtrlEvent(0, 0)
+ if result == 0:
+ raise WindowsError
+ except KeyboardInterrupt:
+ pass
+ else:
+ self.fail('Expecting `KeyboardInterrupt` exception!')
+
+ # Make sure our handler was called.
+ self.assertEqual(interrupt_polling.__calls__, 1)
+ else:
+ # On non-Windows systems, this utility is just a no-op!
+ with allow_interrupt(interrupt_polling):
+ pass
+ self.assertEqual(interrupt_polling.__calls__, 0)