pytest-girder 3.2.18.dev2__tar.gz → 3.2.19__tar.gz

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.
Files changed (22) hide show
  1. {pytest_girder-3.2.18.dev2/pytest_girder.egg-info → pytest_girder-3.2.19}/PKG-INFO +1 -1
  2. {pytest_girder-3.2.18.dev2 → pytest_girder-3.2.19}/pytest_girder/fixtures.py +7 -0
  3. {pytest_girder-3.2.18.dev2 → pytest_girder-3.2.19}/pytest_girder/utils.py +62 -45
  4. {pytest_girder-3.2.18.dev2 → pytest_girder-3.2.19}/pytest_girder/web_client.py +30 -24
  5. {pytest_girder-3.2.18.dev2 → pytest_girder-3.2.19/pytest_girder.egg-info}/PKG-INFO +1 -1
  6. pytest_girder-3.2.19/pytest_girder.egg-info/scm_version.json +8 -0
  7. pytest_girder-3.2.18.dev2/pytest_girder.egg-info/scm_version.json +0 -8
  8. {pytest_girder-3.2.18.dev2 → pytest_girder-3.2.19}/LICENSE +0 -0
  9. {pytest_girder-3.2.18.dev2 → pytest_girder-3.2.19}/MANIFEST.in +0 -0
  10. {pytest_girder-3.2.18.dev2 → pytest_girder-3.2.19}/pyproject.toml +0 -0
  11. {pytest_girder-3.2.18.dev2 → pytest_girder-3.2.19}/pytest_girder/__init__.py +0 -0
  12. {pytest_girder-3.2.18.dev2 → pytest_girder-3.2.19}/pytest_girder/assertions.py +0 -0
  13. {pytest_girder-3.2.18.dev2 → pytest_girder-3.2.19}/pytest_girder/plugin.py +0 -0
  14. {pytest_girder-3.2.18.dev2 → pytest_girder-3.2.19}/pytest_girder/plugin_registry.py +0 -0
  15. {pytest_girder-3.2.18.dev2 → pytest_girder-3.2.19}/pytest_girder.egg-info/SOURCES.txt +0 -0
  16. {pytest_girder-3.2.18.dev2 → pytest_girder-3.2.19}/pytest_girder.egg-info/dependency_links.txt +0 -0
  17. {pytest_girder-3.2.18.dev2 → pytest_girder-3.2.19}/pytest_girder.egg-info/entry_points.txt +0 -0
  18. {pytest_girder-3.2.18.dev2 → pytest_girder-3.2.19}/pytest_girder.egg-info/requires.txt +0 -0
  19. {pytest_girder-3.2.18.dev2 → pytest_girder-3.2.19}/pytest_girder.egg-info/scm_file_list.json +0 -0
  20. {pytest_girder-3.2.18.dev2 → pytest_girder-3.2.19}/pytest_girder.egg-info/top_level.txt +0 -0
  21. {pytest_girder-3.2.18.dev2 → pytest_girder-3.2.19}/setup.cfg +0 -0
  22. {pytest_girder-3.2.18.dev2 → pytest_girder-3.2.19}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-girder
3
- Version: 3.2.18.dev2
3
+ Version: 3.2.19
4
4
  Summary: A set of pytest fixtures for testing Girder applications.
5
5
  Author: Kitware, Inc.
6
6
  Author-email: kitware@kitware.com
@@ -83,8 +83,15 @@ def db(request):
83
83
 
84
84
  # Clear connection cache and model singletons
85
85
  _dbClients.clear()
86
+ # Only keep the most recent instance of each model class. Older instances
87
+ # can no longer be reached through event bindings (which are keyed by
88
+ # handler name and replaced by newer instances), and reconnecting all of
89
+ # them in every test makes each test slower than the last.
90
+ latest = {}
86
91
  for model in model_base._modelSingletons:
87
92
  model.__class__._instance = None
93
+ latest[model.__class__] = model
94
+ model_base._modelSingletons[:] = latest.values()
88
95
 
89
96
  if mockDb:
90
97
  pymongo.MongoClient = realMongoClient
@@ -2,18 +2,65 @@ import base64
2
2
  import cherrypy
3
3
  import contextlib
4
4
  import email
5
- import errno
6
5
  import io
7
6
  import json
8
- import os
9
7
  import queue
10
8
  import socket
9
+ import socketserver
11
10
  import threading
12
11
  import time
13
12
  import urllib.parse
14
13
 
