matlab-proxy 0.26.0__py3-none-any.whl → 0.27.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.

Files changed (54) hide show
  1. matlab_proxy/app.py +13 -15
  2. matlab_proxy/app_state.py +8 -2
  3. matlab_proxy/default_configuration.py +2 -2
  4. matlab_proxy/gui/index.html +1 -1
  5. matlab_proxy/gui/static/js/{index.CZgGkMCD.js → index.BcDShXfH.js} +16 -16
  6. matlab_proxy/settings.py +3 -2
  7. matlab_proxy/util/list_servers.py +2 -2
  8. matlab_proxy/util/mwi/environment_variables.py +5 -0
  9. matlab_proxy/util/mwi/session_name.py +28 -0
  10. matlab_proxy/util/mwi/validators.py +2 -4
  11. {matlab_proxy-0.26.0.dist-info → matlab_proxy-0.27.0.dist-info}/METADATA +37 -25
  12. {matlab_proxy-0.26.0.dist-info → matlab_proxy-0.27.0.dist-info}/RECORD +19 -49
  13. {matlab_proxy-0.26.0.dist-info → matlab_proxy-0.27.0.dist-info}/WHEEL +1 -2
  14. matlab_proxy_manager/README.md +85 -0
  15. matlab_proxy_manager/lib/README.md +53 -0
  16. matlab_proxy_manager/storage/README.md +54 -0
  17. matlab_proxy_manager/web/README.md +37 -0
  18. matlab_proxy-0.26.0.dist-info/top_level.txt +0 -3
  19. tests/integration/__init__.py +0 -1
  20. tests/integration/integration_tests_with_license/__init__.py +0 -1
  21. tests/integration/integration_tests_with_license/conftest.py +0 -47
  22. tests/integration/integration_tests_with_license/test_http_end_points.py +0 -397
  23. tests/integration/integration_tests_without_license/__init__.py +0 -1
  24. tests/integration/integration_tests_without_license/conftest.py +0 -116
  25. tests/integration/integration_tests_without_license/test_matlab_is_down_if_unlicensed.py +0 -49
  26. tests/integration/utils/__init__.py +0 -1
  27. tests/integration/utils/integration_tests_utils.py +0 -352
  28. tests/integration/utils/licensing.py +0 -152
  29. tests/unit/__init__.py +0 -1
  30. tests/unit/conftest.py +0 -66
  31. tests/unit/test_app.py +0 -1299
  32. tests/unit/test_app_state.py +0 -1094
  33. tests/unit/test_constants.py +0 -7
  34. tests/unit/test_ddux.py +0 -22
  35. tests/unit/test_devel.py +0 -246
  36. tests/unit/test_non_dev_mode.py +0 -169
  37. tests/unit/test_settings.py +0 -679
  38. tests/unit/util/__init__.py +0 -3
  39. tests/unit/util/mwi/__init__.py +0 -1
  40. tests/unit/util/mwi/embedded_connector/__init__.py +0 -1
  41. tests/unit/util/mwi/embedded_connector/test_helpers.py +0 -29
  42. tests/unit/util/mwi/embedded_connector/test_request.py +0 -64
  43. tests/unit/util/mwi/test_custom_http_headers.py +0 -281
  44. tests/unit/util/mwi/test_download.py +0 -152
  45. tests/unit/util/mwi/test_logger.py +0 -82
  46. tests/unit/util/mwi/test_token_auth.py +0 -303
  47. tests/unit/util/mwi/test_validators.py +0 -364
  48. tests/unit/util/test_cookie_jar.py +0 -252
  49. tests/unit/util/test_mw.py +0 -550
  50. tests/unit/util/test_util.py +0 -221
  51. tests/utils/__init__.py +0 -1
  52. tests/utils/logging_util.py +0 -81
  53. {matlab_proxy-0.26.0.dist-info → matlab_proxy-0.27.0.dist-info}/entry_points.txt +0 -0
  54. {matlab_proxy-0.26.0.dist-info → matlab_proxy-0.27.0.dist-info/licenses}/LICENSE.md +0 -0
