From ebeb020b9aa12393fdb11221c3e47175408e2659 Mon Sep 17 00:00:00 2001 From: Vikash Singh <3116482+vi3k6i5@users.noreply.github.com> Date: Wed, 26 May 2021 01:06:59 +0530 Subject: [PATCH 1/2] refactor: update coverage score in nox file and cleanup imports in test_operations --- noxfile.py | 4 +- tests/unit/django_spanner/test_operations.py | 46 +++++++++----------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/noxfile.py b/noxfile.py index 569650a335..b2d42a5174 100644 --- a/noxfile.py +++ b/noxfile.py @@ -87,7 +87,7 @@ def default(session): "--cov-append", "--cov-config=.coveragerc", "--cov-report=", - "--cov-fail-under=65", + "--cov-fail-under=80", os.path.join("tests", "unit"), *session.posargs, ) @@ -157,7 +157,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=65") + session.run("coverage", "report", "--show-missing", "--fail-under=80") session.run("coverage", "erase") diff --git a/tests/unit/django_spanner/test_operations.py b/tests/unit/django_spanner/test_operations.py index 9bed6a447e..ed52e1b49b 100644 --- a/tests/unit/django_spanner/test_operations.py +++ b/tests/unit/django_spanner/test_operations.py @@ -4,10 +4,15 @@ # license that can be found in the LICENSE file or at # https://developers.google.com/open-source/licenses/bsd -from django.db.utils import DatabaseError +from base64 import b64encode from datetime import timedelta -from tests.unit.django_spanner.simple_test import SpannerSimpleTestClass from decimal import Decimal +from django.conf import settings +from django.core.management.color import no_style +from django.db.utils import DatabaseError +from google.cloud.spanner_dbapi.types import DateStr +from tests.unit.django_spanner.simple_test import SpannerSimpleTestClass +import uuid class TestOperations(SpannerSimpleTestClass): @@ -29,8 +34,6 @@ def test_bulk_batch_size(self): ) def test_sql_flush(self): - from django.core.management.color import no_style - self.assertEqual( self.db_operations.sql_flush( style=no_style(), tables=["Table1", "Table2"] @@ -39,17 +42,15 @@ def test_sql_flush(self): ) def test_sql_flush_empty_table_list(self): - from django.core.management.color import no_style - self.assertEqual( - self.db_operations.sql_flush(style=no_style(), tables=[]), [], + self.db_operations.sql_flush(style=no_style(), tables=[]), + [], ) def test_adapt_datefield_value(self): - from google.cloud.spanner_dbapi.types import DateStr - self.assertIsInstance( - self.db_operations.adapt_datefield_value("dummy_date"), DateStr, + self.db_operations.adapt_datefield_value("dummy_date"), + DateStr, ) def test_adapt_datefield_value_none(self): @@ -69,8 +70,6 @@ def test_adapt_decimalfield_value_none(self): ) def test_convert_binaryfield_value(self): - from base64 import b64encode - self.assertEqual( self.db_operations.convert_binaryfield_value( value=b64encode(b"abc"), expression=None, connection=None @@ -96,8 +95,6 @@ def test_adapt_timefield_value_none(self): ) def test_convert_uuidfield_value(self): - import uuid - uuid_obj = uuid.uuid4() self.assertEqual( self.db_operations.convert_uuidfield_value( @@ -126,8 +123,6 @@ def test_date_extract_sql_lookup_type_dayofweek(self): ) def test_datetime_extract_sql(self): - from django.conf import settings - settings.USE_TZ = True self.assertEqual( self.db_operations.datetime_extract_sql( @@ -137,8 +132,6 @@ def test_datetime_extract_sql(self): ) def test_datetime_extract_sql_use_tz_false(self): - from django.conf import settings - settings.USE_TZ = False self.assertEqual( self.db_operations.datetime_extract_sql( @@ -167,8 +160,6 @@ def test_datetime_cast_date_sql(self): ) def test_datetime_cast_time_sql(self): - from django.conf import settings - settings.USE_TZ = True self.assertEqual( self.db_operations.datetime_cast_time_sql("dummy_field", "IST"), @@ -176,8 +167,6 @@ def test_datetime_cast_time_sql(self): ) def test_datetime_cast_time_sql_use_tz_false(self): - from django.conf import settings - settings.USE_TZ = False self.assertEqual( self.db_operations.datetime_cast_time_sql("dummy_field", "IST"), @@ -217,7 +206,8 @@ def test_combine_expression_bit_extention(self): def test_combine_expression_multiply(self): self.assertEqual( - self.db_operations.combine_expression("*", ["10", "2"]), "10 * 2", + self.db_operations.combine_expression("*", ["10", "2"]), + "10 * 2", ) def test_combine_duration_expression_add(self): @@ -248,10 +238,16 @@ def test_combine_duration_expression_database_error(self): def test_lookup_cast_match_lookup_type(self): self.assertEqual( - self.db_operations.lookup_cast("contains",), "CAST(%s AS STRING)", + self.db_operations.lookup_cast( + "contains", + ), + "CAST(%s AS STRING)", ) def test_lookup_cast_unmatched_lookup_type(self): self.assertEqual( - self.db_operations.lookup_cast("dummy",), "%s", + self.db_operations.lookup_cast( + "dummy", + ), + "%s", ) From 8853f41d5a9d77cfa27954fa15a02e612129a702 Mon Sep 17 00:00:00 2001 From: Vikash Singh <3116482+vi3k6i5@users.noreply.github.com> Date: Wed, 26 May 2021 01:10:03 +0530 Subject: [PATCH 2/2] refactor: lint correction in test_operations --- tests/unit/django_spanner/test_operations.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/tests/unit/django_spanner/test_operations.py b/tests/unit/django_spanner/test_operations.py index ed52e1b49b..a946b51303 100644 --- a/tests/unit/django_spanner/test_operations.py +++ b/tests/unit/django_spanner/test_operations.py @@ -43,14 +43,12 @@ def test_sql_flush(self): def test_sql_flush_empty_table_list(self): self.assertEqual( - self.db_operations.sql_flush(style=no_style(), tables=[]), - [], + self.db_operations.sql_flush(style=no_style(), tables=[]), [], ) def test_adapt_datefield_value(self): self.assertIsInstance( - self.db_operations.adapt_datefield_value("dummy_date"), - DateStr, + self.db_operations.adapt_datefield_value("dummy_date"), DateStr, ) def test_adapt_datefield_value_none(self): @@ -206,8 +204,7 @@ def test_combine_expression_bit_extention(self): def test_combine_expression_multiply(self): self.assertEqual( - self.db_operations.combine_expression("*", ["10", "2"]), - "10 * 2", + self.db_operations.combine_expression("*", ["10", "2"]), "10 * 2", ) def test_combine_duration_expression_add(self): @@ -238,16 +235,10 @@ def test_combine_duration_expression_database_error(self): def test_lookup_cast_match_lookup_type(self): self.assertEqual( - self.db_operations.lookup_cast( - "contains", - ), - "CAST(%s AS STRING)", + self.db_operations.lookup_cast("contains",), "CAST(%s AS STRING)", ) def test_lookup_cast_unmatched_lookup_type(self): self.assertEqual( - self.db_operations.lookup_cast( - "dummy", - ), - "%s", + self.db_operations.lookup_cast("dummy",), "%s", )