Skip to content

Adding datastore _DEFAULTS stubs in all tests that use it. - #665

Merged
dhermes merged 1 commit into
googleapis:masterfrom
dhermes:lazy-loading-attempt-2
Feb 19, 2015
Merged

Adding datastore _DEFAULTS stubs in all tests that use it.#665
dhermes merged 1 commit into
googleapis:masterfrom
dhermes:lazy-loading-attempt-2

Conversation

@dhermes

Copy link
Copy Markdown
Contributor

NOTE: Has #664 as diffbase

Introduces

  • concept of implicit for _DefaultsContainer.
  • testing module for datastore for patching

Verified all test cases that would accidentally rely on _DEFAULTS implicit
behavior by using a custom _DefaultsContainer that raises when the
instance is implicit.

Main delta for the custom properties:

diff --git a/gcloud/datastore/_implicit_environ.py b/gcloud/datastore/_implicit_environ.py
index 3afc954..1d38562 100644
--- a/gcloud/datastore/_implicit_environ.py+++ b/gcloud/datastore/_implicit_environ.py@@ -38,9 +38,37 @@ class _DefaultsContainer(object):
:param dataset_id: Persistent implied dataset ID from environment.
"""
- def __init__(self, connection=None, dataset_id=None):- self.connection = connection- self.dataset_id = dataset_id+ class FooError(Exception):+ pass++ @property+ def dataset_id(self):+ if self.implicit:+ raise self.FooError+ return self._dataset_id++ @dataset_id.setter+ def dataset_id(self, value):+ if self.implicit:+ raise self.FooError+ self._dataset_id = value++ @property+ def connection(self):+ if self.implicit:+ raise self.FooError+ return self._connection++ @connection.setter+ def connection(self, value):+ if self.implicit:+ raise self.FooError+ self._connection = value++ def __init__(self, connection=None, dataset_id=None, implicit=False):+ self.implicit = implicit+ self._connection = connection+ self._dataset_id = dataset_id
def app_engine_id():

@googlebotgooglebot added the cla: yes This human has signed the Contributor License Agreement. label Feb 18, 2015
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 100.0% when pulling 1f990e0 on dhermes:lazy-loading-attempt-2 into 72b6359 on GoogleCloudPlatform:master.

@dhermesdhermes added the api: datastore Issues related to the Datastore API. label Feb 19, 2015
@dhermesdhermes mentioned this pull request Feb 19, 2015

This comment was marked as spam.

@tseaver

Copy link
Copy Markdown
Contributor

I don't grasp the "main delta" bit: are you saying that was stuff you used to find places relying on implicit values, but didn't check it in after fixing them?

@dhermes

Copy link
Copy Markdown
ContributorAuthor

This PR is really just about using _monkey_defaults, _setup_defaults and _tear_down_defaults in tests.

The diff above is a hack I used to sniff out tests that relied on implicit behavior. It makes it so that anytime connection or dataset_id are get or set on a _DefaultsContainer, the following occurs:

ifself.implicit:
raiseself.FooError

So if the container being tested was implicit, the test would fail. (I made a custom error, so it didn't get caught by any assertRaises)

Introduces
- concept of `implicit` for `_DefaultsContainer`.
- testing module for datastore for patching
Verified all test cases that would accidentally rely on _DEFAULTS implicit
behavior by using a custom `_DefaultsContainer` that raises when the
instance is implicit.
Main delta for the custom properties:
diff --git a/gcloud/datastore/_implicit_environ.py b/gcloud/datastore/_implicit_environ.py
index 3afc954..1d38562 100644
--- a/gcloud/datastore/_implicit_environ.py
+++ b/gcloud/datastore/_implicit_environ.py
@@ -38,9 +38,37 @@ class _DefaultsContainer(object):
:param dataset_id: Persistent implied dataset ID from environment.
"""
- def __init__(self, connection=None, dataset_id=None):
- self.connection = connection
- self.dataset_id = dataset_id
+ class FooError(Exception):
+ pass
+
+ @Property
+ def dataset_id(self):
+ if self.implicit:
+ raise self.FooError
+ return self._dataset_id
+
+ @dataset_id.setter
+ def dataset_id(self, value):
+ if self.implicit:
+ raise self.FooError
+ self._dataset_id = value
+
+ @Property
+ def connection(self):
+ if self.implicit:
+ raise self.FooError
+ return self._connection
+
+ @connection.setter
+ def connection(self, value):
+ if self.implicit:
+ raise self.FooError
+ self._connection = value
+
+ def __init__(self, connection=None, dataset_id=None, implicit=False):
+ self.implicit = implicit
+ self._connection = connection
+ self._dataset_id = dataset_id
def app_engine_id():
@dhermes
dhermesforce-pushed the lazy-loading-attempt-2 branch from 1f990e0 to 5e281ddCompareFebruary 19, 2015 19:10
@dhermes