@@ -1,7 +0,0 @@
1
- # Copyright 2023-2024 The MathWorks, Inc.
2
-
3
- TWO_MAX_TRIES = 2
4
- FIVE_MAX_TRIES = 5
5
- HALF_SECOND_DELAY = 0.5
6
- ONE_SECOND_DELAY = 1
7
- CHECK_MATLAB_STATUS_INTERVAL = 1
tests/unit/test_ddux.py DELETED
@@ -1,22 +0,0 @@
1
- # Copyright 2020-2022 The MathWorks, Inc.
2
-
3
- import matlab_proxy
4
- from matlab_proxy import util
5
-
6
-
7
- def test_get_mwi_ddux_value():
8
- """Tests ddux value for matlab-proxy with different extension names"""
9
- expected_result = matlab_proxy.__get_matlab_proxy_base_ddux_value()
10
- actual_result = matlab_proxy.get_mwi_ddux_value(
11
- matlab_proxy.get_default_config_name()
12
- )
13
-
14
- assert expected_result == actual_result
15
-
16
- expected_result = f"MATLAB_PROXY:HELLO_WORLD:V1"
17
- actual_result = matlab_proxy.get_mwi_ddux_value("hello world")
18
-
19
- assert expected_result == actual_result
20
-
21
- actual_result = matlab_proxy.get_mwi_ddux_value(" \n \t hello-world \n")
22
- assert expected_result == actual_result
tests/unit/test_devel.py DELETED
@@ -1,246 +0,0 @@
1
- # Copyright 2020-2024 The MathWorks, Inc.
2
-
3
- import os
4
- import socket
5
- import subprocess
6
- import sys
7
- import time
8
- from collections import namedtuple
9
- from pathlib import Path
10
-
11
- import pytest
12
- import aiohttp
13
- from matlab_proxy.util.mwi import environment_variables as mwi_env
14
- from matlab_proxy.constants import CONNECTOR_SECUREPORT_FILENAME
15
-
16
- """
17
- This file consists of tests which check the devel.py file
18
- """
19
-
20
- TWO_MAX_TRIES = 2
21
- FIVE_MAX_TRIES = 5
22
- HALF_SECOND_DELAY = 0.5
23
- ONE_SECOND_DELAY = 1
24
-
25
-
26
- @pytest.fixture(name="matlab_log_dir")
27
- def matlab_log_dir_fixture(monkeypatch, tmp_path):
28
- """A pytest fixture to monkeypatch an environment variable.
29
-
30
- This fixture monkeypatches MATLAB_LOG_DIR env variable which the
31
- fake matlab server utilizes to write the matlab_ready_file into.
32
-
33
- Args:
34
- monkeypatch : A built-in pytest fixture.
35
- tmp_path: tmp_path fixture provides a temporary directory unique to the test invocation.
36
- """
37
- hostname = socket.gethostname()
38
- matlab_log_dir = Path(tmp_path)
39
-
40
- if hostname:
41
- matlab_log_dir = matlab_log_dir / "hosts" / hostname
42
- matlab_log_dir.mkdir(parents=True, exist_ok=True)
43
-
44
- monkeypatch.setenv("MATLAB_LOG_DIR", str(matlab_log_dir))
45
-
46
- return matlab_log_dir
47
-
48
-
49
- @pytest.fixture(name="matlab_ready_file")
50
- def matlab_ready_file_fixture(matlab_log_dir):
51
- """A pytest fixture to create the matlab_ready_file.
52
-
53
- This fixture creates the matlab readyfile path based on the matlab_log_dir fixture output.
54
-
55
- Args:
56
- matlab_log_dir: pytest fixture that returns a temp dir to be used as matlab_log_dir
57
-
58
- Returns:
59
- Path: Returns path of the matlab_ready_file
60
- """
61
- return Path(f"{matlab_log_dir}/{CONNECTOR_SECUREPORT_FILENAME}")
62
-
63
-
64
- @pytest.fixture(name="valid_nlm")
65
- def valid_nlm_fixture(monkeypatch):
66
- """A pytest fixture to monkeypatch an environment variable.
67
-
68
- This fixture monkeypatches MLM_LICENSE_FILE with a valid NLM connection string.
69
-
70
- Args:
71
- monkeypatch : A built-in pytest fixture
72
- """
73
-
74
- monkeypatch.setenv(mwi_env.get_env_name_network_license_manager(), "123@nlm")
75
-
76
-
77
- @pytest.fixture(name="invalid_nlm")
78
- def invalid_nlm_fixture(monkeypatch):
79
- """A pytest fixture to monkeypatch an environment variable.
80
-
81
- This fixture monkeypatches MLM_LICENSE_FILE with an invalid NLM connection string.
82
-
83
-
84
- Args:
85
- monkeypatch : A built-in pytest fixture
86
- """
87
-
88
- monkeypatch.setenv(mwi_env.get_env_name_network_license_manager(), "123@brokenhost")
89
-
90
-
91
- @pytest.fixture(name="matlab_process_setup")
92
- def matlab_process_setup_fixture():
93
- """A pytest fixture which creates a NamedTuple required for creating a fake matlab process
94
-
95
- This fixture returns a NamedTuple containing values required to run the fake matlab process
96
-
97
- Returns:
98
- variables : A NamedTuple containing the following values:
99
-
100
- devel_file = Path to devel_file
101
- matlab_cmd = The matlab command to start the matlab process
102
- """
103
-
104
- matlab_setup_variables = namedtuple(
105
- "matlab_setup_variables",
106
- ["devel_file", "matlab_cmd"],
107
- )
108
- devel_file = Path(os.path.join(os.getcwd(), "matlab_proxy", "devel.py"))
109
-
110
- python_executable = sys.executable
111
-
112
- matlab_cmd = [
113
- python_executable,
114
- "-u",
115
- str(devel_file),
116
- "matlab",
117
- "--ready-delay",
118
- "0",
119
- ]
120
- variables = matlab_setup_variables(devel_file, matlab_cmd)
121
-
122
- return variables
123
-
124
-
125
- @pytest.fixture(name="matlab_process_valid_nlm")
126
- def matlab_process_valid_nlm_fixture(matlab_log_dir, matlab_process_setup, valid_nlm):
127
- """A pytest fixture which creates a fake matlab process with a valid NLM connection string.
128
-
129
- This pytest fixture creates a matlab process and yields control to the test which utilizes this
130
- fixture. After completion of tests stops the matlab process
131
- """
132
-
133
- matlab_process = subprocess.Popen(
134
- matlab_process_setup.matlab_cmd, stderr=subprocess.PIPE
135
- )
136
-
137
- yield
138
-
139
- matlab_process.terminate()
140
- matlab_process.wait()
141
-
142
-
143
- async def test_matlab_valid_nlm(matlab_ready_file, matlab_process_valid_nlm):
144
- """Test if the Fake Matlab server has started and is able to serve content.
145
-
146
- This test checks if the fake matlab process is able to start a web server and serve some
147
- fake content.
148
-
149
- Args:
150
- matlab_process_valid_nlm : A pytest fixture which creates the fake matlab process which starts the web server
151
-
152
- Raises:
153
- ConnectionError: If the fake matlab server doesn't startup, after the specified number of max_tries this test
154
- raises a ConnectionError.
155
- """
156
-
157
- matlab_port = get_matlab_port_from_ready_file(matlab_ready_file)
158
- if matlab_port is None:
159
- raise FileNotFoundError(f"matlab_ready_file at {matlab_ready_file} not found")
160
-
161
- count = 0
162
- while True:
163
- try:
164
- url = f"http://localhost:{matlab_port}/index-jsd-cr.html"
165
- async with aiohttp.ClientSession(trust_env=True) as session:
166
- async with session.get(url) as resp:
167
- assert resp.content_type == "text/html"
168
- assert resp.status == 200
169
- assert resp.content is not None
170
- break
171
- except:
172
- count += 1
173
- if count > FIVE_MAX_TRIES:
174
- raise ConnectionError
175
- time.sleep(ONE_SECOND_DELAY)
176
-
177
-
178
- @pytest.fixture(name="matlab_process_invalid_nlm")
179
- def matlab_process_invalid_nlm_fixture(
180
- matlab_log_dir, matlab_process_setup, invalid_nlm
181
- ):
182
- """A pytest fixture which creates a fake matlab server with an invalid NLM connection string.
183
-
184
- Utilizes matlab_log_dir, matlab_process_setup and invalid_nlm fixtures for creating a
185
- fake matlab web server then yields control for tests to utilize it.
186
-
187
-
188
- Args:
189
- matlab_log_dir : A pytest fixture which monkeypatches an environment variable.
190
- matlab_process_setup (NamedTuple): A NamedTuple which contains values to start the matlab process
191
- invalid_nlm : A pytest fixture which monkeypatches an invalid nlm connection string
192
- """
193
-
194
- matlab_process = subprocess.Popen(
195
- matlab_process_setup.matlab_cmd,
196
- stderr=subprocess.PIPE,
197
- )
198
-
199
- yield
200
-
201
- matlab_process.terminate()
202
- matlab_process.wait()
203
-
204
-
205
- async def test_matlab_invalid_nlm(matlab_ready_file, matlab_process_invalid_nlm):
206
- """Test which checks if the fake Matlab process stops when NLM string is invalid
207
-
208
- When the NLM string is invalid, the fake matlab server will automatically
209
- exit. This test checks if a ConnectionError is raised when a GET request is sent to it.
210
-
211
- Args:
212
- matlab_process_invalid_nlm (Process): A process which starts a fake Matlab WebServer.
213
- """
214
- matlab_port = get_matlab_port_from_ready_file(matlab_ready_file)
215
- count = 0
216
-
217
- with pytest.raises(ConnectionError):
218
- while True:
219
- try:
220
- url = f"http://localhost:{matlab_port}/index-jsd-cr.html"
221
-
222
- async with aiohttp.ClientSession(trust_env=True) as session:
223
- async with session.get(url) as resp:
224
- assert resp.content_type == "text/html"
225
- assert resp.status == 200
226
- assert resp.content is not None
227
-
228
- break
229
- except:
230
- count += 1
231
- if count > TWO_MAX_TRIES:
232
- raise ConnectionError
233
- time.sleep(HALF_SECOND_DELAY)
234
-
235
-
236
- def get_matlab_port_from_ready_file(matlab_ready_file):
237
- for i in range(FIVE_MAX_TRIES):
238
- try:
239
- with open(matlab_ready_file) as f:
240
- return int(f.read())
241
- # Retry in the event that matlab_ready_file isn't created yet or
242
- # it has been created but the matlab_port information is not yet
243
- # written into the file which throws ValueError while converting to int.
244
- except (FileNotFoundError, ValueError):
245
- time.sleep(HALF_SECOND_DELAY)
246
- continue
@@ -1,169 +0,0 @@
1
- # Copyright 2020-2025 The MathWorks, Inc.
2
-
3
- import os
4
- import shutil
5
- from pathlib import Path
6
-
7
- import matlab_proxy
8
- import pytest
9
- from matlab_proxy.util.mwi import environment_variables as mwi_env
10
-
11
- from tests.unit.test_app import FakeServer
12
-
13
- """
14
- This file checks whether static assets are being added successfully to the
15
- test web server's static route table in non-dev mode.
16
- """
17
-
18
-
19
- @pytest.fixture(name="matlab_port_setup")
20
- def matlab_port_fixture(monkeypatch):
21
- """A pytest fixture which monkeypatches an environment variable.
22
-
23
- Pytest by default sets MWI_DEV to true.
24
- Args:
25
- monkeypatch : A built-in pytest fixture
26
- """
27
- # For the test: test_non_dev, when run independently, works as expected.
28
- # But, when all the tests are run, if port 8000 was picked
29
- # by some previous test and was not released yet, then test_non_dev will fail to bind to it.
30
- # To overcome this, I've temporarily patched MWI_APP_PORT to pick a random port.
31
- try:
32
- import socket
33
-
34
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
35
- s.bind(("", 0))
36
- port = s.getsockname()[1]
37
- s.close()
38
- except Exception as e:
39
- pass
40
-
41
- monkeypatch.setenv(mwi_env.get_env_name_development(), "false")
42
- monkeypatch.setenv(mwi_env.get_env_name_app_port(), str(port))
43
-
44
-
45
- @pytest.fixture(name="build_frontend")
46
- def build_frontend_fixture():
47
- """A method to build react front-end and place it in matlab_proxy directory
48
-
49
- This method builds react front-end and copies the built files to matlab_proxy/gui.
50
- Then adds __init__.py to each folder within it to make it accessible for python.
51
- This prework is for the purpose of adding the built files as static assets to the server.
52
- """
53
-
54
- static_files_dir = os.path.join(os.getcwd(), "matlab_proxy", "gui")
55
-
56
- try:
57
- shutil.rmtree(static_files_dir)
58
-
59
- except FileNotFoundError:
60
- pass
61
-
62
- finally:
63
- # Create static files
64
- os.mkdir(static_files_dir)
65
- with open(Path(static_files_dir) / "index.html", "w") as f:
66
- f.write("<h1> Hello World </h1>")
67
-
68
- with open(Path(static_files_dir) / "manifest.json", "w") as f:
69
- f.write('{"display: "standalone"}')
70
-
71
- build_contents = [
72
- {
73
- "dir": "css",
74
- "file": "index.css",
75
- "file_content": "html { height: 100%;}",
76
- },
77
- {
78
- "dir": "js",
79
- "file": "index.js",
80
- "file_content": "import React from 'react';'",
81
- },
82
- {
83
- "dir": "media",
84
- "file": "media.txt",
85
- "file_content": "Copyright (c) 2020-2022 The Mathworks, Inc.",
86
- },
87
- ]
88
-
89
- for build_content in build_contents:
90
- os.makedirs(Path(static_files_dir) / "static" / build_content["dir"])
91
- with open(
92
- Path(static_files_dir)
93
- / "static"
94
- / build_content["dir"]
95
- / build_content["file"],
96
- "w",
97
- ) as f:
98
- f.write(build_content["file_content"])
99
-
100
- (Path(static_files_dir) / "__init__.py").touch(exist_ok=True)
101
-
102
- for path, directories, filenames in os.walk(static_files_dir):
103
- for directory in directories:
104
- (Path(path) / directory / "__init__.py").touch(exist_ok=True)
105
-
106
- # Yield to execute test
107
- yield
108
-
109
- # Delete the static files after executing test.
110
- shutil.rmtree(static_files_dir)
111
-
112
-
113
- @pytest.fixture(name="mock_settings_get")
114
- def mock_settings_get_fixture(mocker):
115
- """Pytest fixture which mocks settings.get() method to return
116
- dev settings.
117
-
118
- Args:
119
- mocker : Built in pytest fixture
120
- """
121
- mocker.patch(
122
- "matlab_proxy.settings.get",
123
- return_value=matlab_proxy.settings.get(dev=True),
124
- )
125
-
126
-
127
- @pytest.fixture(name="test_server")
128
- def test_server_fixture(
129
- event_loop,
130
- aiohttp_client,
131
- build_frontend,
132
- matlab_port_setup,
133
- mock_settings_get,
134
- ):
135
- """A pytest fixture which yields a test server.
136
-
137
- This test server is used to test various endpoints. After gaining control back, gracefully shuts
138
- down the server.
139
-
140
- This fixture 'initializes' the test server with different constraints from the test server in test_app.py
141
-
142
- Args:
143
- event_loop : Event loop
144
- aiohttp_client : A built-in pytest fixture
145
- build_frontend: Pytest fixture which generates the directory structure of static files with some placeholder content
146
- matlab_port_setup: Pytest fixture which monkeypatches 'MWI_DEV' env to False. This is required for the test_server to add static content
147
- mock_settings_get: Pytest fixture which mocks settings.get() to return dev settings when env 'MWI_DEV' is set to False.
148
-
149
- Yields:
150
- [aiohttp_client]: A aiohttp_client to send HTTP requests.
151
- """
152
-
153
- with FakeServer(event_loop, aiohttp_client) as test_server:
154
- yield test_server
155
-
156
-
157
- async def test_non_dev(test_server):
158
- """Tests whether static files are being added to the web server.
159
-
160
- This test checks if the test_server successfully added the static files built and
161
- copied into matlab_proxy/gui folder are added to the static_route_table of the server.
162
-
163
- Args:
164
- test_server (aiohttp_client): A aiohttp server to send HTTP requests to.
165
- """
166
- resp = await test_server.get("/get_status")
167
- assert resp.status == 200
168
-
169
- assert test_server.app["static_route_table"] is not None