matlab-proxy 0.24.1__py3-none-any.whl → 0.25.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of matlab-proxy might be problematic. Click here for more details.

@@ -1,9 +1,9 @@
1
- # Copyright 2020-2024 The MathWorks, Inc.
1
+ # Copyright 2020-2025 The MathWorks, Inc.
2
2
 
3
3
  import os
4
- import ssl
5
4
  import time
6
5
  import tempfile
6
+ import platform
7
7
 
8
8
  import matlab_proxy
9
9
  import matlab_proxy.settings as settings
@@ -467,29 +467,193 @@ def test_get_ssl_context_with_invalid_custom_ssl_files_raises_exception(
467
467
  )
468
468
  def test_get_matlab_settings_custom_code(
469
469
  monkeypatch,
470
- mocker,
471
470
  expected_value_for_has_custom_code,
472
471
  custom_code,
473
472
  has_custom_code_exception_matlab_cmd,
474
473
  ):
475
474
  # Arrange
476
475
  monkeypatch.setenv(mwi_env.get_env_name_custom_matlab_code(), custom_code)
476
+
477
+ # Act
478
+ has_custom_code, code_to_execute = settings._get_matlab_code_to_execute()
479
+ exception_present_in_matlab_cmd = "MATLABCustomStartupCodeError" in code_to_execute
480
+
481
+ # Assert
482
+ assert has_custom_code == expected_value_for_has_custom_code
483
+ assert exception_present_in_matlab_cmd == has_custom_code_exception_matlab_cmd
484
+
485
+
486
+ def test_get_nlm_conn_str(monkeypatch):
487
+ # Arrange
488
+ test_nlm_str = "123@license_server_address"
489
+ monkeypatch.setenv(mwi_env.get_env_name_network_license_manager(), test_nlm_str)
490
+
491
+ # Act
492
+ nlm_conn_str = settings._get_nlm_conn_str()
493
+
494
+ # Assert
495
+ assert nlm_conn_str == test_nlm_str
496
+
497
+
498
+ @pytest.mark.parametrize("ws_env_suffix", ["", "-dev", "-test"])
499
+ def test_get_mw_licensing_urls(ws_env_suffix):
500
+ # Act
501
+ urls = settings._get_mw_licensing_urls(ws_env_suffix)
502
+
503
+ # Assert
504
+ assert all(ws_env_suffix in url for url in urls.values())
505
+
506
+
507
+ @pytest.mark.parametrize("nlm_conn_str", [None, "1234@testserver"])
508
+ def test_get_matlab_cmd_posix(nlm_conn_str, mocker):
509
+ # Arrange
510
+ matlab_executable_path = "/path/to/matlab"
511
+ code_to_execute = "disp('Test')"
512
+ mocker.patch("matlab_proxy.settings.system.is_windows", return_value=False)
513
+
514
+ # Act
515
+ cmd = settings._get_matlab_cmd(
516
+ matlab_executable_path, code_to_execute, nlm_conn_str
517
+ )
518
+
519
+ # Assert
520
+ assert cmd[0] == matlab_executable_path
521
+ assert "-noDisplayDesktop" not in cmd
522
+
523
+ if nlm_conn_str:
524
+ assert "-licmode" in cmd
525
+ assert "file" in cmd
526
+ else:
527
+ assert "-licmode" not in cmd
528
+
529
+
530
+ def test_get_matlab_cmd_windows(mocker):
531
+ # Arrange
532
+ matlab_executable_path = "C:\\path\\to\\matlab.exe"
533
+ code_to_execute = "disp('Test')"
534
+ mocker.patch("matlab_proxy.settings.system.is_windows", return_value=True)
535
+
536
+ # Act
537
+ cmd = settings._get_matlab_cmd(matlab_executable_path, code_to_execute, None)
538
+
539
+ # Assert
540
+ assert "-noDisplayDesktop" in cmd
541
+ assert "-wait" in cmd
542
+ assert "-log" in cmd
543
+ assert ".exe" in cmd[0] # Assert .exe suffix in matlab_executable_path
544
+
545
+
546
+ def test_get_matlab_cmd_with_startup_profiling(mocker):
547
+ # Arrange
548
+ mocker.patch("matlab_proxy.settings.system.is_windows", return_value=False)
477
549
  mocker.patch(
478
- "matlab_proxy.settings.get_matlab_executable_and_root_path",
479
- return_value=("matlab", None),
550
+ "matlab_proxy.settings.mwi_env.Experimental.is_matlab_startup_profiling_enabled",
551
+ return_value=True,
480
552
  )
