Skip to content

Commit d8aa15d

Browse files
committed
linting
1 parent cb1e0ca commit d8aa15d

File tree

9 files changed

+168
-118
lines changed

9 files changed

+168
-118
lines changed

‎google/cloud/spanner_v1/instance.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -557,24 +557,25 @@ def copy_backup(
557557
self, backup_id, source_backup, expire_time=None, encryption_config=None,
558558
):
559559
"""Factory to create a copy backup within this instance.
560-
:type backup_id: str
561-
:param backup_id: The ID of the backup copy.
562-
:type source_backup: str
563-
:param source_backup_id: The full path of the source backup to be copied.
564-
:type expire_time: :class:`datetime.datetime`
565-
:param expire_time:
566-
Optional. The expire time that will be used when creating the copy backup.
567-
Required if the create method needs to be called.
568-
:type encryption_config:
569-
:class:`~google.cloud.spanner_admin_database_v1.types.CopyBackupEncryptionConfig`
570-
or :class:`dict`
571-
:param encryption_config:
572-
(Optional) Encryption configuration for the backup.
573-
If a dict is provided, it must be of the same form as the protobuf
574-
message :class:`~google.cloud.spanner_admin_database_v1.types.CopyBackupEncryptionConfig`
575-
:rtype: :class:`~google.cloud.spanner_v1.backup.Backup`
576-
:returns: a copy backup owned by this instance.
577-
"""
560+
561+
:type backup_id: str
562+
:param backup_id: The ID of the backup copy.
563+
:type source_backup: str
564+
:param source_backup_id: The full path of the source backup to be copied.
565+
:type expire_time: :class:`datetime.datetime`
566+
:param expire_time:
567+
Optional. The expire time that will be used when creating the copy backup.
568+
Required if the create method needs to be called.
569+
:type encryption_config:
570+
:class:`~google.cloud.spanner_admin_database_v1.types.CopyBackupEncryptionConfig`
571+
or :class:`dict`
572+
:param encryption_config:
573+
(Optional) Encryption configuration for the backup.
574+
If a dict is provided, it must be of the same form as the protobuf
575+
message :class:`~google.cloud.spanner_admin_database_v1.types.CopyBackupEncryptionConfig`
576+
:rtype: :class:`~google.cloud.spanner_v1.backup.Backup`
577+
:returns: a copy backup owned by this instance.
578+
"""
578579
return Backup(
579580
backup_id,
580581
self,

‎samples/samples/autocommit.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,11 @@ def enable_autocommit_mode(instance_id, database_id):
4646

4747
if __name__ == "__main__":
4848
parser = argparse.ArgumentParser(
49-
description=__doc__,
50-
formatter_class=argparse.RawDescriptionHelpFormatter,
49+
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter,
5150
)
5251
parser.add_argument("instance_id", help="Your Cloud Spanner instance ID.")
5352
parser.add_argument(
54-
"--database-id",
55-
help="Your Cloud Spanner database ID.",
56-
default="example_db",
53+
"--database-id", help="Your Cloud Spanner database ID.", default="example_db",
5754
)
5855
subparsers = parser.add_subparsers(dest="command")
5956
subparsers.add_parser("enable_autocommit_mode", help=enable_autocommit_mode.__doc__)

‎samples/samples/autocommit_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def sample_name():
1919
@RetryErrors(exception=Aborted, max_tries=2)
2020
def test_enable_autocommit_mode(capsys, instance_id, sample_database):
2121
# Delete table if it exists for retry attempts.
22-
table = sample_database.table('Singers')
22+
table = sample_database.table("Singers")
2323
if table.exists():
2424
op = sample_database.update_ddl(["DROP TABLE Singers"])
2525
op.result()

‎samples/samples/backup_sample.py

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def create_backup(instance_id, database_id, backup_id, version_time):
3434

3535
# Create a backup
3636
expire_time = datetime.utcnow() + timedelta(days=14)
37-
backup = instance.backup(backup_id, database=database, expire_time=expire_time, version_time=version_time)
37+
backup = instance.backup(
38+
backup_id, database=database, expire_time=expire_time, version_time=version_time
39+
)
3840
operation = backup.create()
3941

4042
# Wait for backup operation to complete.
@@ -56,7 +58,9 @@ def create_backup(instance_id, database_id, backup_id, version_time):
5658
# [END spanner_create_backup]
5759

5860
# [START spanner_create_backup_with_encryption_key]
59-
def create_backup_with_encryption_key(instance_id, database_id, backup_id, kms_key_name):
61+
def create_backup_with_encryption_key(
62+
instance_id, database_id, backup_id, kms_key_name
63+
):
6064
"""Creates a backup for a database using a Customer Managed Encryption Key (CMEK)."""
6165
from google.cloud.spanner_admin_database_v1 import CreateBackupEncryptionConfig
6266

@@ -67,10 +71,15 @@ def create_backup_with_encryption_key(instance_id, database_id, backup_id, kms_k
6771
# Create a backup
6872
expire_time = datetime.utcnow() + timedelta(days=14)
6973
encryption_config = {
70-
'encryption_type': CreateBackupEncryptionConfig.EncryptionType.CUSTOMER_MANAGED_ENCRYPTION,
71-
'kms_key_name': kms_key_name,
74+
"encryption_type": CreateBackupEncryptionConfig.EncryptionType.CUSTOMER_MANAGED_ENCRYPTION,
75+
"kms_key_name": kms_key_name,
7276
}
73-
backup = instance.backup(backup_id, database=database, expire_time=expire_time, encryption_config=encryption_config)
77+
backup = instance.backup(
78+
backup_id,
79+
database=database,
80+
expire_time=expire_time,
81+
encryption_config=encryption_config,
82+
)
7483
operation = backup.create()
7584

7685
# Wait for backup operation to complete.
@@ -115,7 +124,7 @@ def restore_database(instance_id, new_database_id, backup_id):
115124
restore_info.backup_info.source_database,
116125
new_database_id,
117126
restore_info.backup_info.backup,
118-
restore_info.backup_info.version_time
127+
restore_info.backup_info.version_time,
119128
)
120129
)
121130

@@ -124,7 +133,9 @@ def restore_database(instance_id, new_database_id, backup_id):
124133

125134

126135
# [START spanner_restore_backup_with_encryption_key]
127-
def restore_database_with_encryption_key(instance_id, new_database_id, backup_id, kms_key_name):
136+
def restore_database_with_encryption_key(
137+
instance_id, new_database_id, backup_id, kms_key_name
138+
):
128139
"""Restores a database from a backup using a Customer Managed Encryption Key (CMEK)."""
129140
from google.cloud.spanner_admin_database_v1 import RestoreDatabaseEncryptionConfig
130141

@@ -134,10 +145,12 @@ def restore_database_with_encryption_key(instance_id, new_database_id, backup_id
134145
# Start restoring an existing backup to a new database.
135146
backup = instance.backup(backup_id)
136147
encryption_config = {
137-
'encryption_type': RestoreDatabaseEncryptionConfig.EncryptionType.CUSTOMER_MANAGED_ENCRYPTION,
138-
'kms_key_name': kms_key_name,
148+
"encryption_type": RestoreDatabaseEncryptionConfig.EncryptionType.CUSTOMER_MANAGED_ENCRYPTION,
149+
"kms_key_name": kms_key_name,
139150
}
140-
new_database = instance.database(new_database_id, encryption_config=encryption_config)
151+
new_database = instance.database(
152+
new_database_id, encryption_config=encryption_config
153+
)
141154
operation = new_database.restore(backup)
142155

143156
# Wait for restore operation to complete.
@@ -210,7 +223,7 @@ def list_backup_operations(instance_id, database_id, backup_id):
210223
metadata.name, metadata.database, metadata.progress.progress_percent
211224
)
212225
)
213-
226+
214227
# List the CopyBackup operations.
215228
filter_ = (
216229
"(metadata.@type:type.googleapis.com/google.spanner.admin.database.v1.CopyBackupMetadata) "
@@ -221,7 +234,9 @@ def list_backup_operations(instance_id, database_id, backup_id):
221234
metadata = op.metadata
222235
print(
223236
"Backup {} on source backup {}: {}% complete.".format(
224-
metadata.name, metadata.source_backup, metadata.progress.progress_percent
237+
metadata.name,
238+
metadata.source_backup,
239+
metadata.progress.progress_percent,
225240
)
226241
)
227242

@@ -358,7 +373,9 @@ def update_backup(instance_id, backup_id):
358373

359374

360375
# [START spanner_create_database_with_version_retention_period]
361-
def create_database_with_version_retention_period(instance_id, database_id, retention_period):
376+
def create_database_with_version_retention_period(
377+
instance_id, database_id, retention_period
378+
):
362379
"""Creates a database with a version retention period."""
363380
spanner_client = spanner.Client()
364381
instance = spanner_client.instance(instance_id)
@@ -378,7 +395,7 @@ def create_database_with_version_retention_period(instance_id, database_id, rete
378395
"ALTER DATABASE `{}`"
379396
" SET OPTIONS (version_retention_period = '{}')".format(
380397
database_id, retention_period
381-
)
398+
),
382399
]
383400
db = instance.database(database_id, ddl_statements)
384401
operation = db.create()
@@ -387,12 +404,15 @@ def create_database_with_version_retention_period(instance_id, database_id, rete
387404

388405
db.reload()
389406

390-
print("Database {} created with version retention period {} and earliest version time {}".format(
391-
db.database_id, db.version_retention_period, db.earliest_version_time
392-
))
407+
print(
408+
"Database {} created with version retention period {} and earliest version time {}".format(
409+
db.database_id, db.version_retention_period, db.earliest_version_time
410+
)
411+
)
393412

394413
db.drop()
395414

415+
396416
# [END spanner_create_database_with_version_retention_period]
397417

398418

@@ -404,7 +424,9 @@ def copy_backup(instance_id, backup_id, source_backup_path):
404424

405425
# Create a backup object and wait for copy backup operation to complete.
406426
expire_time = datetime.utcnow() + timedelta(days=14)
407-
copy_backup = instance.copy_backup(backup_id=backup_id, source_backup=source_backup_path, expire_time=expire_time)
427+
copy_backup = instance.copy_backup(
428+
backup_id=backup_id, source_backup=source_backup_path, expire_time=expire_time
429+
)
408430
operation = copy_backup.create()
409431

410432
# Wait for copy backup operation to complete.
@@ -416,10 +438,14 @@ def copy_backup(instance_id, backup_id, source_backup_path):
416438

417439
print(
418440
"Backup {} of size {} bytes was created at {} with version time {}".format(
419-
copy_backup.name, copy_backup.size_bytes, copy_backup.create_time, copy_backup.version_time,
441+
copy_backup.name,
442+
copy_backup.size_bytes,
443+
copy_backup.create_time,
444+
copy_backup.version_time,
420445
)
421446
)
422447

448+
423449
# [END spanner_copy_backup]
424450

425451

‎samples/samples/backup_sample_test.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,22 @@ def test_create_backup(capsys, instance_id, sample_database):
5252
version_time = list(results)[0][0]
5353

5454
backup_sample.create_backup(
55-
instance_id,
56-
sample_database.database_id,
57-
BACKUP_ID,
58-
version_time,
55+
instance_id, sample_database.database_id, BACKUP_ID, version_time,
5956
)
6057
out, _ = capsys.readouterr()
6158
assert BACKUP_ID in out
6259

6360

64-
@pytest.mark.dependency(name="copy_backup",depends=["create_backup"])
61+
@pytest.mark.dependency(name="copy_backup", depends=["create_backup"])
6562
def test_copy_backup(capsys, instance_id, spanner_client):
66-
source_backp_path=spanner_client.project_name+'/instances/'+instance_id+'/backups/'+BACKUP_ID
67-
backup_sample.copy_backup(
68-
instance_id,
69-
COPY_BACKUP_ID,
70-
source_backp_path
63+
source_backp_path = (
64+
spanner_client.project_name
65+
+ "/instances/"
66+
+ instance_id
67+
+ "/backups/"
68+
+ BACKUP_ID
7169
)
70+
backup_sample.copy_backup(instance_id, COPY_BACKUP_ID, source_backp_path)
7271
out, _ = capsys.readouterr()
7372
assert COPY_BACKUP_ID in out
7473

@@ -78,10 +77,7 @@ def test_create_backup_with_encryption_key(
7877
capsys, instance_id, sample_database, kms_key_name,
7978
):
8079
backup_sample.create_backup_with_encryption_key(
81-
instance_id,
82-
sample_database.database_id,
83-
CMEK_BACKUP_ID,
84-
kms_key_name,
80+
instance_id, sample_database.database_id, CMEK_BACKUP_ID, kms_key_name,
8581
)
8682
out, _ = capsys.readouterr()
8783
assert CMEK_BACKUP_ID in out
@@ -104,7 +100,8 @@ def test_restore_database_with_encryption_key(
104100
capsys, instance_id, sample_database, kms_key_name,
105101
):
106102
backup_sample.restore_database_with_encryption_key(
107-
instance_id, CMEK_RESTORE_DB_ID, CMEK_BACKUP_ID, kms_key_name)
103+
instance_id, CMEK_RESTORE_DB_ID, CMEK_BACKUP_ID, kms_key_name
104+
)
108105
out, _ = capsys.readouterr()
109106
assert (sample_database.database_id + " restored to ") in out
110107
assert (CMEK_RESTORE_DB_ID + " from backup ") in out
@@ -115,20 +112,24 @@ def test_restore_database_with_encryption_key(
115112
@pytest.mark.dependency(depends=["create_backup", "copy_backup"])
116113
def test_list_backup_operations(capsys, instance_id, sample_database):
117114
backup_sample.list_backup_operations(
118-
instance_id, sample_database.database_id, BACKUP_ID)
115+
instance_id, sample_database.database_id, BACKUP_ID
116+
)
119117
out, _ = capsys.readouterr()
120118
assert BACKUP_ID in out
121119
assert sample_database.database_id in out
122120
assert COPY_BACKUP_ID in out
123121
print(out)
124122

125123

126-
@pytest.mark.dependency(depends=["create_backup"])
127-
def test_list_backups(capsys, instance_id, sample_database, ):
124+
@pytest.mark.dependency(name="list_backup", depends=["create_backup", "copy_backup"])
125+
def test_list_backups(
126+
capsys, instance_id, sample_database,
127+
):
128128
backup_sample.list_backups(
129129
instance_id, sample_database.database_id, BACKUP_ID,
130130
)
131131
out, _ = capsys.readouterr()
132+
print(out)
132133
id_count = out.count(BACKUP_ID)
133134
assert id_count == 7
134135

@@ -140,7 +141,7 @@ def test_update_backup(capsys, instance_id):
140141
assert BACKUP_ID in out
141142

142143

143-
@pytest.mark.dependency(depends=["create_backup","copy_backup"])
144+
@pytest.mark.dependency(depends=["create_backup", "copy_backup", "list_backup"])
144145
def test_delete_backup(capsys, instance_id):
145146
backup_sample.delete_backup(instance_id, BACKUP_ID)
146147
out, _ = capsys.readouterr()
@@ -173,4 +174,3 @@ def test_create_database_with_retention_period(capsys, sample_instance):
173174
assert ("retention period " + RETENTION_PERIOD) in out
174175
database = sample_instance.database(RETENTION_DATABASE_ID)
175176
database.drop()
176-

‎samples/samples/conftest.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ def instance_config(spanner_client):
9393

9494
@pytest.fixture(scope="module")
9595
def multi_region_instance_config(spanner_client):
96-
return "{}/instanceConfigs/{}".format(
97-
spanner_client.project_name, "nam3"
98-
)
96+
return "{}/instanceConfigs/{}".format(spanner_client.project_name, "nam3")
9997

10098

10199
@pytest.fixture(scope="module")
@@ -143,7 +141,7 @@ def multi_region_instance(
143141
labels={
144142
"cloud_spanner_samples": "true",
145143
"sample_name": sample_name,
146-
"created": str(int(time.time()))
144+
"created": str(int(time.time())),
147145
},
148146
)
149147
op = retry_429(multi_region_instance.create)()

‎samples/samples/noxfile.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,7 @@ def _session_tests(
208208

209209
if os.path.exists("requirements-test.txt"):
210210
if os.path.exists("constraints-test.txt"):
211-
session.install(
212-
"-r", "requirements-test.txt", "-c", "constraints-test.txt"
213-
)
211+
session.install("-r", "requirements-test.txt", "-c", "constraints-test.txt")
214212
else:
215213
session.install("-r", "requirements-test.txt")
216214
with open("requirements-test.txt") as rtfile:
@@ -223,9 +221,9 @@ def _session_tests(
223221
post_install(session)
224222

225223
if "pytest-parallel" in packages:
226-
concurrent_args.extend(['--workers', 'auto', '--tests-per-worker', 'auto'])
224+
concurrent_args.extend(["--workers", "auto", "--tests-per-worker", "auto"])
227225
elif "pytest-xdist" in packages:
228-
concurrent_args.extend(['-n', 'auto'])
226+
concurrent_args.extend(["-n", "auto"])
229227

230228
session.run(
231229
"pytest",

0 commit comments

Comments
 (0)