Content-Length: 448559 | pFad | http://github.com/richkadel/google-cloud-python/commit/04e6df37027a94357423bf031091fa71f1c2617c

21 Rename `document_from_url` to `document_from_gcs_url`. (#2986) · richkadel/google-cloud-python@04e6df3 · GitHub
Skip to content

Commit 04e6df3

Browse files
Rename document_from_url to document_from_gcs_url. (googleapis#2986)
This does a rename requested by the NL team.
1 parent cff7e8d commit 04e6df3

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

language/google/cloud/language/client.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
"""Basic client for Google Cloud Natural Language API."""
1616

17+
import functools
18+
import warnings
1719

1820
from google.cloud import client as client_module
1921
from google.cloud.language.connection import Connection
@@ -87,8 +89,8 @@ def document_from_html(self, content, **kwargs):
8789
return Document(self, content=content,
8890
doc_type=Document.HTML, **kwargs)
8991

90-
def document_from_url(self, gcs_url,
91-
doc_type=Document.PLAIN_TEXT, **kwargs):
92+
def document_from_gcs_url(self, gcs_url,
93+
doc_type=Document.PLAIN_TEXT, **kwargs):
9294
"""Create a Cloud Storage document bound to this client.
9395
9496
:type gcs_url: str
@@ -110,3 +112,13 @@ def document_from_url(self, gcs_url,
110112
:returns: A document bound to this client.
111113
"""
112114
return Document(self, gcs_url=gcs_url, doc_type=doc_type, **kwargs)
115+
116+
@functools.wraps(document_from_gcs_url)
117+
def document_from_url(self, *args, **kwargs):
118+
"""Deprecated equivalent to document_from_gcs_url.
119+
120+
DEPRECATED: 2017-02-06
121+
"""
122+
warnings.warn('The `document_from_url` method is deprecated; use '
123+
'`document_from_gcs_url` instead.', DeprecationWarning)
124+
return self.document_from_gcs_url(*args, **kwargs)

language/unit_tests/test_client.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414

1515
import unittest
1616

17+
import mock
18+
1719

1820
def make_mock_credentials():
19-
import mock
2021
from google.auth import credentials
2122

2223
credentials = mock.Mock(spec=credentials.Credentials)
@@ -92,21 +93,21 @@ def test_document_from_html_factory_failure(self):
9293
with self.assertRaises(TypeError):
9394
client.document_from_html('abc', doc_type='foo')
9495

95-
def test_document_from_url_factory(self):
96+
def test_document_from_gcs_url_factory(self):
9697
from google.cloud.language.document import Document
9798

9899
creds = make_mock_credentials()
99100
client = self._make_one(credentials=creds, http=object())
100101

101102
gcs_url = 'gs://my-text-bucket/sentiment-me.txt'
102-
document = client.document_from_url(gcs_url)
103+
document = client.document_from_gcs_url(gcs_url)
103104
self.assertIsInstance(document, Document)
104105
self.assertIs(document.client, client)
105106
self.assertIsNone(document.content)
106107
self.assertEqual(document.gcs_url, gcs_url)
107108
self.assertEqual(document.doc_type, Document.PLAIN_TEXT)
108109

109-
def test_document_from_url_factory_explicit(self):
110+
def test_document_from_gcs_url_factory_explicit(self):
110111
from google.cloud.language.document import Document
111112
from google.cloud.language.document import Encoding
112113

@@ -115,11 +116,31 @@ def test_document_from_url_factory_explicit(self):
115116

116117
encoding = Encoding.UTF32
117118
gcs_url = 'gs://my-text-bucket/sentiment-me.txt'
118-
document = client.document_from_url(gcs_url, doc_type=Document.HTML,
119-
encoding=encoding)
119+
document = client.document_from_gcs_url(gcs_url,
120+
doc_type=Document.HTML,
121+
encoding=encoding)
120122
self.assertIsInstance(document, Document)
121123
self.assertIs(document.client, client)
122124
self.assertIsNone(document.content)
123125
self.assertEqual(document.gcs_url, gcs_url)
124126
self.assertEqual(document.doc_type, Document.HTML)
125127
self.assertEqual(document.encoding, encoding)
128+
129+
def test_document_from_url_deprecation(self):
130+
import warnings
131+
132+
creds = make_mock_credentials()
133+
client = self._make_one(credentials=creds, http=object())
134+
135+
Client = self._get_target_class()
136+
with mock.patch.object(Client, 'document_from_gcs_url') as dfgu:
137+
with mock.patch.object(warnings, 'warn') as warn:
138+
client.document_from_url(gcs_url='gs://bogus')
139+
140+
# Establish that the warning happened and sent a
141+
# DeprecationWarning.
142+
self.assertEqual(warn.call_count, 1)
143+
self.assertEqual(warn.mock_calls[0][1][1], DeprecationWarning)
144+
145+
# Establish that the new (renamed) method is called.
146+
dfgu.assert_called_once_with(gcs_url='gs://bogus')

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/richkadel/google-cloud-python/commit/04e6df37027a94357423bf031091fa71f1c2617c

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy