From d0a3a7e1b2f1a900222128bb4cb8067dfb2a6d50 Mon Sep 17 00:00:00 2001 From: Christopher Wilcox Date: Fri, 30 Nov 2018 15:56:13 -0800 Subject: [PATCH] add blacken to noxfile (#6795) --- dns/noxfile.py | 60 +++-- resource_manager/google/__init__.py | 2 + resource_manager/google/cloud/__init__.py | 2 + .../google/cloud/resource_manager/__init__.py | 5 +- .../google/cloud/resource_manager/_http.py | 10 +- .../google/cloud/resource_manager/client.py | 21 +- .../google/cloud/resource_manager/project.py | 52 ++-- resource_manager/noxfile.py | 60 +++-- resource_manager/tests/unit/test__http.py | 38 +-- resource_manager/tests/unit/test_client.py | 153 ++++++----- resource_manager/tests/unit/test_project.py | 244 +++++++----------- runtimeconfig/noxfile.py | 59 +++-- translate/noxfile.py | 58 +++-- 13 files changed, 386 insertions(+), 378 deletions(-) diff --git a/dns/noxfile.py b/dns/noxfile.py index 8ea0316d29db..4b57692922fc 100644 --- a/dns/noxfile.py +++ b/dns/noxfile.py @@ -25,6 +25,45 @@ ) +@nox.session(python="3.7") +def lint(session): + """Run linters. + Returns a failure if the linters find linting errors or sufficiently + serious code quality issues. + """ + session.install("flake8", "black", *LOCAL_DEPS) + session.run( + "black", + "--check", + "google", + "tests", + "docs", + ) + session.run("flake8", "google", "tests") + + +@nox.session(python="3.6") +def blacken(session): + """Run black. + Format code to uniform standard. + """ + session.install("black") + session.run( + "black", + "google", + "tests", + "docs", + ) + + +@nox.session(python='3.6') +def lint_setup_py(session): + """Verify that setup.py is valid (including RST check).""" + session.install('docutils', 'Pygments') + session.run( + 'python', 'setup.py', 'check', '--restructuredtext', '--strict') + + def default(session): """Default unit test session. @@ -60,27 +99,6 @@ def unit(session): default(session) -@nox.session(python='3.6') -def lint(session): - """Run linters. - - Returns a failure if the linters find linting errors or sufficiently - serious code quality issues. - """ - session.install('flake8', *LOCAL_DEPS) - session.install('.') - session.run('flake8', 'google', 'tests') - - -@nox.session(python='3.6') -def lint_setup_py(session): - """Verify that setup.py is valid (including RST check).""" - - session.install('docutils', 'Pygments') - session.run( - 'python', 'setup.py', 'check', '--restructuredtext', '--strict') - - @nox.session(python='3.6') def cover(session): """Run the final coverage report. diff --git a/resource_manager/google/__init__.py b/resource_manager/google/__init__.py index 9ee9bf4342ab..0e1bc5131ba6 100644 --- a/resource_manager/google/__init__.py +++ b/resource_manager/google/__init__.py @@ -14,7 +14,9 @@ try: import pkg_resources + pkg_resources.declare_namespace(__name__) except ImportError: import pkgutil + __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/resource_manager/google/cloud/__init__.py b/resource_manager/google/cloud/__init__.py index 9ee9bf4342ab..0e1bc5131ba6 100644 --- a/resource_manager/google/cloud/__init__.py +++ b/resource_manager/google/cloud/__init__.py @@ -14,7 +14,9 @@ try: import pkg_resources + pkg_resources.declare_namespace(__name__) except ImportError: import pkgutil + __path__ = pkgutil.extend_path(__path__, __name__) diff --git a/resource_manager/google/cloud/resource_manager/__init__.py b/resource_manager/google/cloud/resource_manager/__init__.py index e8ac30951b14..bf71be7546f9 100644 --- a/resource_manager/google/cloud/resource_manager/__init__.py +++ b/resource_manager/google/cloud/resource_manager/__init__.py @@ -16,7 +16,8 @@ from pkg_resources import get_distribution -__version__ = get_distribution('google-cloud-resource-manager').version + +__version__ = get_distribution("google-cloud-resource-manager").version from google.cloud.resource_manager.client import Client from google.cloud.resource_manager.project import Project @@ -24,4 +25,4 @@ SCOPE = Client.SCOPE -__all__ = ['__version__', 'Client', 'Project', 'SCOPE'] +__all__ = ["__version__", "Client", "Project", "SCOPE"] diff --git a/resource_manager/google/cloud/resource_manager/_http.py b/resource_manager/google/cloud/resource_manager/_http.py index 17e578108301..d0118c810385 100644 --- a/resource_manager/google/cloud/resource_manager/_http.py +++ b/resource_manager/google/cloud/resource_manager/_http.py @@ -30,15 +30,13 @@ class Connection(_http.JSONConnection): :param client: The client that owns the current connection. """ - API_BASE_URL = 'https://cloudresourcemanager.googleapis.com' + API_BASE_URL = "https://cloudresourcemanager.googleapis.com" """The base of the API call URL.""" - API_VERSION = 'v1beta1' + API_VERSION = "v1beta1" """The version of the API, used in building the API call's URL.""" - API_URL_TEMPLATE = '{api_base_url}/{api_version}{path}' + API_URL_TEMPLATE = "{api_base_url}/{api_version}{path}" """A template for the URL of a particular API call.""" - _EXTRA_HEADERS = { - _http.CLIENT_INFO_HEADER: _CLIENT_INFO, - } + _EXTRA_HEADERS = {_http.CLIENT_INFO_HEADER: _CLIENT_INFO} diff --git a/resource_manager/google/cloud/resource_manager/client.py b/resource_manager/google/cloud/resource_manager/client.py index 4dec6a24ef56..39c252c0ea17 100644 --- a/resource_manager/google/cloud/resource_manager/client.py +++ b/resource_manager/google/cloud/resource_manager/client.py @@ -51,12 +51,11 @@ class Client(BaseClient): change in the future. """ - SCOPE = ('https://www.googleapis.com/auth/cloud-platform',) + SCOPE = ("https://www.googleapis.com/auth/cloud-platform",) """The scopes required for authenticating as a Resouce Manager consumer.""" def __init__(self, credentials=None, _http=None): - super(Client, self).__init__( - credentials=credentials, _http=_http) + super(Client, self).__init__(credentials=credentials, _http=_http) self._connection = Connection(self) def new_project(self, project_id, name=None, labels=None): @@ -85,8 +84,7 @@ def new_project(self, project_id, name=None, labels=None): :class:`~google.cloud.resource_manager.project.Project` **without** any metadata loaded. """ - return Project(project_id=project_id, - client=self, name=name, labels=labels) + return Project(project_id=project_id, client=self, name=name, labels=labels) def fetch_project(self, project_id): """Fetch an existing project and it's relevant metadata by ID. @@ -160,21 +158,22 @@ def list_projects(self, filter_params=None, page_size=None): extra_params = {} if page_size is not None: - extra_params['pageSize'] = page_size + extra_params["pageSize"] = page_size if filter_params is not None: - extra_params['filter'] = [ - '{}:{}'.format(key, value) + extra_params["filter"] = [ + "{}:{}".format(key, value) for key, value in six.iteritems(filter_params) ] return page_iterator.HTTPIterator( client=self, api_request=self._connection.api_request, - path='/projects', + path="/projects", item_to_value=_item_to_project, - items_key='projects', - extra_params=extra_params) + items_key="projects", + extra_params=extra_params, + ) def _item_to_project(iterator, resource): diff --git a/resource_manager/google/cloud/resource_manager/project.py b/resource_manager/google/cloud/resource_manager/project.py index 649c4a88edd4..cf499fa286b1 100644 --- a/resource_manager/google/cloud/resource_manager/project.py +++ b/resource_manager/google/cloud/resource_manager/project.py @@ -51,6 +51,7 @@ class Project(object): :type labels: dict :param labels: A list of labels associated with the project. """ + def __init__(self, project_id, client, name=None, labels=None): self._client = client self.project_id = project_id @@ -61,7 +62,7 @@ def __init__(self, project_id, client, name=None, labels=None): self.parent = None def __repr__(self): - return '' % (self.name, self.project_id) + return "" % (self.name, self.project_id) @classmethod def from_api_repr(cls, resource, client): @@ -76,30 +77,30 @@ def from_api_repr(cls, resource, client): :rtype: :class:`google.cloud.resource_manager.project.Project` :returns: The project created. """ - project = cls(project_id=resource['projectId'], client=client) + project = cls(project_id=resource["projectId"], client=client) project.set_properties_from_api_repr(resource) return project def set_properties_from_api_repr(self, resource): """Update specific properties from its API representation.""" - self.name = resource.get('name') - self.number = resource['projectNumber'] - self.labels = resource.get('labels', {}) - self.status = resource['lifecycleState'] - if 'parent' in resource: - self.parent = resource['parent'] + self.name = resource.get("name") + self.number = resource["projectNumber"] + self.labels = resource.get("labels", {}) + self.status = resource["lifecycleState"] + if "parent" in resource: + self.parent = resource["parent"] @property def full_name(self): """Fully-qualified name (ie, ``'projects/purple-spaceship-123'``).""" if not self.project_id: - raise ValueError('Missing project ID.') - return 'projects/%s' % (self.project_id) + raise ValueError("Missing project ID.") + return "projects/%s" % (self.project_id) @property def path(self): """URL for the project (ie, ``'/projects/purple-spaceship-123'``).""" - return '/%s' % (self.full_name) + return "/%s" % (self.full_name) def _require_client(self, client): """Check client or verify over-ride. @@ -129,13 +130,10 @@ def create(self, client=None): """ client = self._require_client(client) - data = { - 'projectId': self.project_id, - 'name': self.name, - 'labels': self.labels, - } - resp = client._connection.api_request(method='POST', path='/projects', - data=data) + data = {"projectId": self.project_id, "name": self.name, "labels": self.labels} + resp = client._connection.api_request( + method="POST", path="/projects", data=data + ) self.set_properties_from_api_repr(resource=resp) def reload(self, client=None): @@ -164,7 +162,7 @@ def reload(self, client=None): # We assume the project exists. If it doesn't it will raise a NotFound # exception. - resp = client._connection.api_request(method='GET', path=self.path) + resp = client._connection.api_request(method="GET", path=self.path) self.set_properties_from_api_repr(resource=resp) def exists(self, client=None): @@ -186,7 +184,7 @@ def exists(self, client=None): try: # Note that we have to request the entire resource as the API # doesn't provide a way tocheck for existence only. - client._connection.api_request(method='GET', path=self.path) + client._connection.api_request(method="GET", path=self.path) except NotFound: return False else: @@ -205,14 +203,9 @@ def update(self, client=None): """ client = self._require_client(client) - data = { - 'name': self.name, - 'labels': self.labels, - 'parent': self.parent, - } + data = {"name": self.name, "labels": self.labels, "parent": self.parent} - resp = client._connection.api_request( - method='PUT', path=self.path, data=data) + resp = client._connection.api_request(method="PUT", path=self.path, data=data) self.set_properties_from_api_repr(resp) def delete(self, client=None, reload_data=False): @@ -240,7 +233,7 @@ def delete(self, client=None, reload_data=False): Default: :data:`False`. """ client = self._require_client(client) - client._connection.api_request(method='DELETE', path=self.path) + client._connection.api_request(method="DELETE", path=self.path) # If the reload flag is set, reload the project. if reload_data: @@ -270,8 +263,7 @@ def undelete(self, client=None, reload_data=False): Default: :data:`False`. """ client = self._require_client(client) - client._connection.api_request( - method='POST', path=self.path + ':undelete') + client._connection.api_request(method="POST", path=self.path + ":undelete") # If the reload flag is set, reload the project. if reload_data: diff --git a/resource_manager/noxfile.py b/resource_manager/noxfile.py index 35bc9ad5805f..443521302f02 100644 --- a/resource_manager/noxfile.py +++ b/resource_manager/noxfile.py @@ -25,6 +25,45 @@ ) +@nox.session(python="3.7") +def lint(session): + """Run linters. + Returns a failure if the linters find linting errors or sufficiently + serious code quality issues. + """ + session.install("flake8", "black", *LOCAL_DEPS) + session.run( + "black", + "--check", + "google", + "tests", + "docs", + ) + session.run("flake8", "google", "tests") + + +@nox.session(python="3.6") +def blacken(session): + """Run black. + Format code to uniform standard. + """ + session.install("black") + session.run( + "black", + "google", + "tests", + "docs", + ) + + +@nox.session(python='3.6') +def lint_setup_py(session): + """Verify that setup.py is valid (including RST check).""" + session.install('docutils', 'Pygments') + session.run( + 'python', 'setup.py', 'check', '--restructuredtext', '--strict') + + def default(session): """Default unit test session. @@ -58,27 +97,6 @@ def unit(session): default(session) -@nox.session(python='3.6') -def lint(session): - """Run linters. - - Returns a failure if the linters find linting errors or sufficiently - serious code quality issues. - """ - session.install('flake8', *LOCAL_DEPS) - session.install('.') - session.run('flake8', 'google', 'tests') - - -@nox.session(python='3.6') -def lint_setup_py(session): - """Verify that setup.py is valid (including RST check).""" - - session.install('docutils', 'Pygments') - session.run( - 'python', 'setup.py', 'check', '--restructuredtext', '--strict') - - @nox.session(python='3.6') def cover(session): """Run the final coverage report. diff --git a/resource_manager/tests/unit/test__http.py b/resource_manager/tests/unit/test__http.py index 13d13049799d..77be1a34ee87 100644 --- a/resource_manager/tests/unit/test__http.py +++ b/resource_manager/tests/unit/test__http.py @@ -18,7 +18,6 @@ class TestConnection(unittest.TestCase): - @staticmethod def _get_target_class(): from google.cloud.resource_manager._http import Connection @@ -30,25 +29,20 @@ def _make_one(self, *args, **kw): def test_build_api_url_no_extra_query_params(self): conn = self._make_one(object()) - URI = '/'.join([ - conn.API_BASE_URL, - conn.API_VERSION, - 'foo', - ]) - self.assertEqual(conn.build_api_url('/foo'), URI) + URI = "/".join([conn.API_BASE_URL, conn.API_VERSION, "foo"]) + self.assertEqual(conn.build_api_url("/foo"), URI) def test_build_api_url_w_extra_query_params(self): from six.moves.urllib.parse import parse_qsl from six.moves.urllib.parse import urlsplit conn = self._make_one(object()) - uri = conn.build_api_url('/foo', {'bar': 'baz'}) + uri = conn.build_api_url("/foo", {"bar": "baz"}) scheme, netloc, path, qs, _ = urlsplit(uri) - self.assertEqual('%s://%s' % (scheme, netloc), conn.API_BASE_URL) - self.assertEqual(path, - '/'.join(['', conn.API_VERSION, 'foo'])) + self.assertEqual("%s://%s" % (scheme, netloc), conn.API_BASE_URL) + self.assertEqual(path, "/".join(["", conn.API_VERSION, "foo"])) parms = dict(parse_qsl(qs)) - self.assertEqual(parms['bar'], 'baz') + self.assertEqual(parms["bar"], "baz") def test_extra_headers(self): import requests @@ -59,26 +53,22 @@ def test_extra_headers(self): http = mock.create_autospec(requests.Session, instance=True) response = requests.Response() response.status_code = 200 - data = b'brent-spiner' + data = b"brent-spiner" response._content = data http.request.return_value = response - client = mock.Mock(_http=http, spec=['_http']) + client = mock.Mock(_http=http, spec=["_http"]) conn = self._make_one(client) - req_data = 'req-data-boring' - result = conn.api_request( - 'GET', '/rainbow', data=req_data, expect_json=False) + req_data = "req-data-boring" + result = conn.api_request("GET", "/rainbow", data=req_data, expect_json=False) self.assertEqual(result, data) expected_headers = { - 'Accept-Encoding': 'gzip', + "Accept-Encoding": "gzip", base_http.CLIENT_INFO_HEADER: MUT._CLIENT_INFO, - 'User-Agent': conn.USER_AGENT, + "User-Agent": conn.USER_AGENT, } - expected_uri = conn.build_api_url('/rainbow') + expected_uri = conn.build_api_url("/rainbow") http.request.assert_called_once_with( - data=req_data, - headers=expected_headers, - method='GET', - url=expected_uri, + data=req_data, headers=expected_headers, method="GET", url=expected_uri ) diff --git a/resource_manager/tests/unit/test_client.py b/resource_manager/tests/unit/test_client.py index 4731a24a57fe..d0223649ed59 100644 --- a/resource_manager/tests/unit/test_client.py +++ b/resource_manager/tests/unit/test_client.py @@ -24,7 +24,6 @@ def _make_credentials(): class TestClient(unittest.TestCase): - @staticmethod def _get_target_class(): from google.cloud.resource_manager.client import Client @@ -49,7 +48,7 @@ def test_new_project_factory(self): credentials = _make_credentials() client = self._make_one(credentials=credentials) - project_id = 'project_id' + project_id = "project_id" name = object() labels = object() project = client.new_project(project_id, name=name, labels=labels) @@ -63,16 +62,16 @@ def test_new_project_factory(self): def test_fetch_project(self): from google.cloud.resource_manager.project import Project - project_id = 'project-id' + project_id = "project-id" project_number = 123 - project_name = 'Project Name' - labels = {'env': 'prod'} + project_name = "Project Name" + labels = {"env": "prod"} project_resource = { - 'projectId': project_id, - 'projectNumber': project_number, - 'name': project_name, - 'labels': labels, - 'lifecycleState': 'ACTIVE', + "projectId": project_id, + "projectNumber": project_number, + "name": project_name, + "labels": labels, + "lifecycleState": "ACTIVE", } credentials = _make_credentials() @@ -102,22 +101,22 @@ def test_list_projects_no_paging(self): credentials = _make_credentials() client = self._make_one(credentials=credentials) - PROJECT_ID = 'project-id' + PROJECT_ID = "project-id" PROJECT_NUMBER = 1 - STATUS = 'ACTIVE' + STATUS = "ACTIVE" PROJECTS_RESOURCE = { - 'projects': [ + "projects": [ { - 'projectId': PROJECT_ID, - 'projectNumber': PROJECT_NUMBER, - 'lifecycleState': STATUS, - }, - ], + "projectId": PROJECT_ID, + "projectNumber": PROJECT_NUMBER, + "lifecycleState": STATUS, + } + ] } # Patch the connection with one we can easily control. client._connection = _Connection(PROJECTS_RESOURCE) # Make sure there will be no paging. - self.assertFalse('nextPageToken' in PROJECTS_RESOURCE) + self.assertFalse("nextPageToken" in PROJECTS_RESOURCE) results = list(client.list_projects()) @@ -130,34 +129,35 @@ def test_list_projects_with_paging(self): credentials = _make_credentials() client = self._make_one(credentials=credentials) - PROJECT_ID1 = 'project-id' + PROJECT_ID1 = "project-id" PROJECT_NUMBER1 = 1 - STATUS = 'ACTIVE' - TOKEN = 'next-page-token' + STATUS = "ACTIVE" + TOKEN = "next-page-token" FIRST_PROJECTS_RESOURCE = { - 'projects': [ + "projects": [ { - 'projectId': PROJECT_ID1, - 'projectNumber': PROJECT_NUMBER1, - 'lifecycleState': STATUS, - }, + "projectId": PROJECT_ID1, + "projectNumber": PROJECT_NUMBER1, + "lifecycleState": STATUS, + } ], - 'nextPageToken': TOKEN, + "nextPageToken": TOKEN, } - PROJECT_ID2 = 'project-id-2' + PROJECT_ID2 = "project-id-2" PROJECT_NUMBER2 = 42 SECOND_PROJECTS_RESOURCE = { - 'projects': [ + "projects": [ { - 'projectId': PROJECT_ID2, - 'projectNumber': PROJECT_NUMBER2, - 'lifecycleState': STATUS, - }, - ], + "projectId": PROJECT_ID2, + "projectNumber": PROJECT_NUMBER2, + "lifecycleState": STATUS, + } + ] } # Patch the connection with one we can easily control. - client._connection = _Connection(FIRST_PROJECTS_RESOURCE, - SECOND_PROJECTS_RESOURCE) + client._connection = _Connection( + FIRST_PROJECTS_RESOURCE, SECOND_PROJECTS_RESOURCE + ) # Page size = 1 with two response means we'll have two requests. results = list(client.list_projects(page_size=1)) @@ -173,42 +173,39 @@ def test_list_projects_with_paging(self): # Check that two requests were required since page_size=1. request1, request2 = client._connection._requested - self.assertEqual(request1, { - 'path': '/projects', - 'method': 'GET', - 'query_params': { - 'pageSize': 1, + self.assertEqual( + request1, + {"path": "/projects", "method": "GET", "query_params": {"pageSize": 1}}, + ) + self.assertEqual( + request2, + { + "path": "/projects", + "method": "GET", + "query_params": {"pageSize": 1, "pageToken": TOKEN}, }, - }) - self.assertEqual(request2, { - 'path': '/projects', - 'method': 'GET', - 'query_params': { - 'pageSize': 1, - 'pageToken': TOKEN, - }, - }) + ) def test_list_projects_with_filter(self): credentials = _make_credentials() client = self._make_one(credentials=credentials) - PROJECT_ID = 'project-id' + PROJECT_ID = "project-id" PROJECT_NUMBER = 1 - STATUS = 'ACTIVE' + STATUS = "ACTIVE" PROJECTS_RESOURCE = { - 'projects': [ + "projects": [ { - 'projectId': PROJECT_ID, - 'projectNumber': PROJECT_NUMBER, - 'lifecycleState': STATUS, - }, - ], + "projectId": PROJECT_ID, + "projectNumber": PROJECT_NUMBER, + "lifecycleState": STATUS, + } + ] } # Patch the connection with one we can easily control. client._connection = _Connection(PROJECTS_RESOURCE) - FILTER_PARAMS = {'id': 'project-id'} + FILTER_PARAMS = {"id": "project-id"} results = list(client.list_projects(filter_params=FILTER_PARAMS)) project, = results @@ -217,15 +214,16 @@ def test_list_projects_with_filter(self): self.assertEqual(project.status, STATUS) # Check that the filter made it in the request. - FLATTENED_FILTER_PARAMS = ['id:project-id'] + FLATTENED_FILTER_PARAMS = ["id:project-id"] request, = client._connection._requested - self.assertEqual(request, { - 'path': '/projects', - 'method': 'GET', - 'query_params': { - 'filter': FLATTENED_FILTER_PARAMS, + self.assertEqual( + request, + { + "path": "/projects", + "method": "GET", + "query_params": {"filter": FLATTENED_FILTER_PARAMS}, }, - }) + ) def test_page_empty_response(self): from google.api_core import page_iterator @@ -243,19 +241,19 @@ def test_page_non_empty_response(self): import six from google.cloud.resource_manager.project import Project - project_id = 'project-id' - project_name = 'My Project Name' + project_id = "project-id" + project_name = "My Project Name" project_number = 12345678 - project_labels = {'env': 'prod'} - project_lifecycle_state = 'ACTIVE' + project_labels = {"env": "prod"} + project_lifecycle_state = "ACTIVE" api_resource = { - 'projectId': project_id, - 'name': project_name, - 'projectNumber': project_number, - 'labels': project_labels, - 'lifecycleState': project_lifecycle_state, + "projectId": project_id, + "name": project_name, + "projectNumber": project_number, + "labels": project_labels, + "lifecycleState": project_lifecycle_state, } - response = {'projects': [api_resource]} + response = {"projects": [api_resource]} credentials = _make_credentials() client = self._make_one(credentials=credentials) @@ -279,7 +277,6 @@ def dummy_response(): class _Connection(object): - def __init__(self, *responses): self._responses = responses self._requested = [] diff --git a/resource_manager/tests/unit/test_project.py b/resource_manager/tests/unit/test_project.py index 28970c0abb68..bc23bdc02cb7 100644 --- a/resource_manager/tests/unit/test_project.py +++ b/resource_manager/tests/unit/test_project.py @@ -16,7 +16,6 @@ class TestProject(unittest.TestCase): - @staticmethod def _get_target_class(): from google.cloud.resource_manager.project import Project @@ -28,7 +27,7 @@ def _make_one(self, *args, **kw): def test_constructor_defaults(self): client = object() - PROJECT_ID = 'project-id' + PROJECT_ID = "project-id" project = self._make_one(PROJECT_ID, client) self.assertEqual(project.project_id, PROJECT_ID) self.assertEqual(project._client, client) @@ -40,11 +39,10 @@ def test_constructor_defaults(self): def test_constructor_explicit(self): client = object() - PROJECT_ID = 'project-id' - DISPLAY_NAME = 'name' - LABELS = {'foo': 'bar'} - project = self._make_one(PROJECT_ID, client, - name=DISPLAY_NAME, labels=LABELS) + PROJECT_ID = "project-id" + DISPLAY_NAME = "name" + LABELS = {"foo": "bar"} + project = self._make_one(PROJECT_ID, client, name=DISPLAY_NAME, labels=LABELS) self.assertEqual(project.project_id, PROJECT_ID) self.assertEqual(project._client, client) self.assertEqual(project.name, DISPLAY_NAME) @@ -55,19 +53,21 @@ def test_constructor_explicit(self): def test_from_api_repr(self): client = object() - PROJECT_ID = 'project-id' - PROJECT_NAME = 'My Project Name' + PROJECT_ID = "project-id" + PROJECT_NAME = "My Project Name" PROJECT_NUMBER = 12345678 - PROJECT_LABELS = {'env': 'prod'} - PROJECT_LIFECYCLE_STATE = 'ACTIVE' - PARENT = {'type': 'organization', 'id': '433637338579'} - - resource = {'projectId': PROJECT_ID, - 'name': PROJECT_NAME, - 'projectNumber': PROJECT_NUMBER, - 'labels': PROJECT_LABELS, - 'lifecycleState': PROJECT_LIFECYCLE_STATE, - 'parent': PARENT} + PROJECT_LABELS = {"env": "prod"} + PROJECT_LIFECYCLE_STATE = "ACTIVE" + PARENT = {"type": "organization", "id": "433637338579"} + + resource = { + "projectId": PROJECT_ID, + "name": PROJECT_NAME, + "projectNumber": PROJECT_NUMBER, + "labels": PROJECT_LABELS, + "lifecycleState": PROJECT_LIFECYCLE_STATE, + "parent": PARENT, + } project = self._get_target_class().from_api_repr(resource, client) self.assertEqual(project.project_id, PROJECT_ID) self.assertEqual(project._client, client) @@ -78,9 +78,9 @@ def test_from_api_repr(self): self.assertEqual(project.parent, PARENT) def test_full_name(self): - PROJECT_ID = 'project-id' + PROJECT_ID = "project-id" project = self._make_one(PROJECT_ID, None) - self.assertEqual('projects/%s' % PROJECT_ID, project.full_name) + self.assertEqual("projects/%s" % PROJECT_ID, project.full_name) def test_full_name_missing_id(self): project = self._make_one(None, None) @@ -88,23 +88,20 @@ def test_full_name_missing_id(self): self.assertIsNone(project.full_name) def test_path(self): - PROJECT_ID = 'project-id' + PROJECT_ID = "project-id" project = self._make_one(PROJECT_ID, None) - self.assertEqual('/projects/%s' % PROJECT_ID, project.path) + self.assertEqual("/projects/%s" % PROJECT_ID, project.path) def test_create(self): - PROJECT_ID = 'project-id' + PROJECT_ID = "project-id" PROJECT_NUMBER = 123 PROJECT_RESOURCE = { - 'projectId': PROJECT_ID, - 'projectNumber': PROJECT_NUMBER, - 'name': 'Project Name', - 'labels': {}, - 'lifecycleState': 'ACTIVE', - 'parent': { - 'type': 'organization', - 'id': '433637338589', - }, + "projectId": PROJECT_ID, + "projectNumber": PROJECT_NUMBER, + "name": "Project Name", + "labels": {}, + "lifecycleState": "ACTIVE", + "parent": {"type": "organization", "id": "433637338589"}, } connection = _Connection(PROJECT_RESOURCE) client = _Client(connection=connection) @@ -115,29 +112,22 @@ def test_create(self): request, = connection._requested expected_request = { - 'method': 'POST', - 'data': { - 'projectId': PROJECT_ID, - 'labels': {}, - 'name': None, - }, - 'path': '/projects', + "method": "POST", + "data": {"projectId": PROJECT_ID, "labels": {}, "name": None}, + "path": "/projects", } self.assertEqual(request, expected_request) def test_reload(self): - PROJECT_ID = 'project-id' + PROJECT_ID = "project-id" PROJECT_NUMBER = 123 PROJECT_RESOURCE = { - 'projectId': PROJECT_ID, - 'projectNumber': PROJECT_NUMBER, - 'name': 'Project Name', - 'labels': {'env': 'prod'}, - 'lifecycleState': 'ACTIVE', - 'parent': { - 'type': 'organization', - 'id': '433637338579', - }, + "projectId": PROJECT_ID, + "projectNumber": PROJECT_NUMBER, + "name": "Project Name", + "labels": {"env": "prod"}, + "lifecycleState": "ACTIVE", + "parent": {"type": "organization", "id": "433637338579"}, } connection = _Connection(PROJECT_RESOURCE) client = _Client(connection=connection) @@ -147,57 +137,54 @@ def test_reload(self): self.assertEqual(project.labels, {}) self.assertIsNone(project.status) project.reload() - self.assertEqual(project.name, PROJECT_RESOURCE['name']) + self.assertEqual(project.name, PROJECT_RESOURCE["name"]) self.assertEqual(project.number, PROJECT_NUMBER) - self.assertEqual(project.labels, PROJECT_RESOURCE['labels']) - self.assertEqual(project.status, PROJECT_RESOURCE['lifecycleState']) + self.assertEqual(project.labels, PROJECT_RESOURCE["labels"]) + self.assertEqual(project.status, PROJECT_RESOURCE["lifecycleState"]) request, = connection._requested # NOTE: data is not in the request since a GET request. - expected_request = { - 'method': 'GET', - 'path': project.path, - } + expected_request = {"method": "GET", "path": project.path} self.assertEqual(request, expected_request) def test_exists(self): - PROJECT_ID = 'project-id' - connection = _Connection({'projectId': PROJECT_ID}) + PROJECT_ID = "project-id" + connection = _Connection({"projectId": PROJECT_ID}) client = _Client(connection=connection) project = self._make_one(PROJECT_ID, client) self.assertTrue(project.exists()) def test_exists_with_explicitly_passed_client(self): - PROJECT_ID = 'project-id' - connection = _Connection({'projectId': PROJECT_ID}) + PROJECT_ID = "project-id" + connection = _Connection({"projectId": PROJECT_ID}) client = _Client(connection=connection) project = self._make_one(PROJECT_ID, None) self.assertTrue(project.exists(client=client)) def test_exists_with_missing_client(self): - PROJECT_ID = 'project-id' + PROJECT_ID = "project-id" project = self._make_one(PROJECT_ID, None) with self.assertRaises(AttributeError): project.exists() def test_exists_not_found(self): - PROJECT_ID = 'project-id' + PROJECT_ID = "project-id" connection = _Connection() client = _Client(connection=connection) project = self._make_one(PROJECT_ID, client) self.assertFalse(project.exists()) def test_update(self): - PROJECT_ID = 'project-id' + PROJECT_ID = "project-id" PROJECT_NUMBER = 123 - PROJECT_NAME = 'Project Name' - LABELS = {'env': 'prod'} + PROJECT_NAME = "Project Name" + LABELS = {"env": "prod"} PROJECT_RESOURCE = { - 'projectId': PROJECT_ID, - 'projectNumber': PROJECT_NUMBER, - 'name': PROJECT_NAME, - 'labels': LABELS, - 'lifecycleState': 'ACTIVE', + "projectId": PROJECT_ID, + "projectNumber": PROJECT_NUMBER, + "name": PROJECT_NAME, + "labels": LABELS, + "lifecycleState": "ACTIVE", } connection = _Connection(PROJECT_RESOURCE) client = _Client(connection=connection) @@ -208,29 +195,22 @@ def test_update(self): request, = connection._requested expected_request = { - 'method': 'PUT', - 'data': { - 'name': PROJECT_NAME, - 'labels': LABELS, - 'parent': None, - }, - 'path': project.path, + "method": "PUT", + "data": {"name": PROJECT_NAME, "labels": LABELS, "parent": None}, + "path": project.path, } self.assertEqual(request, expected_request) def test_delete_without_reload_data(self): - PROJECT_ID = 'project-id' + PROJECT_ID = "project-id" PROJECT_NUMBER = 123 PROJECT_RESOURCE = { - 'projectId': PROJECT_ID, - 'projectNumber': PROJECT_NUMBER, - 'name': 'Project Name', - 'labels': {'env': 'prod'}, - 'lifecycleState': 'ACTIVE', - 'parent': { - 'type': 'organization', - 'id': '433637338579', - }, + "projectId": PROJECT_ID, + "projectNumber": PROJECT_NUMBER, + "name": "Project Name", + "labels": {"env": "prod"}, + "lifecycleState": "ACTIVE", + "parent": {"type": "organization", "id": "433637338579"}, } connection = _Connection(PROJECT_RESOURCE) client = _Client(connection=connection) @@ -239,28 +219,22 @@ def test_delete_without_reload_data(self): request, = connection._requested # NOTE: data is not in the request since a DELETE request. - expected_request = { - 'method': 'DELETE', - 'path': project.path, - } + expected_request = {"method": "DELETE", "path": project.path} self.assertEqual(request, expected_request) def test_delete_with_reload_data(self): - PROJECT_ID = 'project-id' + PROJECT_ID = "project-id" PROJECT_NUMBER = 123 PROJECT_RESOURCE = { - 'projectId': PROJECT_ID, - 'projectNumber': PROJECT_NUMBER, - 'name': 'Project Name', - 'labels': {'env': 'prod'}, - 'lifecycleState': 'ACTIVE', - 'parent': { - 'type': 'organization', - 'id': '433637338579', - }, + "projectId": PROJECT_ID, + "projectNumber": PROJECT_NUMBER, + "name": "Project Name", + "labels": {"env": "prod"}, + "lifecycleState": "ACTIVE", + "parent": {"type": "organization", "id": "433637338579"}, } DELETING_PROJECT = PROJECT_RESOURCE.copy() - DELETING_PROJECT['lifecycleState'] = NEW_STATE = 'DELETE_REQUESTED' + DELETING_PROJECT["lifecycleState"] = NEW_STATE = "DELETE_REQUESTED" connection = _Connection(PROJECT_RESOURCE, DELETING_PROJECT) client = _Client(connection=connection) @@ -270,32 +244,23 @@ def test_delete_with_reload_data(self): delete_request, get_request = connection._requested # NOTE: data is not in the request since a DELETE request. - expected_delete_request = { - 'method': 'DELETE', - 'path': project.path, - } + expected_delete_request = {"method": "DELETE", "path": project.path} self.assertEqual(delete_request, expected_delete_request) # NOTE: data is not in the request since a GET request. - expected_get_request = { - 'method': 'GET', - 'path': project.path, - } + expected_get_request = {"method": "GET", "path": project.path} self.assertEqual(get_request, expected_get_request) def test_undelete_without_reload_data(self): - PROJECT_ID = 'project-id' + PROJECT_ID = "project-id" PROJECT_NUMBER = 123 PROJECT_RESOURCE = { - 'projectId': PROJECT_ID, - 'projectNumber': PROJECT_NUMBER, - 'name': 'Project Name', - 'labels': {'env': 'prod'}, - 'lifecycleState': 'DELETE_REQUESTED', - 'parent': { - 'type': 'organization', - 'id': '433637338579', - }, + "projectId": PROJECT_ID, + "projectNumber": PROJECT_NUMBER, + "name": "Project Name", + "labels": {"env": "prod"}, + "lifecycleState": "DELETE_REQUESTED", + "parent": {"type": "organization", "id": "433637338579"}, } connection = _Connection(PROJECT_RESOURCE) client = _Client(connection=connection) @@ -304,28 +269,22 @@ def test_undelete_without_reload_data(self): request, = connection._requested # NOTE: data is not in the request, undelete doesn't need it. - expected_request = { - 'method': 'POST', - 'path': project.path + ':undelete', - } + expected_request = {"method": "POST", "path": project.path + ":undelete"} self.assertEqual(request, expected_request) def test_undelete_with_reload_data(self): - PROJECT_ID = 'project-id' + PROJECT_ID = "project-id" PROJECT_NUMBER = 123 PROJECT_RESOURCE = { - 'projectId': PROJECT_ID, - 'projectNumber': PROJECT_NUMBER, - 'name': 'Project Name', - 'labels': {'env': 'prod'}, - 'lifecycleState': 'DELETE_REQUESTED', - 'parent': { - 'type': 'organization', - 'id': '433637338579', - }, + "projectId": PROJECT_ID, + "projectNumber": PROJECT_NUMBER, + "name": "Project Name", + "labels": {"env": "prod"}, + "lifecycleState": "DELETE_REQUESTED", + "parent": {"type": "organization", "id": "433637338579"}, } UNDELETED_PROJECT = PROJECT_RESOURCE.copy() - UNDELETED_PROJECT['lifecycleState'] = NEW_STATE = 'ACTIVE' + UNDELETED_PROJECT["lifecycleState"] = NEW_STATE = "ACTIVE" connection = _Connection(PROJECT_RESOURCE, UNDELETED_PROJECT) client = _Client(connection=connection) @@ -336,21 +295,17 @@ def test_undelete_with_reload_data(self): undelete_request, get_request = connection._requested # NOTE: data is not in the request, undelete doesn't need it. expected_undelete_request = { - 'method': 'POST', - 'path': project.path + ':undelete', + "method": "POST", + "path": project.path + ":undelete", } self.assertEqual(undelete_request, expected_undelete_request) # NOTE: data is not in the request since a GET request. - expected_get_request = { - 'method': 'GET', - 'path': project.path, - } + expected_get_request = {"method": "GET", "path": project.path} self.assertEqual(get_request, expected_get_request) class _Connection(object): - def __init__(self, *responses): self._responses = responses self._requested = [] @@ -363,12 +318,11 @@ def api_request(self, **kw): try: response, self._responses = self._responses[0], self._responses[1:] except IndexError: - raise NotFound('miss') + raise NotFound("miss") else: return response class _Client(object): - def __init__(self, connection=None): self._connection = connection diff --git a/runtimeconfig/noxfile.py b/runtimeconfig/noxfile.py index 02dca1406752..76b88851320c 100644 --- a/runtimeconfig/noxfile.py +++ b/runtimeconfig/noxfile.py @@ -25,6 +25,45 @@ ) +@nox.session(python="3.7") +def lint(session): + """Run linters. + Returns a failure if the linters find linting errors or sufficiently + serious code quality issues. + """ + session.install("flake8", "black", *LOCAL_DEPS) + session.run( + "black", + "--check", + "google", + "tests", + "docs", + ) + session.run("flake8", "google", "tests") + + +@nox.session(python="3.6") +def blacken(session): + """Run black. + Format code to uniform standard. + """ + session.install("black") + session.run( + "black", + "google", + "tests", + "docs", + ) + + +@nox.session(python='3.6') +def lint_setup_py(session): + """Verify that setup.py is valid (including RST check).""" + session.install('docutils', 'Pygments') + session.run( + 'python', 'setup.py', 'check', '--restructuredtext', '--strict') + + def default(session): """Default unit test session. """ @@ -52,26 +91,6 @@ def unit(session): default(session) -@nox.session(python='3.6') -def lint(session): - """Run linters. - - Returns a failure if the linters find linting errors or sufficiently - serious code quality issues. - """ - session.install('flake8', *LOCAL_DEPS) - session.install('.') - session.run('flake8', 'google', 'tests') - - -@nox.session(python='3.6') -def lint_setup_py(session): - """Verify that setup.py is valid (including RST check).""" - session.install('docutils', 'Pygments') - session.run( - 'python', 'setup.py', 'check', '--restructuredtext', '--strict') - - @nox.session(python='3.6') def cover(session): """Run the final coverage report. diff --git a/translate/noxfile.py b/translate/noxfile.py index 2b5ced7d60cc..fe9d1a8f0deb 100644 --- a/translate/noxfile.py +++ b/translate/noxfile.py @@ -24,6 +24,44 @@ os.path.join('..', 'core'), ) +@nox.session(python="3.7") +def lint(session): + """Run linters. + Returns a failure if the linters find linting errors or sufficiently + serious code quality issues. + """ + session.install("flake8", "black", *LOCAL_DEPS) + session.run( + "black", + "--check", + "google", + "tests", + "docs", + ) + session.run("flake8", "google", "tests") + + +@nox.session(python="3.6") +def blacken(session): + """Run black. + Format code to uniform standard. + """ + session.install("black") + session.run( + "black", + "google", + "tests", + "docs", + ) + + +@nox.session(python='3.6') +def lint_setup_py(session): + """Verify that setup.py is valid (including RST check).""" + session.install('docutils', 'Pygments') + session.run( + 'python', 'setup.py', 'check', '--restructuredtext', '--strict') + def default(session): """Default unit test session.""" @@ -70,26 +108,6 @@ def system(session): session.run('py.test', '--quiet', 'tests/system.py') -@nox.session(python='3.6') -def lint(session): - """Run linters. - - Returns a failure if the linters find linting errors or sufficiently - serious code quality issues. - """ - session.install('flake8', *LOCAL_DEPS) - session.install('.') - session.run('flake8', 'google', 'tests') - - -@nox.session(python='3.6') -def lint_setup_py(session): - """Verify that setup.py is valid (including RST check).""" - session.install('docutils', 'Pygments') - session.run( - 'python', 'setup.py', 'check', '--restructuredtext', '--strict') - - @nox.session(python='3.6') def cover(session): """Run the final coverage report.