Skip to content

Commit 5e7a81d

Browse files
feat: upgrade sample style (Other) (GoogleCloudPlatform#9944)
Co-authored-by: Andrew Ferlitsch <aferlitsch@gmail.com>
1 parent 6e063e0 commit 5e7a81d

File tree

53 files changed

+152
-172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+152
-172
lines changed

asset/snippets/quickstart_analyzeiampolicy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def analyze_iam_policy(project_id):
2525
# TODO project_id = 'Your Google Cloud Project ID'
2626

2727
client = asset_v1.AssetServiceClient()
28-
parent = "projects/{}".format(project_id)
28+
parent = f"projects/{project_id}"
2929

3030
# Build analysis query
3131
analysis_query = asset_v1.IamPolicyAnalysisQuery()

asset/snippets/quickstart_analyzeiampolicylongrunning.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def analyze_iam_policy_longrunning_gcs(project_id, dump_file_path):
2626
# TODO dump_file_path = 'Your analysis dump file path'
2727

2828
client = asset_v1.AssetServiceClient()
29-
parent = "projects/{}".format(project_id)
29+
parent = f"projects/{project_id}"
3030

3131
# Build analysis query
3232
analysis_query = asset_v1.IamPolicyAnalysisQuery()
@@ -55,7 +55,7 @@ def analyze_iam_policy_longrunning_bigquery(project_id, dataset, table):
5555
# TODO table = 'Your BigQuery table name'
5656

5757
client = asset_v1.AssetServiceClient()
58-
parent = "projects/{}".format(project_id)
58+
parent = f"projects/{project_id}"
5959

6060
# Build analysis query
6161
analysis_query = asset_v1.IamPolicyAnalysisQuery()

asset/snippets/quickstart_analyzeiampolicylongrunning_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import quickstart_analyzeiampolicylongrunning
2626

2727
PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"]
28-
BUCKET = "analysis-{}".format(int(uuid.uuid4()))
29-
DATASET = "analysis_{}".format(int(uuid.uuid4()))
28+
BUCKET = f"analysis-{int(uuid.uuid4())}"
29+
DATASET = f"analysis_{int(uuid.uuid4())}"
3030

3131

3232
@pytest.fixture(scope="module")
@@ -48,13 +48,13 @@ def analysis_bucket(storage_client):
4848
try:
4949
bucket.delete(force=True)
5050
except Exception as e:
51-
print("Failed to delete bucket{}".format(BUCKET))
51+
print(f"Failed to delete bucket{BUCKET}")
5252
raise e
5353

5454

5555
@pytest.fixture(scope="module")
5656
def dataset(bigquery_client):
57-
dataset_id = "{}.{}".format(PROJECT, DATASET)
57+
dataset_id = f"{PROJECT}.{DATASET}"
5858
dataset = bigquery.Dataset(dataset_id)
5959
dataset.location = "US"
6060
dataset = bigquery_client.create_dataset(dataset)
@@ -66,12 +66,12 @@ def dataset(bigquery_client):
6666

6767

6868
def test_analyze_iam_policy_longrunning(analysis_bucket, dataset, capsys):
69-
dump_file_path = "gs://{}/analysis-dump.txt".format(analysis_bucket)
69+
dump_file_path = f"gs://{analysis_bucket}/analysis-dump.txt"
7070
quickstart_analyzeiampolicylongrunning.analyze_iam_policy_longrunning_gcs(PROJECT, dump_file_path)
7171
out, _ = capsys.readouterr()
7272
assert "True" in out
7373

74-
dataset_id = "projects/{}/datasets/{}".format(PROJECT, dataset)
74+
dataset_id = f"projects/{PROJECT}/datasets/{dataset}"
7575
quickstart_analyzeiampolicylongrunning.analyze_iam_policy_longrunning_bigquery(PROJECT, dataset_id, "analysis_")
7676
out, _ = capsys.readouterr()
7777
assert "True" in out

asset/snippets/quickstart_batchgetassetshistory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def batch_get_assets_history(project_id, asset_names):
2727
# ["//storage.googleapis.com/[BUCKET_NAME]",]'
2828

2929
client = asset_v1.AssetServiceClient()
30-
parent = "projects/{}".format(project_id)
30+
parent = f"projects/{project_id}"
3131
content_type = asset_v1.ContentType.RESOURCE
3232
read_time_window = asset_v1.TimeWindow()
3333
response = client.batch_get_assets_history(
@@ -38,7 +38,7 @@ def batch_get_assets_history(project_id, asset_names):
3838
"read_time_window": read_time_window,
3939
}
4040
)
41-
print("assets: {}".format(response.assets))
41+
print(f"assets: {response.assets}")
4242
# [END asset_quickstart_batch_get_assets_history]
4343

4444

asset/snippets/quickstart_batchgetassetshistory_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import quickstart_batchgetassetshistory
2626

2727
PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"]
28-
BUCKET = "assets-{}".format(uuid.uuid4().hex)
28+
BUCKET = f"assets-{uuid.uuid4().hex}"
2929

3030

3131
@pytest.fixture(scope="module")
@@ -42,12 +42,12 @@ def asset_bucket(storage_client):
4242
try:
4343
bucket.delete(force=True)
4444
except Exception as e:
45-
print("Failed to delete bucket{}".format(BUCKET))
45+
print(f"Failed to delete bucket{BUCKET}")
4646
raise e
4747

4848

