matlab-proxy 0.24.1__py3-none-any.whl → 0.24.2__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.
- matlab_proxy/app_state.py +17 -8
- matlab_proxy/gui/index.html +1 -1
- matlab_proxy/gui/static/js/{index.Cm14Eqsb.js → index.c3NLxnRM.js} +4 -4
- matlab_proxy/settings.py +136 -86
- matlab_proxy/util/mwi/validators.py +19 -11
- {matlab_proxy-0.24.1.dist-info → matlab_proxy-0.24.2.dist-info}/METADATA +2 -2
- {matlab_proxy-0.24.1.dist-info → matlab_proxy-0.24.2.dist-info}/RECORD +14 -14
- tests/unit/test_app_state.py +29 -2
- tests/unit/test_settings.py +190 -11
- tests/unit/util/mwi/test_validators.py +12 -7
- {matlab_proxy-0.24.1.dist-info → matlab_proxy-0.24.2.dist-info}/LICENSE.md +0 -0
- {matlab_proxy-0.24.1.dist-info → matlab_proxy-0.24.2.dist-info}/WHEEL +0 -0
- {matlab_proxy-0.24.1.dist-info → matlab_proxy-0.24.2.dist-info}/entry_points.txt +0 -0
- {matlab_proxy-0.24.1.dist-info → matlab_proxy-0.24.2.dist-info}/top_level.txt +0 -0
tests/unit/test_settings.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
# Copyright 2020-
|
|
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,208 @@ 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_mpa_flags(mocker):
|
|
547
|
+
# Arrange
|
|
477
548
|
mocker.patch(
|
|
478
|
-
"matlab_proxy.settings.
|
|
479
|
-
return_value=("matlab", None),
|
|
549
|
+
"matlab_proxy.settings.mwi_env.Experimental.is_mpa_enabled", return_value=True
|
|
480
550
|
)
|
|
551
|
+
matlab_executable_path = "/path/to/matlab"
|
|
552
|
+
code_to_execute = "disp('Test')"
|
|
553
|
+
|
|
554
|
+
# Act
|
|
555
|
+
cmd = settings._get_matlab_cmd(matlab_executable_path, code_to_execute, None)
|
|
556
|
+
|
|
557
|
+
# Assert
|
|
558
|
+
assert all(mpa_flag in cmd for mpa_flag in mwi_env.Experimental.get_mpa_flags())
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
def test_get_matlab_cmd_with_startup_profiling(mocker):
|
|
562
|
+
# Arrange
|
|
563
|
+
mocker.patch("matlab_proxy.settings.system.is_windows", return_value=False)
|
|
564
|
+
mocker.patch(
|
|
565
|
+
"matlab_proxy.settings.mwi_env.Experimental.is_matlab_startup_profiling_enabled",
|
|
566
|
+
return_value=True,
|
|
567
|
+
)
|
|
568
|
+
|
|
569
|
+
matlab_executable_path = "/path/to/matlab"
|
|
570
|
+
code_to_execute = "disp('Test')"
|
|
571
|
+
|
|
572
|
+
# Act
|
|
573
|
+
cmd = settings._get_matlab_cmd(matlab_executable_path, code_to_execute, None)
|
|
574
|
+
|
|
575
|
+
# Assert
|
|
576
|
+
assert "-timing" in cmd
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
def test_get_matlab_settings_no_matlab_on_path(mocker):
|
|
580
|
+
# Arrange
|
|
581
|
+
mocker.patch("matlab_proxy.settings.shutil.which", return_value=None)
|
|
481
582
|
|
|
482
583
|
# Act
|
|
483
584
|
matlab_settings = settings.get_matlab_settings()
|
|
484
|
-
|
|
485
|
-
|
|
585
|
+
|
|
586
|
+
# Assert
|
|
587
|
+
assert isinstance(matlab_settings["error"], MatlabInstallError)
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
def test_get_matlab_settings_matlab_softlink(mocker, tmp_path):
|
|
591
|
+
# Arrange
|
|
592
|
+
matlab_root_path = Path(tmp_path)
|
|
593
|
+
matlab_exec_path = matlab_root_path / "bin" / "matlab"
|
|
594
|
+
mocker.patch("matlab_proxy.settings.shutil.which", return_value=matlab_exec_path)
|
|
595
|
+
mocker.patch(
|
|
596
|
+
"matlab_proxy.settings.mwi.validators.validate_matlab_root_path",
|
|
597
|
+
return_value=matlab_root_path,
|
|
486
598
|
)
|
|
487
|
-
|
|
599
|
+
|
|
600
|
+
# Act
|
|
601
|
+
matlab_settings = settings.get_matlab_settings()
|
|
602
|
+
|
|
603
|
+
# Assert
|
|
604
|
+
assert str(matlab_exec_path) in str(matlab_settings["matlab_cmd"][0])
|
|
605
|
+
assert matlab_settings["matlab_path"] == matlab_root_path
|
|
606
|
+
assert (
|
|
607
|
+
matlab_settings["matlab_version"] is None
|
|
608
|
+
) # There's no VersionInfo.xml file in the mock setup
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
def test_get_matlab_settings_matlab_wrapper(mocker, tmp_path):
|
|
612
|
+
# Arrange
|
|
613
|
+
matlab_exec_path = Path(tmp_path) / "matlab"
|
|
614
|
+
mocker.patch("matlab_proxy.settings.shutil.which", return_value=matlab_exec_path)
|
|
615
|
+
|
|
616
|
+
# Act
|
|
617
|
+
matlab_settings = settings.get_matlab_settings()
|
|
488
618
|
|
|
489
619
|
# Assert
|
|
620
|
+
assert str(matlab_exec_path) in str(matlab_settings["matlab_cmd"][0])
|
|
621
|
+
assert (
|
|
622
|
+
matlab_settings["matlab_path"] is None
|
|
623
|
+
) # Matlab root could not be determined because wrapper script is being used
|
|
624
|
+
assert matlab_settings["matlab_version"] is None
|
|
490
625
|
assert (
|
|
491
|
-
matlab_settings["
|
|
492
|
-
|
|
626
|
+
matlab_settings["error"] is None
|
|
627
|
+
) # Error has to be None when matlab executable is on PATH but root path could not be determined
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
def test_get_matlab_settings_valid_custom_matlab_root(mocker, monkeypatch, tmp_path):
|
|
631
|
+
# Arrange
|
|
632
|
+
matlab_root_path = Path(tmp_path)
|
|
633
|
+
matlab_exec_path = matlab_root_path / "bin" / "matlab"
|
|
634
|
+
matlab_version = "R2024b"
|
|
635
|
+
monkeypatch.setenv(mwi_env.get_env_name_custom_matlab_root(), str(matlab_root_path))
|
|
636
|
+
mocker.patch(
|
|
637
|
+
"matlab_proxy.settings.mwi.validators.validate_matlab_root_path",
|
|
638
|
+
return_value=matlab_root_path,
|
|
639
|
+
)
|
|
640
|
+
mocker.patch(
|
|
641
|
+
"matlab_proxy.settings.get_matlab_version", return_value=matlab_version
|
|
493
642
|
)
|
|
494
643
|
|
|
495
|
-
|
|
644
|
+
# Act
|
|
645
|
+
matlab_settings = settings.get_matlab_settings()
|
|
646
|
+
|
|
647
|
+
# Assert
|
|
648
|
+
assert str(matlab_exec_path) in str(matlab_settings["matlab_cmd"][0])
|
|
649
|
+
assert matlab_settings["matlab_path"] == matlab_root_path
|
|
650
|
+
assert matlab_settings["matlab_version"] == matlab_version
|
|
651
|
+
assert matlab_settings["error"] is None
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
def test_get_matlab_settings_invalid_custom_matlab_root(mocker, monkeypatch, tmp_path):
|
|
655
|
+
# Arrange
|
|
656
|
+
matlab_root_path = Path(tmp_path)
|
|
657
|
+
monkeypatch.setenv(mwi_env.get_env_name_custom_matlab_root(), str(matlab_root_path))
|
|
658
|
+
|
|
659
|
+
# Act
|
|
660
|
+
matlab_settings = settings.get_matlab_settings()
|
|
661
|
+
|
|
662
|
+
# Assert
|
|
663
|
+
# When custom MATLAB root is supplied, it must be the actual MATLAB root ie.
|
|
664
|
+
# VersionInfo.xml file must to be there
|
|
665
|
+
# matlab executable inside the bin folder must be there
|
|
666
|
+
# If not, MATLAB related settings should be None and custom MATLAB root error should be present
|
|
667
|
+
assert matlab_settings["matlab_cmd"] is None
|
|
668
|
+
assert matlab_settings["matlab_path"] is None
|
|
669
|
+
assert matlab_settings["matlab_version"] is None
|
|
670
|
+
assert (
|
|
671
|
+
isinstance(matlab_settings["error"], MatlabInstallError)
|
|
672
|
+
and mwi_env.get_env_name_custom_matlab_root()
|
|
673
|
+
in matlab_settings["error"].message
|
|
674
|
+
)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Copyright 2020-
|
|
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
|
|
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
|
-
|
|
328
|
-
|
|
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(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|