napari-plugin-manager 0.1.3__py3-none-any.whl → 0.1.5__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.
@@ -0,0 +1,23 @@
1
+ import pytest
2
+
3
+ from napari_plugin_manager.base_qt_package_installer import (
4
+ AbstractInstallerTool,
5
+ )
6
+
7
+
8
+ def test_not_implemented_methods():
9
+ tool = AbstractInstallerTool('install', ['requests'])
10
+ with pytest.raises(NotImplementedError):
11
+ tool.executable()
12
+
13
+ with pytest.raises(NotImplementedError):
14
+ tool.arguments()
15
+
16
+ with pytest.raises(NotImplementedError):
17
+ tool.environment()
18
+
19
+ with pytest.raises(NotImplementedError):
20
+ tool.constraints()
21
+
22
+ with pytest.raises(NotImplementedError):
23
+ tool.available()
@@ -1,4 +1,6 @@
1
+ import logging
1
2
  import re
3
+ import sys
2
4
  import time
3
5
  from pathlib import Path
4
6
  from types import MethodType
@@ -7,13 +9,16 @@ from typing import TYPE_CHECKING
7
9
  import pytest
8
10
  from qtpy.QtCore import QProcessEnvironment
9
11
 
10
- from napari_plugin_manager.qt_package_installer import (
12
+ import napari_plugin_manager.base_qt_package_installer as bqpi
13
+ from napari_plugin_manager.base_qt_package_installer import (
11
14
  AbstractInstallerTool,
12
- CondaInstallerTool,
13
15
  InstallerActions,
14
- InstallerQueue,
15
16
  InstallerTools,
16
- PipInstallerTool,
17
+ )
18
+ from napari_plugin_manager.qt_package_installer import (
19
+ NapariCondaInstallerTool,
20
+ NapariInstallerQueue,
21
+ NapariPipInstallerTool,
17
22
  )
18
23
 
19
24
  if TYPE_CHECKING:
@@ -55,25 +60,20 @@ class _NonExistingTool(AbstractInstallerTool):
55
60
  return QProcessEnvironment.systemEnvironment()
56
61
 
57
62
 
58
- def test_not_implemented_methods():
59
- tool = AbstractInstallerTool('install', ['requests'])
60
- with pytest.raises(NotImplementedError):
61
- tool.executable()
62
-
63
- with pytest.raises(NotImplementedError):
64
- tool.arguments()
65
-
66
- with pytest.raises(NotImplementedError):
67
- tool.environment()
68
-
69
- with pytest.raises(NotImplementedError):
70
- tool.available()
71
-
72
-
73
- def test_pip_installer_tasks(qtbot, tmp_virtualenv: 'Session', monkeypatch):
74
- installer = InstallerQueue()
63
+ def test_pip_installer_tasks(
64
+ qtbot, tmp_virtualenv: 'Session', monkeypatch, caplog
65
+ ):
66
+ caplog.set_level(logging.DEBUG, logger=bqpi.__name__)
67
+ installer = NapariInstallerQueue()
75
68
  monkeypatch.setattr(
76
- PipInstallerTool, "executable", lambda *a: tmp_virtualenv.creator.exe
69
+ NapariPipInstallerTool,
70
+ "executable",
71
+ lambda *a: tmp_virtualenv.creator.exe,
72
+ )
73
+ monkeypatch.setattr(
74
+ NapariPipInstallerTool,
75
+ "origins",
76
+ ("https://pypi.org/simple",),
77
77
  )
78
78
  with qtbot.waitSignal(installer.allFinished, timeout=20000):
79
79
  installer.install(
@@ -138,10 +138,34 @@ def test_pip_installer_tasks(qtbot, tmp_virtualenv: 'Session', monkeypatch):
138
138
  )
139
139
 
140
140
 
141
+ def test_pip_installer_invalid_action(tmp_virtualenv: 'Session', monkeypatch):
142
+ installer = NapariInstallerQueue()
143
+ monkeypatch.setattr(
144
+ NapariPipInstallerTool,
145
+ "executable",
146
+ lambda *a: tmp_virtualenv.creator.exe,
147
+ )
148
+ invalid_action = 'Invalid Action'
149
+ with pytest.raises(
150
+ ValueError, match=f"Action '{invalid_action}' not supported!"
151
+ ):
152
+ item = installer._build_queue_item(
153
+ tool=InstallerTools.PIP,
154
+ action=invalid_action,
155
+ pkgs=['pip-install-test'],
156
+ prefix=None,
157
+ origins=(),
158
+ process=installer._create_process(),
159
+ )
160
+ installer._queue_item(item)
161
+
162
+
141
163
  def test_installer_failures(qtbot, tmp_virtualenv: 'Session', monkeypatch):
142
- installer = InstallerQueue()
164
+ installer = NapariInstallerQueue()
143
165
  monkeypatch.setattr(
144
- PipInstallerTool, "executable", lambda *a: tmp_virtualenv.creator.exe
166
+ NapariPipInstallerTool,
167
+ "executable",
168
+ lambda *a: tmp_virtualenv.creator.exe,
145
169
  )
146
170
 
147
171
  # CHECK 1) Errors should trigger finished and allFinished too
@@ -181,7 +205,7 @@ def test_installer_failures(qtbot, tmp_virtualenv: 'Session', monkeypatch):
181
205
 
182
206
 
183
207
  def test_cancel_incorrect_job_id(qtbot, tmp_virtualenv: 'Session'):
184
- installer = InstallerQueue()
208
+ installer = NapariInstallerQueue()
185
209
  with qtbot.waitSignal(installer.allFinished, timeout=20000):
186
210
  job_id = installer.install(
187
211
  tool=InstallerTools.PIP,
@@ -192,13 +216,17 @@ def test_cancel_incorrect_job_id(qtbot, tmp_virtualenv: 'Session'):
192
216
 
193
217
 
194
218
  @pytest.mark.skipif(
195
- not CondaInstallerTool.available(), reason="Conda is not available."
219
+ not NapariCondaInstallerTool.available(), reason="Conda is not available."
196
220
  )
197
- def test_conda_installer(qtbot, tmp_conda_env: Path):
221
+ def test_conda_installer(qtbot, caplog, monkeypatch, tmp_conda_env: Path):
222
+ if sys.platform == "darwin":
223
+ # check handled for `PYTHONEXECUTABLE` env definition on macOS
224
+ monkeypatch.setenv("PYTHONEXECUTABLE", sys.executable)
225
+ caplog.set_level(logging.DEBUG, logger=bqpi.__name__)
198
226
  conda_meta = tmp_conda_env / "conda-meta"
199
227
  glob_pat = "typing-extensions-*.json"
200
228
  glob_pat_2 = "pyzenhub-*.json"
201
- installer = InstallerQueue()
229
+ installer = NapariInstallerQueue()
202
230
 
203
231
  with qtbot.waitSignal(installer.allFinished, timeout=600_000):
204
232
  installer.install(
@@ -277,9 +305,11 @@ def test_conda_installer(qtbot, tmp_conda_env: Path):
277
305
 
278
306
 
279
307
  def test_installer_error(qtbot, tmp_virtualenv: 'Session', monkeypatch):
280
- installer = InstallerQueue()
308
+ installer = NapariInstallerQueue()
281
309
  monkeypatch.setattr(
282
- PipInstallerTool, "executable", lambda *a: 'not-a-real-executable'
310
+ NapariPipInstallerTool,
311
+ "executable",
312
+ lambda *a: 'not-a-real-executable',
283
313
  )
284
314
  with qtbot.waitSignal(installer.allFinished, timeout=600_000):
285
315
  installer.install(
@@ -289,10 +319,10 @@ def test_installer_error(qtbot, tmp_virtualenv: 'Session', monkeypatch):
289
319
 
290
320
 
291
321
  @pytest.mark.skipif(
292
- not CondaInstallerTool.available(), reason="Conda is not available."
322
+ not NapariCondaInstallerTool.available(), reason="Conda is not available."
293
323
  )
294
324
  def test_conda_installer_wait_for_finished(qtbot, tmp_conda_env: Path):
295
- installer = InstallerQueue()
325
+ installer = NapariInstallerQueue()
296
326
 
297
327
  with qtbot.waitSignal(installer.allFinished, timeout=600_000):
298
328
  installer.install(
@@ -309,14 +339,14 @@ def test_conda_installer_wait_for_finished(qtbot, tmp_conda_env: Path):
309
339
 
310
340
 
311
341
  def test_constraints_are_in_sync():
312
- conda_constraints = sorted(CondaInstallerTool.constraints())
313
- pip_constraints = sorted(PipInstallerTool.constraints())
342
+ conda_constraints = sorted(NapariCondaInstallerTool.constraints())
343
+ pip_constraints = sorted(NapariPipInstallerTool.constraints())
314
344
 
315
345
  assert len(conda_constraints) == len(pip_constraints)
316
346
 
317
347
  name_re = re.compile(r"([a-z0-9_\-]+).*")
318
348
  for conda_constraint, pip_constraint in zip(
319
- conda_constraints, pip_constraints
349
+ conda_constraints, pip_constraints, strict=False
320
350
  ):
321
351
  conda_name = name_re.match(conda_constraint).group(1)
322
352
  pip_name = name_re.match(pip_constraint).group(1)
@@ -324,15 +354,15 @@ def test_constraints_are_in_sync():
324
354
 
325
355
 
326
356
  def test_executables():
327
- assert CondaInstallerTool.executable()
328
- assert PipInstallerTool.executable()
357
+ assert NapariCondaInstallerTool.executable()
358
+ assert NapariPipInstallerTool.executable()
329
359
 
330
360
 
331
361
  def test_available():
332
- assert str(CondaInstallerTool.available())
333
- assert PipInstallerTool.available()
362
+ assert str(NapariCondaInstallerTool.available())
363
+ assert NapariPipInstallerTool.available()
334
364
 
335
365
 
336
366
  def test_unrecognized_tool():
337
367
  with pytest.raises(ValueError):
338
- InstallerQueue().install(tool='shrug', pkgs=[])
368
+ NapariInstallerQueue().install(tool='shrug', pkgs=[])
@@ -1,3 +1,5 @@
1
+ from urllib.error import HTTPError, URLError
2
+
1
3
  from flaky import flaky
2
4
 
3
5
  from napari_plugin_manager.npe2api import (
@@ -13,7 +15,7 @@ def test_user_agent():
13
15
  assert _user_agent()
14
16
 
15
17
 
16
- @flaky(max_runs=3, min_passes=2)
18
+ @flaky(max_runs=4, min_passes=2)
17
19
  def test_plugin_summaries():
18
20
  keys = [
19
21
  "name",
@@ -26,20 +28,26 @@ def test_plugin_summaries():
26
28
  "pypi_versions",
27
29
  "conda_versions",
28
30
  ]
29
- data = plugin_summaries()
30
- test_data = dict(data[0])
31
- for key in keys:
32
- assert key in test_data
33
- test_data.pop(key)
31
+ try:
32
+ data = plugin_summaries()
33
+ test_data = dict(data[0])
34
+ for key in keys:
35
+ assert key in test_data
36
+ test_data.pop(key)
34
37
 
35
- assert not test_data
38
+ assert not test_data
39
+ except (HTTPError, URLError):
40
+ pass
36
41
 
37
42
 
38
43
  def test_conda_map():
39
44
  pkgs = ["napari-svg"]
40
- data = conda_map()
41
- for pkg in pkgs:
42
- assert pkg in data
45
+ try:
46
+ data = conda_map()
47
+ for pkg in pkgs:
48
+ assert pkg in data
49
+ except (HTTPError, URLError):
50
+ pass
43
51
 
44
52
 
45
53
  def test_iter_napari_plugin_info():