From fb4f33c11f2cfb2ac9d295130c87218bc3c00e5f Mon Sep 17 00:00:00 2001 From: Zach Sailer Date: Mon, 6 Dec 2021 11:04:12 -0800 Subject: [PATCH] precommit cleanup --- .../services/sessions/sessionmanager.py | 10 +++++---- .../tests/services/sessions/test_manager.py | 21 +++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/jupyter_server/services/sessions/sessionmanager.py b/jupyter_server/services/sessions/sessionmanager.py index e73f580006..8d736f3b93 100644 --- a/jupyter_server/services/sessions/sessionmanager.py +++ b/jupyter_server/services/sessions/sessionmanager.py @@ -2,8 +2,8 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. import os -import uuid import pathlib +import uuid try: import sqlite3 @@ -32,7 +32,7 @@ class SessionManager(LoggingConfigurable): "(e.g. /path/to/session_database.db). By default, the session " "database is stored in-memory (i.e. `:memory:` setting from sqlite3) " "and does not persist when the current Jupyter Server shuts down." - ) + ), ).tag(config=True) @validate("database_filepath") @@ -44,14 +44,16 @@ def _validate_database_filepath(self, proposal): if path.exists(): # Verify that the database path is not a directory. if path.is_dir(): - raise TraitError("`database_filepath` expected a file path, but the given path is a directory.") + raise TraitError( + "`database_filepath` expected a file path, but the given path is a directory." + ) # If the file exists, but it's empty, its a valid entry. if os.stat(path).st_size == 0: return value # Verify that database path is an SQLite 3 Database by checking its header. with open(value, "rb") as f: header = f.read(100) - if not header.startswith(b'SQLite format 3'): + if not header.startswith(b"SQLite format 3"): raise TraitError("The file does not look like ") return value diff --git a/jupyter_server/tests/services/sessions/test_manager.py b/jupyter_server/tests/services/sessions/test_manager.py index e85ad2dbdb..3ca8da8df1 100644 --- a/jupyter_server/tests/services/sessions/test_manager.py +++ b/jupyter_server/tests/services/sessions/test_manager.py @@ -1,5 +1,4 @@ import pytest -import pathlib from tornado import web from traitlets import TraitError @@ -268,7 +267,6 @@ async def test_bad_delete_session(session_manager): await session_manager.delete_session(session_id="23424") # nonexistent - async def test_bad_database_filepath(jp_runtime_dir): kernel_manager = DummyMKM() @@ -276,10 +274,10 @@ async def test_bad_database_filepath(jp_runtime_dir): path_id_directory = str(jp_runtime_dir) # Should raise an error because the path is a directory. with pytest.raises(TraitError) as err: - SessionManager( + SessionManager( kernel_manager=kernel_manager, contents_manager=ContentsManager(), - database_filepath=str(path_id_directory) + database_filepath=str(path_id_directory), ) # Try writing to file that's not a valid SQLite 3 database file. @@ -289,10 +287,10 @@ async def test_bad_database_filepath(jp_runtime_dir): # Should raise an error because the file doesn't # start with an SQLite database file header. with pytest.raises(TraitError) as err: - SessionManager( + SessionManager( kernel_manager=kernel_manager, contents_manager=ContentsManager(), - database_filepath=str(non_db_file) + database_filepath=str(non_db_file), ) @@ -306,7 +304,7 @@ async def test_good_database_filepath(jp_runtime_dir): session_manager = SessionManager( kernel_manager=kernel_manager, contents_manager=ContentsManager(), - database_filepath=str(empty_file) + database_filepath=str(empty_file), ) await session_manager.create_session( @@ -322,11 +320,12 @@ async def test_good_database_filepath(jp_runtime_dir): session_manager = SessionManager( kernel_manager=kernel_manager, contents_manager=ContentsManager(), - database_filepath=str(empty_file) + database_filepath=str(empty_file), ) assert session_manager.database_filepath == str(empty_file) + async def test_session_persistence(jp_runtime_dir): session_db_path = jp_runtime_dir.joinpath("test-session.db") # Kernel manager needs to persist. @@ -337,7 +336,7 @@ async def test_session_persistence(jp_runtime_dir): session_manager = SessionManager( kernel_manager=kernel_manager, contents_manager=ContentsManager(), - database_filepath=str(session_db_path) + database_filepath=str(session_db_path), ) session = await session_manager.create_session( @@ -350,7 +349,7 @@ async def test_session_persistence(jp_runtime_dir): with open(session_db_path, "rb") as f: header = f.read(100) - assert header.startswith(b'SQLite format 3') + assert header.startswith(b"SQLite format 3") # Close the current session manager del session_manager @@ -359,7 +358,7 @@ async def test_session_persistence(jp_runtime_dir): session_manager = SessionManager( kernel_manager=kernel_manager, contents_manager=ContentsManager(), - database_filepath=str(session_db_path) + database_filepath=str(session_db_path), ) # Assert that the session database persists.