2424
2525npm_checked = False
2626
27+ EMTEST_SKIP_PYTHON_DEV_PACKAGES = int (os .getenv ('EMTEST_SKIP_PYTHON_DEV_PACKAGES' , '0' ))
28+
29+
30+ def requires_python_dev_packages (func ):
31+ assert callable (func )
32+
33+ @common .wraps (func )
34+ def decorated (self , * args , ** kwargs ):
35+ if EMTEST_SKIP_PYTHON_DEV_PACKAGES :
36+ return self .skipTest ('python websockify based tests are disabled by EMTEST_SKIP_PYTHON_DEV_PACKAGES=1' )
37+ return func (self , * args , ** kwargs )
38+
39+ return decorated
40+
2741
2842def clean_processes (processes ):
2943 for p in processes :
@@ -61,7 +75,10 @@ def __enter__(self):
6175 process = Popen ([os .path .abspath ('server' )])
6276 self .processes .append (process )
6377
64- import websockify # type: ignore
78+ try :
79+ import websockify # type: ignore
80+ except ModuleNotFoundError :
81+ raise Exception ('Unable to import module websockify. Run "python3 -m pip install websockify" or set environment variable EMTEST_SKIP_PYTHON_DEV_PACKAGES=1 to skip this test.' ) from None
6582
6683 # start the websocket proxy
6784 print ('running websockify on %d, forward to tcp %d' % (self .listen_port , self .target_port ), file = sys .stderr )
@@ -184,6 +201,9 @@ def test_sockets_echo(self, harness_class, port, args):
184201 if harness_class == WebsockifyServerHarness and common .EMTEST_LACKS_NATIVE_CLANG :
185202 self .skipTest ('requires native clang' )
186203
204+ if harness_class == WebsockifyServerHarness and EMTEST_SKIP_PYTHON_DEV_PACKAGES :
205+ self .skipTest ('requires python websockify and EMTEST_SKIP_PYTHON_DEV_PACKAGES=1' )
206+
187207 with harness_class (test_file ('sockets/test_sockets_echo_server.c' ), args , port ) as harness :
188208 self .btest_exit ('sockets/test_sockets_echo_client.c' , cflags = ['-DSOCKK=%d' % harness .listen_port ] + args )
189209
@@ -205,6 +225,8 @@ def test_sdl2_sockets_echo(self):
205225 def test_sockets_async_echo (self , harness_class , port , args ):
206226 if harness_class == WebsockifyServerHarness and common .EMTEST_LACKS_NATIVE_CLANG :
207227 self .skipTest ('requires native clang' )
228+ if harness_class == WebsockifyServerHarness and EMTEST_SKIP_PYTHON_DEV_PACKAGES :
229+ self .skipTest ('requires python websockify and EMTEST_SKIP_PYTHON_DEV_PACKAGES=1' )
208230
209231 args .append ('-DTEST_ASYNC=1' )
210232 with harness_class (test_file ('sockets/test_sockets_echo_server.c' ), args , port ) as harness :
@@ -223,6 +245,8 @@ def test_sockets_async_bad_port(self):
223245 def test_sockets_echo_bigdata (self , harness_class , port , args ):
224246 if harness_class == WebsockifyServerHarness and common .EMTEST_LACKS_NATIVE_CLANG :
225247 self .skipTest ('requires native clang' )
248+ if harness_class == WebsockifyServerHarness and EMTEST_SKIP_PYTHON_DEV_PACKAGES :
249+ self .skipTest ('requires python websockify and EMTEST_SKIP_PYTHON_DEV_PACKAGES=1' )
226250 sockets_include = '-I' + test_file ('sockets' )
227251
228252 # generate a large string literal to use as our message
@@ -238,6 +262,7 @@ def test_sockets_echo_bigdata(self, harness_class, port, args):
238262 self .btest_exit ('test_sockets_echo_bigdata.c' , cflags = [sockets_include , '-DSOCKK=%d' % harness .listen_port ] + args )
239263
240264 @no_windows ('This test is Unix-specific.' )
265+ @requires_python_dev_packages
241266 def test_sockets_partial (self ):
242267 for harness in [
243268 WebsockifyServerHarness (test_file ('sockets/test_sockets_partial_server.c' ), [], 49180 ),
@@ -247,6 +272,7 @@ def test_sockets_partial(self):
247272 self .btest_exit ('sockets/test_sockets_partial_client.c' , assert_returncode = 165 , cflags = ['-DSOCKK=%d' % harness .listen_port ])
248273
249274 @no_windows ('This test is Unix-specific.' )
275+ @requires_python_dev_packages
250276 def test_sockets_select_server_down (self ):
251277 for harness in [
252278 WebsockifyServerHarness (test_file ('sockets/test_sockets_select_server_down_server.c' ), [], 49190 , do_server_check = False ),
@@ -256,6 +282,7 @@ def test_sockets_select_server_down(self):
256282 self .btest_exit ('sockets/test_sockets_select_server_down_client.c' , cflags = ['-DSOCKK=%d' % harness .listen_port ])
257283
258284 @no_windows ('This test is Unix-specific.' )
285+ @requires_python_dev_packages
259286 def test_sockets_select_server_closes_connection_rw (self ):
260287 for harness in [
261288 WebsockifyServerHarness (test_file ('sockets/test_sockets_echo_server.c' ), ['-DCLOSE_CLIENT_AFTER_ECHO' ], 49200 ),
@@ -286,6 +313,8 @@ def test_enet(self):
286313 def test_nodejs_sockets_echo (self , harness_class , port , args ):
287314 if harness_class == WebsockifyServerHarness and common .EMTEST_LACKS_NATIVE_CLANG :
288315 self .skipTest ('requires native clang' )
316+ if harness_class == WebsockifyServerHarness and EMTEST_SKIP_PYTHON_DEV_PACKAGES :
317+ self .skipTest ('requires python websockify and EMTEST_SKIP_PYTHON_DEV_PACKAGES=1' )
289318
290319 # Basic test of node client against both a Websockified and compiled echo server.
291320 with harness_class (test_file ('sockets/test_sockets_echo_server.c' ), args , port ) as harness :
@@ -296,6 +325,7 @@ def test_nodejs_sockets_connect_failure(self):
296325 self .do_runf ('sockets/test_sockets_echo_client.c' , 'connect failed: Connection refused' , cflags = ['-DSOCKK=666' ], assert_returncode = NON_ZERO )
297326
298327 @requires_native_clang
328+ @requires_python_dev_packages
299329 def test_nodejs_sockets_echo_subprotocol (self ):
300330 # Test against a Websockified server with compile time configured WebSocket subprotocol. We use a Websockified
301331 # server because as long as the subprotocol list contains binary it will configure itself to accept binary
@@ -308,6 +338,7 @@ def test_nodejs_sockets_echo_subprotocol(self):
308338 self .assertContained (['connect: ws://127.0.0.1:59168, base64,binary' , 'connect: ws://127.0.0.1:59168/, base64,binary' ], out )
309339
310340 @requires_native_clang
341+ @requires_python_dev_packages
311342 def test_nodejs_sockets_echo_subprotocol_runtime (self ):
312343 # Test against a Websockified server with runtime WebSocket configuration. We specify both url and subprotocol.
313344 # In this test we have *deliberately* used the wrong port '-DSOCKK=12345' to configure the echo_client.c, so
0 commit comments