| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ envlist = | |||
| 5 | 5 | [testing] | |
| 6 | 6 | deps = | |
| 7 | 7 | {toxinidir}/../core | |
| 8 | + mock | ||
| 8 | 9 | pytest | |
| 9 | 10 | covercmd = | |
| 10 | 11 | py.test --quiet \ | |
@@ -25,6 +26,6 @@ basepython = | |||
| 25 | 26 | commands = | |
| 26 | 27 | {[testing]covercmd} | |
| 27 | 28 | deps = | |
| 28 | - {[testenv]deps} | ||
| 29 | + {[testing]deps} | ||
| 29 | 30 | coverage | |
| 30 | 31 | pytest-cov | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,28 +17,33 @@ | |||
| 17 | 17 | ||
| 18 | 18 | class TestClient(unittest.TestCase): | |
| 19 | 19 | ||
| 20 | - def _getTargetClass(self): | ||
| 20 | + @staticmethod | ||
| 21 | + def _get_target_class(): | ||
| 21 | 22 | from google.cloud.language.client import Client | |
| 22 | 23 | return Client | |
| 23 | 24 | ||
| 24 | - def _makeOne(self, *args, **kw): | ||
| 25 | - return self._getTargetClass()(*args, **kw) | ||
| 25 | + def _make_one(self, *args, **kw): | ||
| 26 | + return self._get_target_class()(*args, **kw) | ||
| 26 | 27 | ||
| 27 | 28 | def test_ctor(self): | |
| 29 | + import mock | ||
| 28 | 30 | from google.cloud.language.connection import Connection | |
| 29 | 31 | ||
| 30 | - creds = _Credentials() | ||
| 32 | + creds = mock.Mock() | ||
| 33 | + creds.create_scoped_required.return_value = False | ||
| 31 | 34 | http = object() | |
| 32 | - client = self._makeOne(credentials=creds, http=http) | ||
| 35 | + client = self._make_one(credentials=creds, http=http) | ||
| 33 | 36 | self.assertIsInstance(client.connection, Connection) | |
| 34 | 37 | self.assertIs(client.connection.credentials, creds) | |
| 35 | 38 | self.assertIs(client.connection.http, http) | |
| 36 | 39 | ||
| 37 | 40 | def test_document_from_text_factory(self): | |
| 41 | + import mock | ||
| 38 | 42 | from google.cloud.language.document import Document | |
| 39 | 43 | ||
| 40 | - creds = _Credentials() | ||
| 41 | - client = self._makeOne(credentials=creds, http=object()) | ||
| 44 | + creds = mock.Mock() | ||
| 45 | + creds.create_scoped_required.return_value = False | ||
| 46 | + client = self._make_one(credentials=creds, http=object()) | ||
| 42 | 47 | ||
| 43 | 48 | content = 'abc' | |
| 44 | 49 | language = 'es' | |
@@ -52,17 +57,22 @@ def test_document_from_text_factory(self): | |||
| 52 | 57 | self.assertEqual(document.language, language) | |
| 53 | 58 | ||
| 54 | 59 | def test_document_from_text_factory_failure(self): | |
| 55 | - creds = _Credentials() | ||
| 56 | - client = self._makeOne(credentials=creds, http=object()) | ||
| 60 | + import mock | ||
| 61 | + | ||
| 62 | + creds = mock.Mock() | ||
| 63 | + creds.create_scoped_required.return_value = False | ||
| 64 | + client = self._make_one(credentials=creds, http=object()) | ||
| 57 | 65 | ||
| 58 | 66 | with self.assertRaises(TypeError): | |
| 59 | 67 | client.document_from_text('abc', doc_type='foo') | |
| 60 | 68 | ||
| 61 | 69 | def test_document_from_html_factory(self): | |
| 70 | + import mock | ||
| 62 | 71 | from google.cloud.language.document import Document | |
| 63 | 72 | ||
| 64 | - creds = _Credentials() | ||
| 65 | - client = self._makeOne(credentials=creds, http=object()) | ||
| 73 | + creds = mock.Mock() | ||
| 74 | + creds.create_scoped_required.return_value = False | ||
| 75 | + client = self._make_one(credentials=creds, http=object()) | ||
| 66 | 76 | ||
| 67 | 77 | content = '<html>abc</html>' | |
| 68 | 78 | language = 'ja' | |
@@ -76,17 +86,22 @@ def test_document_from_html_factory(self): | |||
| 76 | 86 | self.assertEqual(document.language, language) | |
| 77 | 87 | ||
| 78 | 88 | def test_document_from_html_factory_failure(self): | |
| 79 | - creds = _Credentials() | ||
| 80 | - client = self._makeOne(credentials=creds, http=object()) | ||
| 89 | + import mock | ||
| 90 | + | ||
| 91 | + creds = mock.Mock() | ||
| 92 | + creds.create_scoped_required.return_value = False | ||
| 93 | + client = self._make_one(credentials=creds, http=object()) | ||
| 81 | 94 | ||
| 82 | 95 | with self.assertRaises(TypeError): | |
| 83 | 96 | client.document_from_html('abc', doc_type='foo') | |
| 84 | 97 | ||
| 85 | 98 | def test_document_from_url_factory(self): | |
| 99 | + import mock | ||
| 86 | 100 | from google.cloud.language.document import Document | |
| 87 | 101 | ||
| 88 | - creds = _Credentials() | ||
| 89 | - client = self._makeOne(credentials=creds, http=object()) | ||
| 102 | + creds = mock.Mock() | ||
| 103 | + creds.create_scoped_required.return_value = False | ||
| 104 | + client = self._make_one(credentials=creds, http=object()) | ||
| 90 | 105 | ||
| 91 | 106 | gcs_url = 'gs://my-text-bucket/sentiment-me.txt' | |
| 92 | 107 | document = client.document_from_url(gcs_url) | |
@@ -97,11 +112,13 @@ def test_document_from_url_factory(self): | |||
| 97 | 112 | self.assertEqual(document.doc_type, Document.PLAIN_TEXT) | |
| 98 | 113 | ||
| 99 | 114 | def test_document_from_url_factory_explicit(self): | |
| 115 | + import mock | ||
| 100 | 116 | from google.cloud.language.document import Document | |
| 101 | 117 | from google.cloud.language.document import Encoding | |
| 102 | 118 | ||
| 103 | - creds = _Credentials() | ||
| 104 | - client = self._makeOne(credentials=creds, http=object()) | ||
| 119 | + creds = mock.Mock() | ||
| 120 | + creds.create_scoped_required.return_value = False | ||
| 121 | + client = self._make_one(credentials=creds, http=object()) | ||
| 105 | 122 | ||
| 106 | 123 | encoding = Encoding.UTF32 | |
| 107 | 124 | gcs_url = 'gs://my-text-bucket/sentiment-me.txt' | |
@@ -113,16 +130,3 @@ def test_document_from_url_factory_explicit(self): | |||
| 113 | 130 | self.assertEqual(document.gcs_url, gcs_url) | |
| 114 | 131 | self.assertEqual(document.doc_type, Document.HTML) | |
| 115 | 132 | self.assertEqual(document.encoding, encoding) | |
| 116 | - | ||
| 117 | - | ||
| 118 | - class _Credentials(object): | ||
| 119 | - | ||
| 120 | - _scopes = None | ||
| 121 | - | ||
| 122 | - @staticmethod | ||
| 123 | - def create_scoped_required(): | ||
| 124 | - return True | ||
| 125 | - | ||
| 126 | - def create_scoped(self, scope): | ||
| 127 | - self._scopes = scope | ||
| 128 | - return self | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,15 +17,15 @@ | |||
| 17 | 17 | ||
| 18 | 18 | class TestConnection(unittest.TestCase): | |
| 19 | 19 | ||
| 20 | - def _getTargetClass(self): | ||
| 20 | + def _get_target_class(self): | ||
| 21 | 21 | from google.cloud.language.connection import Connection | |
| 22 | 22 | return Connection | |
| 23 | 23 | ||
| 24 | - def _makeOne(self, *args, **kw): | ||
| 25 | - return self._getTargetClass()(*args, **kw) | ||
| 24 | + def _make_one(self, *args, **kw): | ||
| 25 | + return self._get_target_class()(*args, **kw) | ||
| 26 | 26 | ||
| 27 | 27 | def test_build_api_url(self): | |
| 28 | - conn = self._makeOne() | ||
| 28 | + conn = self._make_one() | ||
| 29 | 29 | uri = '/'.join([ | |
| 30 | 30 | conn.API_BASE_URL, | |
| 31 | 31 | conn.API_VERSION, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments