Skip to content

Commit

Permalink
chore: Code refactoring to follow common Google API scheme - Stage I (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mf2199 authored and c24t committed Sep 15, 2020
1 parent dc73bf6 commit 21f8229
Show file tree
Hide file tree
Showing 23 changed files with 32 additions and 22 deletions.
3 changes: 1 addition & 2 deletions django_spanner/base.py
Expand Up @@ -4,9 +4,8 @@
# license that can be found in the LICENSE file or at
# https://developers.google.com/open-source/licenses/bsd

import spanner_dbapi as Database
from django.db.backends.base.base import BaseDatabaseWrapper
from google.cloud import spanner_v1 as spanner
from google.cloud import spanner_v1 as spanner, spanner_dbapi as Database

from .client import DatabaseClient
from .creation import DatabaseCreation
Expand Down
6 changes: 5 additions & 1 deletion django_spanner/operations.py
Expand Up @@ -16,7 +16,11 @@
from django.db.utils import DatabaseError
from django.utils import timezone
from django.utils.duration import duration_microseconds
from spanner_dbapi.parse_utils import DateStr, TimestampStr, escape_name
from google.cloud.spanner_dbapi.parse_utils import (
DateStr,
TimestampStr,
escape_name,
)


class DatabaseOperations(BaseDatabaseOperations):
Expand Down
Empty file added google/__init__.py
Empty file.
Empty file added google/cloud/__init__.py
Empty file.
Expand Up @@ -97,6 +97,7 @@ def connect(


__all__ = [
"Connection",
"DatabaseError",
"DataError",
"Error",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions noxfile.py
Expand Up @@ -18,7 +18,7 @@
BLACK_PATHS = [
"django_spanner",
"docs",
"spanner_dbapi",
"google",
"tests",
"noxfile.py",
"setup.py",
Expand All @@ -34,7 +34,7 @@ def lint(session):
"""
session.install("flake8", BLACK_VERSION)
session.run("black", "--check", *BLACK_PATHS)
session.run("flake8", "django_spanner", "spanner_dbapi", "tests")
session.run("flake8", "django_spanner", "google", "tests")


@nox.session(python="3.8")
Expand Down Expand Up @@ -70,7 +70,7 @@ def default(session):
"py.test",
"--quiet",
"--cov=django_spanner",
"--cov=spanner_dbapi",
"--cov=google.cloud",
"--cov=tests.spanner_dbapi",
"--cov-append",
"--cov-config=.coveragerc",
Expand Down Expand Up @@ -126,7 +126,7 @@ def cover(session):
test runs (not system test runs), and then erases coverage data.
"""
session.install("coverage", "pytest-cov")
session.run("coverage", "report", "--show-missing", "--fail-under=20")
session.run("coverage", "report", "--show-missing", "--fail-under=40")
session.run("coverage", "erase")


Expand Down
9 changes: 6 additions & 3 deletions tests/spanner_dbapi/test_connect.py
Expand Up @@ -11,7 +11,7 @@

import google.auth.credentials
from google.api_core.gapic_v1.client_info import ClientInfo
from spanner_dbapi import connect, Connection
from google.cloud.spanner_dbapi import connect, Connection


def _make_credentials():
Expand All @@ -30,9 +30,12 @@ def test_connect(self):
CREDENTIALS = _make_credentials()
CLIENT_INFO = ClientInfo(user_agent=USER_AGENT)

with mock.patch("spanner_dbapi.spanner_v1.Client") as client_mock:
with mock.patch(
"google.cloud.spanner_dbapi.spanner_v1.Client"
) as client_mock:
with mock.patch(
"spanner_dbapi.google_client_info", return_value=CLIENT_INFO
"google.cloud.spanner_dbapi.google_client_info",
return_value=CLIENT_INFO,
) as client_info_mock:

connection = connect(
Expand Down
2 changes: 1 addition & 1 deletion tests/spanner_dbapi/test_connection.py
Expand Up @@ -9,7 +9,7 @@
import unittest
from unittest import mock

from spanner_dbapi import connect, InterfaceError
from google.cloud.spanner_dbapi import connect, InterfaceError


class TestConnection(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/spanner_dbapi/test_cursor.py
Expand Up @@ -9,7 +9,7 @@
import unittest
from unittest import mock

from spanner_dbapi import connect, InterfaceError
from google.cloud.spanner_dbapi import connect, InterfaceError


class TestCursor(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/spanner_dbapi/test_globals.py
Expand Up @@ -6,7 +6,7 @@

from unittest import TestCase

from spanner_dbapi import apilevel, paramstyle, threadsafety
from google.cloud.spanner_dbapi import apilevel, paramstyle, threadsafety


class DBAPIGlobalsTests(TestCase):
Expand Down
6 changes: 3 additions & 3 deletions tests/spanner_dbapi/test_parse_utils.py
Expand Up @@ -9,8 +9,8 @@
from unittest import TestCase

from google.cloud.spanner_v1 import param_types
from spanner_dbapi.exceptions import Error, ProgrammingError
from spanner_dbapi.parse_utils import (
from google.cloud.spanner_dbapi.exceptions import Error, ProgrammingError
from google.cloud.spanner_dbapi.parse_utils import (
STMT_DDL,
STMT_NON_UPDATING,
DateStr,
Expand All @@ -24,7 +24,7 @@
sql_pyformat_args_to_spanner,
strip_backticks,
)
from spanner_dbapi.utils import backtick_unicode
from google.cloud.spanner_dbapi.utils import backtick_unicode


class ParseUtilsTests(TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tests/spanner_dbapi/test_parser.py
Expand Up @@ -6,8 +6,8 @@

from unittest import TestCase

from spanner_dbapi.exceptions import ProgrammingError
from spanner_dbapi.parser import (
from google.cloud.spanner_dbapi.exceptions import ProgrammingError
from google.cloud.spanner_dbapi.parser import (
ARGS,
FUNC,
TERMINAL,
Expand Down
4 changes: 2 additions & 2 deletions tests/spanner_dbapi/test_types.py
Expand Up @@ -7,15 +7,15 @@
import datetime
from unittest import TestCase

from spanner_dbapi.types import (
from google.cloud.spanner_dbapi.types import (
Date,
DateFromTicks,
Time,
TimeFromTicks,
Timestamp,
TimestampFromTicks,
)
from spanner_dbapi.utils import PeekIterator
from google.cloud.spanner_dbapi.utils import PeekIterator

tzUTC = 0 # 0 hours offset from UTC

Expand Down
2 changes: 1 addition & 1 deletion tests/spanner_dbapi/test_utils.py
Expand Up @@ -6,7 +6,7 @@

from unittest import TestCase

from spanner_dbapi.utils import PeekIterator
from google.cloud.spanner_dbapi.utils import PeekIterator


class UtilsTests(TestCase):
Expand Down
5 changes: 4 additions & 1 deletion tests/spanner_dbapi/test_version.py
Expand Up @@ -8,7 +8,10 @@
from unittest import TestCase

from google.api_core.gapic_v1.client_info import ClientInfo
from spanner_dbapi.version import DEFAULT_USER_AGENT, google_client_info
from google.cloud.spanner_dbapi.version import (
DEFAULT_USER_AGENT,
google_client_info,
)

vers = sys.version_info

Expand Down

0 comments on commit 21f8229

Please sign in to comment.