15
- _startPort = 31000
16
- _maxTries = 100
14
+
15
+ class _MockSmtpHandler(socketserver.StreamRequestHandler):
16
+ """
17
+ Handle a single SMTP session, accepting every message and placing its data
18
+ on the server's mail queue. Only the subset of SMTP used by smtplib to
19
+ send unauthenticated, unencrypted mail is implemented.
20
+ """
21
+
22
+ def _reply(self, line):
23
+ self.wfile.write(line.encode('ascii') + b'\r\n')
24
+
25
+ def handle(self):
26
+ self._reply('220 localhost Mock SMTP server ready')
27
+ while True:
28
+ line = self.rfile.readline()
29
+ if not line:
30
+ return
31
+ command = line.strip().split(b' ', 1)[0].upper()
32
+ if command in (b'HELO', b'EHLO'):
33
+ self._reply('250 localhost')
34
+ elif command in (b'MAIL', b'RCPT', b'RSET', b'NOOP'):
35
+ self._reply('250 OK')
36
+ elif command == b'DATA':
37
+ self._reply('354 End data with <CR><LF>.<CR><LF>')
38
+ lines = []
39
+ while True:
40
+ line = self.rfile.readline()
41
+ if not line:
42
+ return
43
+ if line in (b'.\r\n', b'.\n'):
44
+ break
45
+ # Undo dot-stuffing (RFC 5321 section 4.5.2)
46
+ if line.startswith(b'.'):
47
+ line = line[1:]
48
+ lines.append(line)
49
+ self.server.mailQueue.put(b''.join(lines))
50
+ self._reply('250 OK')
51
+ elif command == b'QUIT':
52
+ self._reply('221 Bye')
53
+ return
54
+ else:
55
+ self._reply('502 Command not implemented')
56
+
57
+
58
+ class _MockSmtpServer(socketserver.ThreadingTCPServer):
59
+ daemon_threads = True
60
+
61
+ def __init__(self, address):
62
+ self.mailQueue = queue.Queue()
63
+ super().__init__(address, _MockSmtpHandler)
17
64
 
18
65
 
19
66
  class MockSmtpReceiver:
@@ -24,52 +71,19 @@ class MockSmtpReceiver:
24
71
 
25
72
  def start(self):
26
73
  """
27
- Start the mock SMTP server. Attempt to bind to any port within the
28
- range specified by _startPort and _maxTries. Bias it with the pid of
29
- the current process so as to reduce potential conflicts with parallel
30
- tests that are started nearly simultaneously.
74
+ Start the mock SMTP server on an available port. The bound host and
75
+ port are available as the ``address`` attribute.
31
76
  """
32
- # These imports are not at module level because the smtpd package was
33
- # removed from Python 3.12. By having them within the class, tests
34
- # that do not require the smtp mocks can still use the pytest girder
35
- # fixtures.
36
- import smtpd
37
-
38
- class MockSmtpServer(smtpd.SMTPServer):
39
- mailQueue = queue.Queue()
40
-
41
- def process_message(self, peer, mailfrom, rcpttos, data, **kwargs):
42
- self.mailQueue.put(data)
43
-
44
- for porttry in range(_maxTries):
45
- port = _startPort + ((porttry + os.getpid()) % _maxTries)
46
- try:
47
- self.address = ('localhost', port)
48
- self.smtp = MockSmtpServer(self.address, None)
49
- break
50
- except OSError as e:
51
- if e.errno != errno.EADDRINUSE:
52
- raise
53
- else:
54
- raise Exception('Could not bind to any port for Mock SMTP server')
55
-
56
- self.thread = threading.Thread(target=self.loop)
77
+ self.smtp = _MockSmtpServer(('localhost', 0))
78
+ self.address = ('localhost', self.smtp.server_address[1])
79
+ self.thread = threading.Thread(target=self.smtp.serve_forever, kwargs={
80
+ 'poll_interval': 0.1}, daemon=True)
57
81
  self.thread.start()
58
82
 
59
- def loop(self):
60
- # See comment in start about import scoping
61
- import asyncore
62
-
63
- """
64
- Instead of calling asyncore.loop directly, wrap it with a small
65
- timeout. This prevents using 100% cpu and still allows a graceful exit.
66
- """
67
- while len(asyncore.socket_map):
68
- asyncore.loop(timeout=0.5, use_poll=True)
69
-
70
83
  def stop(self):
71
84
  """Stop the mock STMP server"""
72
- self.smtp.close()
85
+ self.smtp.shutdown()
86
+ self.smtp.server_close()
73
87
  self.thread.join()
74
88
 
75
89
  def getMail(self, parse=False):