481
553
 
554
+ matlab_executable_path = "/path/to/matlab"
555
+ code_to_execute = "disp('Test')"
556
+
557
+ # Act
558
+ cmd = settings._get_matlab_cmd(matlab_executable_path, code_to_execute, None)
559
+
560
+ # Assert
561
+ assert "-timing" in cmd
562
+
563
+
564
+ def test_get_matlab_settings_no_matlab_on_path(mocker):
565
+ # Arrange
566
+ mocker.patch("matlab_proxy.settings.shutil.which", return_value=None)
567
+
482
568
  # Act
483
569
  matlab_settings = settings.get_matlab_settings()
484
- exception_present_in_matlab_cmd = (
485
- "MATLABCustomStartupCodeError" in matlab_settings["matlab_cmd"][-1]
570
+
571
+ # Assert
572
+ assert isinstance(matlab_settings["error"], MatlabInstallError)
573
+
574
+
575
+ def test_get_matlab_settings_matlab_softlink(mocker, tmp_path):
576
+ # Arrange
577
+ matlab_root_path = Path(tmp_path)
578
+ matlab_exec_path = matlab_root_path / "bin" / "matlab"
579
+ mocker.patch("matlab_proxy.settings.shutil.which", return_value=matlab_exec_path)
580
+ mocker.patch(
581
+ "matlab_proxy.settings.mwi.validators.validate_matlab_root_path",
582
+ return_value=matlab_root_path,
486
583
  )
487
- print(matlab_settings)
584
+
585
+ # Act
586
+ matlab_settings = settings.get_matlab_settings()
488
587
 
489
588
  # Assert
589
+ assert str(matlab_exec_path) in str(matlab_settings["matlab_cmd"][0])
590
+ assert matlab_settings["matlab_path"] == matlab_root_path
591
+ assert (
592
+ matlab_settings["matlab_version"] is None
593
+ ) # There's no VersionInfo.xml file in the mock setup
594
+
595
+
596
+ def test_get_matlab_settings_matlab_wrapper(mocker, tmp_path):
597
+ # Arrange
598
+ matlab_exec_path = Path(tmp_path) / "matlab"
599
+ mocker.patch("matlab_proxy.settings.shutil.which", return_value=matlab_exec_path)
600
+
601
+ # Act
602
+ matlab_settings = settings.get_matlab_settings()
603
+
604
+ # Assert
605
+ assert str(matlab_exec_path) in str(matlab_settings["matlab_cmd"][0])
606
+ assert (
607
+ matlab_settings["matlab_path"] is None
608
+ ) # Matlab root could not be determined because wrapper script is being used
609
+ assert matlab_settings["matlab_version"] is None
490
610
  assert (
491
- matlab_settings["has_custom_code_to_execute"]
492
- == expected_value_for_has_custom_code
611
+ matlab_settings["error"] is None
612
+ ) # Error has to be None when matlab executable is on PATH but root path could not be determined
613
+
614
+
615
+ def test_get_matlab_settings_valid_custom_matlab_root(mocker, monkeypatch, tmp_path):
616
+ # Arrange
617
+ matlab_root_path = Path(tmp_path)
618
+ matlab_exec_path = matlab_root_path / "bin" / "matlab"
619
+ matlab_version = "R2024b"
620
+ monkeypatch.setenv(mwi_env.get_env_name_custom_matlab_root(), str(matlab_root_path))
621
+ mocker.patch(
622
+ "matlab_proxy.settings.mwi.validators.validate_matlab_root_path",
623
+ return_value=matlab_root_path,
624
+ )
625
+ mocker.patch(
626
+ "matlab_proxy.settings.get_matlab_version", return_value=matlab_version
493
627
  )
494
628
 
495
- assert exception_present_in_matlab_cmd == has_custom_code_exception_matlab_cmd
629
+ # Act
630
+ matlab_settings = settings.get_matlab_settings()
631
+
632
+ # Assert
633
+ assert str(matlab_exec_path) in str(matlab_settings["matlab_cmd"][0])
634
+ assert matlab_settings["matlab_path"] == matlab_root_path
635
+ assert matlab_settings["matlab_version"] == matlab_version
636
+ assert matlab_settings["error"] is None
637
+
638
+
639
+ def test_get_matlab_settings_invalid_custom_matlab_root(mocker, monkeypatch, tmp_path):
640
+ # Arrange
641
+ matlab_root_path = Path(tmp_path)
642
+ monkeypatch.setenv(mwi_env.get_env_name_custom_matlab_root(), str(matlab_root_path))
643
+
644
+ # Act
645
+ matlab_settings = settings.get_matlab_settings()
646
+
647
+ # Assert
648
+ # When custom MATLAB root is supplied, it must be the actual MATLAB root ie.
649
+ # VersionInfo.xml file must to be there
650
+ # matlab executable inside the bin folder must be there
651
+ # If not, MATLAB related settings should be None and custom MATLAB root error should be present
652
+ assert matlab_settings["matlab_cmd"] is None
653
+ assert matlab_settings["matlab_path"] is None
654
+ assert matlab_settings["matlab_version"] is None
655
+ assert (
656
+ isinstance(matlab_settings["error"], MatlabInstallError)
657
+ and mwi_env.get_env_name_custom_matlab_root()
658
+ in matlab_settings["error"].message
659
+ )
@@ -1,4 +1,4 @@
1
- # Copyright 2023-2024 The MathWorks, Inc.
1
+ # Copyright 2023-2025 The MathWorks, Inc.
2
2
 
3
3
  import pytest
4
4
  from aiohttp import web
@@ -90,7 +90,7 @@ async def fake_endpoint(request):
90
90
 
91
91
  @pytest.fixture
92
92
  def fake_server_with_auth_enabled(
93
- loop, aiohttp_client, monkeypatch, get_custom_auth_token_str
93
+ event_loop, aiohttp_client, monkeypatch, get_custom_auth_token_str
94
94
  ):
95
95
  auth_token = get_custom_auth_token_str
96
96
  auth_enablement = "True"
@@ -120,7 +120,7 @@ def fake_server_with_auth_enabled(
120
120
  aiohttp_session_setup(
121
121
  app, EncryptedCookieStorage(f, cookie_name="matlab-proxy-session")
122
122
  )
123
- return loop.run_until_complete(aiohttp_client(app))
123
+ return event_loop.run_until_complete(aiohttp_client(app))
124
124
 
125
125
 
126
126
  async def test_set_value_with_token(
@@ -256,7 +256,7 @@ async def test_get_value_with_token_in_query_params(
256
256
 
257
257
 
258
258
  @pytest.fixture
259
- def fake_server_without_auth_enabled(loop, aiohttp_client, monkeypatch):
259
+ def fake_server_without_auth_enabled(event_loop, aiohttp_client, monkeypatch):
260
260
  auth_enablement = "False"
261
261
  monkeypatch.setenv(
262
262
  mwi_env.get_env_name_enable_mwi_auth_token(), str(auth_enablement)
@@ -281,7 +281,7 @@ def fake_server_without_auth_enabled(loop, aiohttp_client, monkeypatch):
281
281
  aiohttp_session_setup(
282
282
  app, EncryptedCookieStorage(f, cookie_name="matlab-proxy-session")
283
283
  )
284
- return loop.run_until_complete(aiohttp_client(app))
284
+ return event_loop.run_until_complete(aiohttp_client(app))
285
285
 
286
286
 
287
287
  async def test_get_value(fake_server_without_auth_enabled):
@@ -1,4 +1,4 @@
1
- # Copyright 2020-2024 The MathWorks, Inc.
1
+ # Copyright 2020-2025 The MathWorks, Inc.
2
2
 
3
3
  """Tests for functions in matlab_proxy/util/mwi_validators.py"""
4
4
 
@@ -295,7 +295,7 @@ def test_validate_matlab_root_path(tmp_path):
295
295
  assert actual_matlab_root_custom == matlab_root
296
296
 
297
297
 
298
- def test_validate_matlab_root_path_invalid_root_path(tmp_path):
298
+ def test_validate_matlab_root_path_non_existent_root_path(tmp_path):
299
299
  """Checks if validate_matlab_root_path raises MatlabInstallError when non-existent path is supplied"""
300
300
  # Arrange
301
301
  matlab_root = Path(tmp_path) / "MATLAB"
@@ -315,22 +315,27 @@ def test_validate_matlab_root_path_invalid_root_path(tmp_path):
315
315
 
316
316
 
317
317
  def test_validate_matlab_root_path_non_existent_versioninfo_file(tmp_path):
318
- """Checks if validate_matlab_root_path does not raise any exceptions even if VersionInfo.xml file does not exist"""
318
+ """Checks if validate_matlab_root_path does not raise any exceptions even if VersionInfo.xml file does not exist
319
+ when matlab wrapper is used and raises an exception when custom matlab root is used.
320
+ """
319
321
  # Arrange
320
322
  matlab_root = Path(tmp_path) / "MATLAB"
321
323
  os.mkdir(matlab_root)
322
324
 
323
325
  # Act
326
+ # Location of VersionInfo.xml can't be determined with matlab wrapper script
327
+ # and error should not be raised
324
328
  actual_matlab_root = validate_matlab_root_path(
325
329
  matlab_root, is_custom_matlab_root=False
326
330
  )
327
- actual_matlab_root_custom = validate_matlab_root_path(
328
- matlab_root, is_custom_matlab_root=True
329
- )
331
+
332
+ # Location of VersionInfo.xml must be determinable when custom MATLAB root is supplied.
333
+ # If not, an exception must be raised
334
+ with pytest.raises(MatlabInstallError):
335
+ validate_matlab_root_path(matlab_root, is_custom_matlab_root=True)
330
336
 
331
337
  # Assert
332
338
  assert actual_matlab_root is None
333
- assert actual_matlab_root_custom is None
334
339
 
335
340
 
336
341
  @pytest.mark.parametrize(
@@ -1,4 +1,4 @@
1
- # Copyright 2020-2023 The MathWorks, Inc.
1
+ # Copyright 2020-2025 The MathWorks, Inc.
2
2
 
3
3
  import datetime
4
4
  import random
@@ -519,7 +519,7 @@ def test_range_matlab_connector_ports():
519
519
  not system.is_linux(),
520
520
  reason="Xvfb is only required on linux based operating systems",
521
521
  )
522
- async def test_create_xvfb_process(loop):
522
+ async def test_create_xvfb_process(event_loop):
523
523
  """Test to check if more than 1 xvfb process can be created with -displayfd flag
524
524
 
525
525
  Creates 2 xvfb processes with '-displayfd' flag and checks if the processes are
@@ -1,4 +1,4 @@
1
- # Copyright 2020-2024 The MathWorks, Inc.
1
+ # Copyright 2020-2025 The MathWorks, Inc.
2
2
 
3
3
  import asyncio
4
4
  import pytest
@@ -19,19 +19,19 @@ def test_get_supported_termination_signals():
19
19
  assert len(system.get_supported_termination_signals()) >= 1
20
20
 
21
21
 
22
- def test_add_signal_handlers(loop: asyncio.AbstractEventLoop):
23
- """Test to check if signal handlers are being added to asyncio loop
22
+ def test_add_signal_handlers(event_loop: asyncio.AbstractEventLoop):
23
+ """Test to check if signal handlers are being added to asyncio event_loop
24
24
 
25
25
  Args:
26
- loop (asyncio loop): In built-in pytest fixture.
26
+ event_loop (asyncio event loop): built-in pytest fixture.
27
27
  """
28
28
 
29
- loop = add_signal_handlers(loop)
29
+ event_loop = add_signal_handlers(event_loop)
30
30
 
31
31
  # In posix systems, event loop is modified with new signal handlers
32
32
  if system.is_posix():
33
- assert loop._signal_handlers is not None
34
- assert loop._signal_handlers.items() is not None
33
+ assert event_loop._signal_handlers is not None
34
+ assert event_loop._signal_handlers.items() is not None
35
35
 
36
36
  else:
37
37
  import signal