Copy link
Copy Markdown
ContributorAuthor

@tseaver I just rebased on top of #664.

Remaining issues here?

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage remained the same at 100.0% when pulling 5e281dd on dhermes:lazy-loading-attempt-2 into 998c724 on GoogleCloudPlatform:master.

@tseaver

Copy link
Copy Markdown
Contributor

LGTM. (I think some of this commit gets backed out in #667 anyway).

dhermes added a commit that referenced this pull request Feb 19, 2015
Adding datastore _DEFAULTS stubs in all tests that use it.
@dhermes
dhermes merged commit 6ff634a into googleapis:masterFeb 19, 2015
@dhermes
dhermes deleted the lazy-loading-attempt-2 branch February 19, 2015 19:29
@dhermesdhermes mentioned this pull request Feb 25, 2015
vchudnov-g pushed a commit that referenced this pull request Sep 20, 2023
* feat: added baseline model version used to generate the summary
feat: added the platform of the virtual agent response messages
PiperOrigin-RevId: 555788605
Source-Link: googleapis/googleapis@90a551c
Source-Link: googleapis/googleapis-gen@30620b4
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMzA2MjBiNGYzNDcxMzg2MDA4M2ZmZjAzNjk4MjkwMGIxMDA0Y2JmNSJ9
* 🦉 Updates from OwlBot post-processor
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
---------
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
parthea added a commit that referenced this pull request Sep 18, 2025
* chore(deps): update all dependencies
* 🦉 Updates from OwlBot post-processor
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
---------
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
parthea added a commit that referenced this pull request Nov 22, 2025
* chore(python): exclude setup.py in renovate config
Source-Link: googleapis/synthtool@56da63e
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:993a058718e84a82fda04c3177e58f0a43281a996c7c395e0a56ccc4d6d210d7
* increase timeouts
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
parthea added a commit that referenced this pull request Nov 24, 2025
This reverts commit d96eb5cdd8120bfec97d62b09512c6fecc325be8.
parthea pushed a commit that referenced this pull request Nov 24, 2025
parthea pushed a commit that referenced this pull request Mar 6, 2026
gcr.io/repo-automation-bots/owlbot-python:latest@sha256:4c981a6b6f2b8914a448d7b3a01688365be03e3ed26dfee399a6aa77fb112eaa
parthea pushed a commit that referenced this pull request Mar 6, 2026
* changes to docs for sphinx
* remvoing warnings
* adding sample code
* linting
* modifying import settings
* settings changes
* line accidently deleted in creation.py
* lint_setup_py test
* adding new lines and making changes to read me
Co-authored-by: Vikash Singh <3116482+vi3k6i5@users.noreply.github.com>
parthea pushed a commit that referenced this pull request Mar 9, 2026
* samples: add async upload sample
* make python3.6 compatible
* woops, this one too
* so annoying, can we deprecate 3.6 too?
* be gone with you 3.6!
* add comment clarifying how sample is run
parthea added a commit that referenced this pull request Mar 9, 2026
Source-Link: googleapis/synthtool@4760d8d
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:f0e4b51deef56bed74d3e2359c583fc104a8d6367da3984fc5c66938db738828
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: datastoreIssues related to the Datastore API.cla: yesThis human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@dhermes@coveralls@tseaver@googlebot