@@ -334,6 +348,9 @@ def serverContext(plugins=None, bindPort=False):
334
348
  cherrypy.engine.unsubscribe('stop', girder.events.daemon.stop)
335
349
  cherrypy.engine.stop()
336
350
  cherrypy.engine.exit()
351
+ # Since the daemon was unsubscribed from the engine, stop it explicitly
352
+ # so its thread doesn't linger after the test.
353
+ girder.events.daemon.stop()
337
354
  cherrypy.tree.apps = {}
338
355
  # This is needed to allow cherrypy to restart on another port
339
356
  cherrypy.server.httpserver = None
@@ -1,6 +1,7 @@
1
1
  import inspect
2
2
  import os
3
3
  import subprocess
4
+ import tempfile
4
5
  import time
5
6
 
6
7
 
@@ -104,7 +105,8 @@ def _webClientResource():
104
105
  """
105
106
  flags = self.getBodyJson()
106
107
  for key, info in flags.items():
107
- registerAccessFlag(key, info['name'], info['description'], info['admin'])
108
+ registerAccessFlag(key, info['name'], info['description'], info['admin'],
109
+ public=info.get('public', True))
108
110
 
109
111
  return _WebClientTestEndpoints()
110
112
 
@@ -122,26 +124,30 @@ def runWebClientTest(boundServer, spec, jasmineTimeout=None):
122
124
 
123
125
  boundServer.root.api.v1.webclienttest = _webClientResource()
124
126
 
125
- cmd = (
126
- 'npx', 'phantomjs',
127
- os.path.join(ROOT_DIR, 'girder', 'web_client', 'test', 'specRunner.js'),
128
- 'http://localhost:%s/static/built/testEnv.html' % boundServer.boundPort,
129
- spec,
130
- str(jasmineTimeout or ''),
131
- )
132
-
133
- p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=dict(
134
- # https://github.com/bazelbuild/rules_closure/pull/353
135
- OPENSSL_CONF='/dev/null',
136
- **os.environ
137
- ))
138
- jasmineFinished = False
139
- for line in iter(p.stdout.readline, b''):
140
- print(line.rstrip())
141
- if b'PHANTOM_TIMEOUT' in line or b'error loading source script' in line:
142
- p.kill()
143
- raise Exception('Phantomjs failure')
144
- if b'Testing Finished' in line:
145
- jasmineFinished = True
146
- assert p.wait() == 0
147
- assert jasmineFinished
127
+ # Use private browser storage so that state, such as an auth token in
128
+ # localStorage, cannot leak between runs that use the same port.
129
+ with tempfile.TemporaryDirectory() as storageDir:
130
+ cmd = (
131
+ 'npx', 'phantomjs',
132
+ '--local-storage-path=%s' % storageDir,
133
+ os.path.join(ROOT_DIR, 'girder', 'web_client', 'test', 'specRunner.js'),
134
+ 'http://localhost:%s/static/built/testEnv.html' % boundServer.boundPort,
135
+ spec,
136
+ str(jasmineTimeout or ''),
137
+ )
138
+
139
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=dict(
140
+ # https://github.com/bazelbuild/rules_closure/pull/353
141
+ OPENSSL_CONF='/dev/null',
142
+ **os.environ
143
+ ))
144
+ jasmineFinished = False
145
+ for line in iter(p.stdout.readline, b''):
146
+ print(line.rstrip())
147
+ if b'PHANTOM_TIMEOUT' in line or b'error loading source script' in line:
148
+ p.kill()
149
+ raise Exception('Phantomjs failure')
150
+ if b'Testing Finished' in line:
151
+ jasmineFinished = True
152
+ assert p.wait() == 0
153
+ assert jasmineFinished
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-girder
3
- Version: 3.2.18.dev2
3
+ Version: 3.2.19
4
4
  Summary: A set of pytest fixtures for testing Girder applications.
5
5
  Author: Kitware, Inc.
6
6
  Author-email: kitware@kitware.com
@@ -0,0 +1,8 @@
1
+ {
2
+ "tag": "3.2.19",
3
+ "distance": 0,
4
+ "node": "g82b4d1225ccd440fe15fb9743fcb165e0c64625d",
5
+ "dirty": false,
6
+ "branch": "HEAD",
7
+ "node_date": "2026-11-24"
8
+ }
@@ -1,8 +0,0 @@
1
- {
2
- "tag": "3.2.17",
3
- "distance": 2,
4
- "node": "g339bcdfe6c97a4eb52c194b29b6430523b66d778",
5
- "dirty": false,
6
- "branch": "3.x-maintenance",
7
- "node_date": "2026-09-21"
8
- }