Skip to content

Commit

Permalink
Address some codeQL issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-bates committed May 21, 2021
1 parent 29d90ab commit 9c25147
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
19 changes: 9 additions & 10 deletions jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,16 +512,15 @@ def start(self):
if port == self.port:
self._shutdown_or_exit(port, server)
return
else:
current_endpoint = self.sock or self.port
print(
"There is currently no server running on {}".format(current_endpoint),
file=sys.stderr
)
print("Ports/sockets currently in use:", file=sys.stderr)
for server in servers:
print(" - {}".format(server.get('sock') or server['port']), file=sys.stderr)
self.exit(1)
current_endpoint = self.sock or self.port
print(
"There is currently no server running on {}".format(current_endpoint),
file=sys.stderr
)
print("Ports/sockets currently in use:", file=sys.stderr)
for server in servers:
print(" - {}".format(server.get('sock') or server['port']), file=sys.stderr)
self.exit(1)


class JupyterServerListApp(JupyterApp):
Expand Down
14 changes: 9 additions & 5 deletions jupyter_server/tests/unix_sockets/test_serverapp_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def test_shutdown_sock_server_integration(jp_unix_socket_file):

assert complete, 'did not find socket URL in stdout when launching notebook'

assert encoded_sock_path.encode() in subprocess.check_output(['jupyter-server', 'list'])
socket_path = encoded_sock_path.encode()
assert socket_path in subprocess.check_output(['jupyter-server', 'list'])

# Ensure umask is properly applied.
assert stat.S_IMODE(os.lstat(jp_unix_socket_file).st_mode) == 0o700
Expand Down Expand Up @@ -120,7 +121,8 @@ def test_stop_multi_integration(jp_unix_socket_file, jp_http_port):

time.sleep(3)

assert MSG_TMPL.format(jp_http_port) in subprocess.check_output(
shutdown_msg = MSG_TMPL.format(jp_http_port)
assert shutdown_msg in subprocess.check_output(
['jupyter-server', 'stop']
).decode()

Expand Down Expand Up @@ -157,10 +159,12 @@ def test_launch_socket_collision(jp_unix_socket_file):
# Try to start a server bound to the same UNIX socket.
try:
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
assert check_msg in e.output.decode()
except subprocess.CalledProcessError as cpe:
assert check_msg in cpe.output.decode()
except Exception as ex:
raise AssertionError(f"expected 'already in use' error, got '{ex}'!")
else:
raise AssertionError('expected error, instead got %s' % e.output.decode())
raise AssertionError(f"expected 'already in use' error, got success instead!")

# Stop the background server, ensure it's stopped and wait on the process to exit.
subprocess.check_call(['jupyter-server', 'stop', sock])
Expand Down

0 comments on commit 9c25147

Please sign in to comment.