4949
def test_batch_get_assets_history(asset_bucket, capsys):
50-
bucket_asset_name = "//storage.googleapis.com/{}".format(BUCKET)
50+
bucket_asset_name = f"//storage.googleapis.com/{BUCKET}"
5151
asset_names = [
5252
bucket_asset_name,
5353
]

asset/snippets/quickstart_batchgeteffectiveiampolicy_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323

2424
def test_batch_get_effective_iam_policies(capsys):
25-
scope = "projects/{}".format(PROJECT)
25+
scope = f"projects/{PROJECT}"
2626
resource_names = [
27-
"//cloudresourcemanager.googleapis.com/projects/{}".format(PROJECT)]
27+
f"//cloudresourcemanager.googleapis.com/projects/{PROJECT}"]
2828
quickstart_batchgeteffectiveiampolicy.batch_get_effective_iam_policies(
2929
resource_names, scope)
3030
out, _ = capsys.readouterr()

asset/snippets/quickstart_createfeed.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ def create_feed(project_id, feed_id, asset_names, topic, content_type):
2929
# TODO content_type ="Content type of the feed"
3030

3131
client = asset_v1.AssetServiceClient()
32-
parent = "projects/{}".format(project_id)
32+
parent = f"projects/{project_id}"
3333
feed = asset_v1.Feed()
3434
feed.asset_names.extend(asset_names)
3535
feed.feed_output_config.pubsub_destination.topic = topic
3636
feed.content_type = content_type
3737
response = client.create_feed(
3838
request={"parent": parent, "feed_id": feed_id, "feed": feed}
3939
)
40-
print("feed: {}".format(response))
40+
print(f"feed: {response}")
4141
# [END asset_quickstart_create_feed]
4242
return response
4343

asset/snippets/quickstart_createfeed_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222

2323
PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"]
24-
ASSET_NAME = "assets-{}".format(uuid.uuid4().hex)
25-
FEED_ID = "feed-{}".format(uuid.uuid4().hex)
26-
FEED_ID_R = "feed-{}".format(uuid.uuid4().hex)
24+
ASSET_NAME = f"assets-{uuid.uuid4().hex}"
25+
FEED_ID = f"feed-{uuid.uuid4().hex}"
26+
FEED_ID_R = f"feed-{uuid.uuid4().hex}"
2727

2828

2929
def test_create_feed(capsys, test_topic, deleter):

asset/snippets/quickstart_exportassets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def export_assets(project_id, dump_file_path, content_type=None):
2626
# TODO dump_file_path = 'Your asset dump file path'
2727

2828
client = asset_v1.AssetServiceClient()
29-
parent = "projects/{}".format(project_id)
29+
parent = f"projects/{project_id}"
3030
output_config = asset_v1.OutputConfig()
3131
output_config.gcs_destination.uri = dump_file_path
3232
request_options = {
@@ -54,7 +54,7 @@ def export_assets_bigquery(project_id, dataset, table, content_type):
5454
# TODO content_type ="Content type to export"
5555

5656
client = asset_v1.AssetServiceClient()
57-
parent = "projects/{}".format(project_id)
57+
parent = f"projects/{project_id}"
5858
output_config = asset_v1.OutputConfig()
5959
output_config.bigquery_destination.dataset = dataset
6060
output_config.bigquery_destination.table = table

asset/snippets/quickstart_exportassets_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
import quickstart_exportassets
2626

2727
PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"]
28-
BUCKET = "assets-{}".format(uuid.uuid4().hex)
29-
DATASET = "assets_{}".format(int(uuid.uuid4()))
28+
BUCKET = f"assets-{uuid.uuid4().hex}"
29+
DATASET = f"assets_{int(uuid.uuid4())}"
3030

3131

3232
@pytest.fixture(scope="module")
@@ -48,13 +48,13 @@ def asset_bucket(storage_client):
4848
try:
4949
bucket.delete(force=True)
5050
except Exception as e:
51-
print("Failed to delete bucket{}".format(BUCKET))
51+
print(f"Failed to delete bucket{BUCKET}")
5252
raise e
5353

5454

5555
@pytest.fixture(scope='module')
5656
def dataset(bigquery_client):
57-
dataset_id = "{}.{}".format(PROJECT, DATASET)
57+
dataset_id = f"{PROJECT}.{DATASET}"
5858
dataset = bigquery.Dataset(dataset_id)
5959
dataset.location = "US"
6060
dataset = bigquery_client.create_dataset(dataset)
@@ -67,7 +67,7 @@ def dataset(bigquery_client):
6767

6868
def test_export_assets(asset_bucket, dataset, capsys):
6969
content_type = asset_v1.ContentType.IAM_POLICY
70-
dump_file_path = "gs://{}/assets-dump.txt".format(asset_bucket)
70+
dump_file_path = f"gs://{asset_bucket}/assets-dump.txt"
7171
quickstart_exportassets.export_assets(
7272
PROJECT,
7373
dump_file_path,
@@ -77,7 +77,7 @@ def test_export_assets(asset_bucket, dataset, capsys):
7777
assert dump_file_path in out
7878

7979
content_type = asset_v1.ContentType.RESOURCE
80-
dataset_id = "projects/{}/datasets/{}".format(PROJECT, dataset)
80+
dataset_id = f"projects/{PROJECT}/datasets/{dataset}"
8181
quickstart_exportassets.export_assets_bigquery(
8282
PROJECT, dataset_id, "assettable", content_type)
8383
out, _ = capsys.readouterr()

0 commit comments

Comments
 (0)