Skip to content

Commit

Permalink
minor formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
CuriousLearner committed Nov 27, 2024
1 parent dd462b6 commit f7c5fa6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
10 changes: 6 additions & 4 deletions src/django_libsql/base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import logging
from collections.abc import Mapping
from itertools import chain, tee
from django.utils.regex_helper import _lazy_re_compile
import libsql_experimental as libsql_client

from django.db.backends.sqlite3._functions import register as register_functions
from django.db.backends.sqlite3.base import DatabaseWrapper as SQLite3DatabaseWrapper
import libsql_experimental as libsql_client
from django.db.backends.sqlite3._functions import \
register as register_functions
from django.db.backends.sqlite3.base import \
DatabaseWrapper as SQLite3DatabaseWrapper
from django.utils.asyncio import async_unsafe
from django.utils.regex_helper import _lazy_re_compile

from .creation import DatabaseCreation

Expand Down
26 changes: 8 additions & 18 deletions src/django_libsql/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
import multiprocessing
import os
import shutil
import sqlite3
import sys
from functools import cached_property
from http import HTTPStatus
from urllib.parse import urlparse

from django.db import NotSupportedError
from django.db.backends.sqlite3.creation import DatabaseCreation as SQLite3DatabaseCreation
from django.conf import settings
from django.db import NotSupportedError
from django.db.backends.sqlite3.creation import \
DatabaseCreation as SQLite3DatabaseCreation


class DatabaseCreation(SQLite3DatabaseCreation):

Expand Down Expand Up @@ -90,9 +91,7 @@ def _get_test_db_sync_url(self):
test_database_sync_url = self.connection.settings_dict["TEST"]["SYNC_URL"]
return test_database_sync_url

def create_test_db(
self, verbosity=1, autoclobber=False, serialize=True, keepdb=False
):
def create_test_db(self, verbosity=1, autoclobber=False, serialize=True, keepdb=False):
"""
Create a test database, prompting the user for confirmation if the
database already exists. Return the name of the test database created.
Expand Down Expand Up @@ -133,9 +132,7 @@ def create_test_db(
if self.connection.settings_dict["TEST"]["MIGRATE"] is False:
# Disable migrations for all apps.
old_migration_modules = settings.MIGRATION_MODULES
settings.MIGRATION_MODULES = {
app.label: None for app in apps.get_app_configs()
}
settings.MIGRATION_MODULES = {app.label: None for app in apps.get_app_configs()}
# We report migrate messages at one level lower than that
# requested. This ensures we don't get flooded with messages during
# testing (unless you really ask to be flooded).
Expand Down Expand Up @@ -219,17 +216,12 @@ def get_test_db_clone_settings(self, suffix):
start_method = multiprocessing.get_start_method()
if start_method == "fork":
return orig_settings_dict
raise NotSupportedError(
f"Cloning with start method {start_method!r} is not supported."
)
raise NotSupportedError(f"Cloning with start method {start_method!r} is not supported.")

def _clone_test_db(self, suffix, verbosity, keepdb=False):
"""
Internal implementation - duplicate the test db tables.
"""
import os
import shutil

try:
# Get the source database name from settings
source_database = self.connection.settings_dict["NAME"]
Expand All @@ -249,9 +241,7 @@ def _clone_test_db(self, suffix, verbosity, keepdb=False):
print(f"Cloned test database '{source_database}' to '{clone_database}'")

except Exception as e:
raise NotImplementedError(
"Cloning databases is not supported for this backend."
) from e
raise NotImplementedError("Cloning databases is not supported for this backend.") from e

def _destroy_test_db(self, test_database_name, verbosity):
if test_database_name and not self.is_in_memory_db(test_database_name):
Expand Down

0 comments on commit f7c5fa6

Please sign in to comment.