Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage: Add 'stacklevel=2' to deprecation warnings. #5897

Merged
merged 1 commit into from
Sep 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion storage/google/cloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,8 @@ def upload_from_file(self, file_obj, rewind=False, size=None,
.. _lifecycle: https://cloud.google.com/storage/docs/lifecycle
"""
if num_retries is not None:
warnings.warn(_NUM_RETRIES_MESSAGE, DeprecationWarning)
warnings.warn(
_NUM_RETRIES_MESSAGE, DeprecationWarning, stacklevel=2)

_maybe_rewind(file_obj, rewind=rewind)
predefined_acl = ACL.validate_predefined(predefined_acl)
Expand Down
11 changes: 7 additions & 4 deletions storage/google/cloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
from google.cloud.storage.notification import NONE_PAYLOAD_FORMAT


_LOCATION_SETTER_MESSAGE = (
"Assignment to 'Bucket.location' is deprecated, as it is only "
"valid before the bucket is created. Instead, pass the location "
"to `Bucket.create`.")


def _blobs_page_start(iterator, page, response):
"""Grab prefixes after a :class:`~google.cloud.iterator.Page` started.

Expand Down Expand Up @@ -976,10 +982,7 @@ def location(self, value):
to `Bucket.create`.
"""
warnings.warn(
"Assignment to 'Bucket.location' is deprecated, as it is only "
"valid before the bucket is created. Instead, pass the location "
"to `Bucket.create`.",
DeprecationWarning)
_LOCATION_SETTER_MESSAGE, DeprecationWarning, stacklevel=2)
self._location = value

def get_logging(self):
Expand Down
4 changes: 3 additions & 1 deletion storage/tests/unit/test_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -1654,7 +1654,9 @@ def test_upload_from_file_with_retries(self, mock_warn):

self._upload_from_file_helper(num_retries=20)
mock_warn.assert_called_once_with(
blob_module._NUM_RETRIES_MESSAGE, DeprecationWarning)
blob_module._NUM_RETRIES_MESSAGE,
DeprecationWarning,
stacklevel=2)

def test_upload_from_file_with_rewind(self):
stream = self._upload_from_file_helper(rewind=True)
Expand Down
12 changes: 9 additions & 3 deletions storage/tests/unit/test_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,11 @@ def test_create_w_extra_properties(self):
bucket = self._make_one(client=client, name=BUCKET_NAME)
bucket.cors = CORS
bucket.lifecycle_rules = LIFECYCLE_RULES
bucket.location = LOCATION
bucket.storage_class = STORAGE_CLASS
bucket.versioning_enabled = True
bucket.requester_pays = True
bucket.labels = LABELS
bucket.create()
bucket.create(location=LOCATION)

kw, = connection._requested
self.assertEqual(kw['method'], 'POST')
Expand Down Expand Up @@ -920,13 +919,20 @@ def test_location_getter(self):
bucket = self._make_one(name=NAME, properties=before)
self.assertEqual(bucket.location, 'AS')

def test_location_setter(self):
@mock.patch('warnings.warn')
def test_location_setter(self, mock_warn):
from google.cloud.storage import bucket as bucket_module

NAME = 'name'
bucket = self._make_one(name=NAME)
self.assertIsNone(bucket.location)
bucket.location = 'AS'
self.assertEqual(bucket.location, 'AS')
self.assertTrue('location' in bucket._changes)
mock_warn.assert_called_once_with(
bucket_module._LOCATION_SETTER_MESSAGE,
DeprecationWarning,
stacklevel=2)

def test_lifecycle_rules_getter(self):
NAME = 'name'
Expand Down