Skip to content

Commit

Permalink
chore: drop use of pytz in systests
Browse files Browse the repository at this point in the history
See #479 for rationale.
  • Loading branch information
tseaver committed Aug 6, 2021
1 parent 23910ac commit 4b3a9e8
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions tests/system/test_backup_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import time

import pytest
from pytz import UTC

from google.api_core import exceptions
from google.cloud import spanner_v1
Expand Down Expand Up @@ -82,7 +81,7 @@ def diff_config_instance(

@pytest.fixture(scope="session")
def database_version_time():
return datetime.datetime.utcnow().replace(tzinfo=UTC)
return datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc)


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -126,7 +125,7 @@ def test_backup_workflow(

backup_id = _helpers.unique_id("backup_id", separator="_")
expire_time = datetime.datetime.utcnow() + datetime.timedelta(days=3)
expire_time = expire_time.replace(tzinfo=UTC)
expire_time = expire_time.replace(tzinfo=datetime.timezone.utc)
encryption_enum = CreateBackupEncryptionConfig.EncryptionType
encryption_config = CreateBackupEncryptionConfig(
encryption_type=encryption_enum.GOOGLE_DEFAULT_ENCRYPTION,
Expand Down Expand Up @@ -164,7 +163,7 @@ def test_backup_workflow(

# Update with valid argument.
valid_expire_time = datetime.datetime.utcnow() + datetime.timedelta(days=7)
valid_expire_time = valid_expire_time.replace(tzinfo=UTC)
valid_expire_time = valid_expire_time.replace(tzinfo=datetime.timezone.utc)
backup.update_expire_time(valid_expire_time)
assert valid_expire_time == backup.expire_time

Expand Down Expand Up @@ -202,7 +201,7 @@ def test_backup_create_w_version_time_dflt_to_create_time(
):
backup_id = _helpers.unique_id("backup_id", separator="_")
expire_time = datetime.datetime.utcnow() + datetime.timedelta(days=3)
expire_time = expire_time.replace(tzinfo=UTC)
expire_time = expire_time.replace(tzinfo=datetime.timezone.utc)

# Create backup.
backup = shared_instance.backup(
Expand All @@ -229,7 +228,7 @@ def test_backup_create_w_version_time_dflt_to_create_time(

def test_backup_create_w_invalid_expire_time(shared_instance, shared_database):
backup_id = _helpers.unique_id("backup_id", separator="_")
expire_time = datetime.datetime.utcnow().replace(tzinfo=UTC)
expire_time = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc)

backup = shared_instance.backup(
backup_id, database=shared_database, expire_time=expire_time
Expand All @@ -245,9 +244,9 @@ def test_backup_create_w_invalid_version_time_past(
):
backup_id = _helpers.unique_id("backup_id", separator="_")
expire_time = datetime.datetime.utcnow() + datetime.timedelta(days=3)
expire_time = expire_time.replace(tzinfo=UTC)
expire_time = expire_time.replace(tzinfo=datetime.timezone.utc)
version_time = datetime.datetime.utcnow() - datetime.timedelta(days=10)
version_time = version_time.replace(tzinfo=UTC)
version_time = version_time.replace(tzinfo=datetime.timezone.utc)

backup = shared_instance.backup(
backup_id,
Expand All @@ -266,9 +265,9 @@ def test_backup_create_w_invalid_version_time_future(
):
backup_id = _helpers.unique_id("backup_id", separator="_")
expire_time = datetime.datetime.utcnow() + datetime.timedelta(days=3)
expire_time = expire_time.replace(tzinfo=UTC)
expire_time = expire_time.replace(tzinfo=datetime.timezone.utc)
version_time = datetime.datetime.utcnow() + datetime.timedelta(days=2)
version_time = version_time.replace(tzinfo=UTC)
version_time = version_time.replace(tzinfo=datetime.timezone.utc)

backup = shared_instance.backup(
backup_id,
Expand All @@ -291,7 +290,7 @@ def test_database_restore_to_diff_instance(
):
backup_id = _helpers.unique_id("backup_id", separator="_")
expire_time = datetime.datetime.utcnow() + datetime.timedelta(days=3)
expire_time = expire_time.replace(tzinfo=UTC)
expire_time = expire_time.replace(tzinfo=datetime.timezone.utc)

# Create backup.
backup = shared_instance.backup(
Expand Down Expand Up @@ -325,7 +324,7 @@ def test_multi_create_cancel_update_error_restore_errors(
backup_id_1 = _helpers.unique_id("backup_id1", separator="_")
backup_id_2 = _helpers.unique_id("backup_id2", separator="_")
expire_time = datetime.datetime.utcnow() + datetime.timedelta(days=3)
expire_time = expire_time.replace(tzinfo=UTC)
expire_time = expire_time.replace(tzinfo=datetime.timezone.utc)

backup1 = shared_instance.backup(
backup_id_1, database=shared_database, expire_time=expire_time
Expand Down Expand Up @@ -357,7 +356,7 @@ def test_multi_create_cancel_update_error_restore_errors(
# Update expire time to invalid value.
max_expire_days = 366 # documented maximum
invalid_expire_time = datetime.datetime.now().replace(
tzinfo=UTC
tzinfo=datetime.timezone.utc
) + datetime.timedelta(days=max_expire_days + 1)
with pytest.raises(exceptions.InvalidArgument):
backup1.update_expire_time(invalid_expire_time)
Expand Down Expand Up @@ -388,7 +387,7 @@ def test_instance_list_backups(
backup_id_2 = _helpers.unique_id("backup_id2", separator="_")

expire_time_1 = datetime.datetime.utcnow() + datetime.timedelta(days=21)
expire_time_1 = expire_time_1.replace(tzinfo=UTC)
expire_time_1 = expire_time_1.replace(tzinfo=datetime.timezone.utc)
expire_time_1_stamp = expire_time_1.strftime("%Y-%m-%dT%H:%M:%S.%fZ")

backup1 = shared_instance.backup(
Expand All @@ -399,7 +398,7 @@ def test_instance_list_backups(
)

expire_time_2 = datetime.datetime.utcnow() + datetime.timedelta(days=1)
expire_time_2 = expire_time_2.replace(tzinfo=UTC)
expire_time_2 = expire_time_2.replace(tzinfo=datetime.timezone.utc)
backup2 = shared_instance.backup(
backup_id_2, database=second_database, expire_time=expire_time_2
)
Expand All @@ -410,7 +409,9 @@ def test_instance_list_backups(
op1.result() # blocks indefinitely
backup1.reload()

create_time_compare = datetime.datetime.utcnow().replace(tzinfo=UTC)
create_time_compare = datetime.datetime.utcnow().replace(
tzinfo=datetime.timezone.utc
)
create_time_stamp = create_time_compare.strftime("%Y-%m-%dT%H:%M:%S.%fZ")

backup2.create()
Expand Down

0 comments on commit 4b3a9e8

Please sign in to comment.