GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Make pubsub example snippets testable. by tseaver · Pull Request #1690 · googleapis/google-cloud-python

Conversation

@tseaver

@tseaver tseaver commented Apr 1, 2016

Copy link
Copy Markdown
Contributor

Toward #212, #1141, etc.

@dhermes, @jgeewax Not-yet-complete transformation, but worth discussing.

I'm basically ripping off the snippet format from @pcostell.

The snippets can be tested by running the file as a script, under an appropriately configured environment:

$ .tox/system-tests/bin/python docs/pubsub_snippets.py 
client_list_topics       : List topics for a project.
client_list_subscriptions: List all subscriptions for a project.
topic_create             : Create a topic.
topic_exists             : Test existence of a topic.
topic_delete             : Delete a topic.
topic_iam_policy         : Fetch / set a topic's IAM policy.
topic_publish_messages   : Publish messages to a topic.
topic_batch              : Publish multiple messages in a single request.
topic_subscription       : Create subscriptions to a topic.
subscription_lifecycle   : Test lifecycle of a subscription.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tseaver tseaver added docs do not merge Indicates a pull request not ready for merge, due to either quality or timing. api: pubsub Issues related to the Pub/Sub API. labels Apr 1, 2016
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Apr 1, 2016
dhermes
dhermes reviewed Apr 1, 2016
View reviewed changes
Comment thread docs/pubsub-usage.rst
.. doctest::
.. literalinclude:: pubsub_snippets.py
:start-after: [START client_list_topics]
:end-before: [END client_list_topics]

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Apr 1, 2016

Copy link
Copy Markdown
Contributor Author

I fixed the lint errors and squashed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver tseaver removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Apr 1, 2016
@tseaver

tseaver commented Apr 1, 2016

Copy link
Copy Markdown
Contributor Author

docs/pubsub-usage.rst is now completely converted to snippets. The check_iam_permissions methods are till untested (due to #1687), and we don't have tested examples for pull mode (because they require a validated enpoint URL).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Apr 7, 2016

Copy link
Copy Markdown
Contributor Author

Rebased to fix merge conflicts.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver tseaver mentioned this pull request Apr 7, 2016
Add a 'docs-doc2dash' Tox target. #1702
Merged
@dhermes

dhermes commented Apr 8, 2016

Copy link
Copy Markdown
Contributor

@tseaver What's the status here? Just deciding what we want?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Apr 8, 2016

Copy link
Copy Markdown
Contributor Author

@dhermes From my perspective, the PR is ready to merge: I'm pleased with the end-to-end testability of the snippets.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Apr 8, 2016

Copy link
Copy Markdown
Contributor

OK so @jgeewax can we try to reach a resolution? My preference is to remove the literalinclude statements from actual docstrings and just rely on the RST files for examples.

@tseaver One note I keep forgetting to mention, running the examples as system tests isn't particularly crucial. However, mocking out some parts (e.g. env. sniffing when constructing a client) would be painful to do with doctest but wonderfully easy to do in pure Python.

We could "meet in the middle" and have a script which extracts snippets from docstrings and writes them to a file and then fail if the generated files don't match what we expect them to look like?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Apr 8, 2016

Copy link
Copy Markdown
Contributor Author

Running the examples as system tests isn't particularly crucial.

Hmm, ensuring they don't bitrot as the API fixes bugs, etc, seems like a win to me: the code that shows up in examples demonstrably works, rather than just compiling without errors.

I still haven't heard anything defending the need for snippets at the REPL prompt, rather than expecting users to read our fine manual.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Apr 8, 2016

Copy link
Copy Markdown
Contributor

I'm saying running them as unit tests with some mocks/stubs should be just fine. Full set-up as system tests may be overkill.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Apr 8, 2016

Copy link
Copy Markdown
Contributor Author

Running them as unit tests with some mocks/stubs should be just fine. Full set-up as system tests may be overkill.

I'd be willing to bet there would be more code involved setting up the mocks needed to run them without talking to the API: the mocks would have to preserve / update expected state across multiple requests, which our current mocking patterns don't handle well.

FWIW, as they stand in this PR, the Pubsub snippets are actually have better API coverage than our current system tests.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Apr 8, 2016

Copy link
Copy Markdown
Contributor

FWIW, as they stand in this PR, the Pubsub snippets are actually have better API coverage than our current system tests.

That's just a statement about poor coverage of the system tests.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Apr 9, 2016

Copy link
Copy Markdown
Contributor Author

It is a statement about the system test coverage, sure: needing a tested snippet for the uncovered Subscription.modify_ack_deadlines method motivated making the coverage better.

I'm puzzled that you don't weigh the "snippets actually work against the real API" consideration higher: if we had that pattern in place for all our APIs, we would get many fewer user-driven bug reports about the docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Apr 11, 2016

Copy link
Copy Markdown
Contributor

@tseaver We've got the thumbs up from @jgeewax to use the literal includes and make sure our docs look good when Sphinx-generated.

Now we need to make sure we are square on this approach. Some things I think still need to be addressed (maybe not in this PR, but in a follow-up):

  1. A clear story on when these snippets are run (i.e. update tox.ini)
  2. Way fewer pylint disable statements
  3. Integrating with unittest, it seems your main() is emulating some of that functionality.

I think the easiest way to get this PR in is just to drop a lot of the features in the snippets file that make it runnable and then build up in new PRs something we can agree on and is extensible. So the core change in this PR would be in using the literal includes from an actual Python file.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Apr 22, 2016

Copy link
Copy Markdown
Contributor

@tseaver Bump

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Apr 22, 2016

Copy link
Copy Markdown
Contributor Author

I've rebased to fix conflicts. I will look at your other points shortly.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Apr 22, 2016

Copy link
Copy Markdown
Contributor Author

@dhermes I can't repro the Travis failures (or skips) locally: not only that, but the hash for the failing test (06b9815) doesn't match the hash at the tip of my branch (b587a66).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Apr 22, 2016

Copy link
Copy Markdown
Contributor

Did you create a merge commit? Even if you did, it's unclear why it isn't showing up in the PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Apr 22, 2016

Copy link
Copy Markdown
Contributor Author

https://github.com/tseaver/gcloud-python/commits/212-pubsub-extract_usage_examples_to_snippets

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Apr 22, 2016

Copy link
Copy Markdown
Contributor Author

The commit hash that Travis wants to test isn't even on my branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Apr 22, 2016

Copy link
Copy Markdown
Contributor Author

Maybe I should just close this PR and open a new one for my branch?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Apr 22, 2016

Copy link
Copy Markdown
Contributor

I'd create a fresh branch locally from HEAD, cherry pick each of your commits and then force push onto this branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Apr 22, 2016

Copy link
Copy Markdown
Contributor

But do whatever you're comfortable with.

As it were, I suggested you just rip out the snippets into literal includes for now and then we have a design discussion around how to run the snippets.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Apr 22, 2016

Copy link
Copy Markdown
Contributor Author

I just rebased again from the current head.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tseaver added 4 commits April 22, 2016 16:21
@tseaver
Make pubsub example snippets testable.
ecd0ffc
Toward #212, #1141, etc.
@tseaver
Snippets for 'Subscription.{pull,acknowledge,modify_ack_deadline}'.
51bcf91
@tseaver
Snippets for Subscription IAM methods.
cb77bb6
@tseaver
Fix unmerged test change.
95a0ccc
@tseaver
tseaver merged commit 4e242ec into googleapis:master Apr 22, 2016
@tseaver
tseaver deleted the 212-pubsub-extract_usage_examples_to_snippets branch April 22, 2016 23:17
@dhermes

dhermes commented Apr 22, 2016

Copy link
Copy Markdown
Contributor

@tseaver I never gave the LGTM for the merge. I suppose the "do whatever you're comfortable with" may have been confusing. It was in reference to your git / GitHub problem.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver tseaver mentioned this pull request Apr 22, 2016
How should we exercise snippets via testing? #1744
Closed
@tseaver

tseaver commented Apr 22, 2016

Copy link
Copy Markdown
Contributor Author

I opened #1744 to track your points about how the snippets should be exercised.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver tseaver mentioned this pull request May 16, 2016
Cut 0.14.0 release. #1799
Merged
parthea pushed a commit that referenced this pull request Oct 21, 2023
@daniel-sanche @busunkim96
KMS test fix [(#1690)](GoogleCloudPlatform/python-docs-samples#1690)
2db00e3
parthea pushed a commit that referenced this pull request Mar 9, 2026
@chandra-siri @gemini-code-assist
chore: skip kms tests until b/470276398 (#1690)
bdab3ac
chore: skip kms tests until b/470276398

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this pull request Apr 1, 2026
@sycai
fix: use value equality to check types for unix epoch functions and t…
b23a1e3
…imestamp diff (#1690)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

api: pubsub Issues related to the Pub/Sub API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@tseaver @dhermes @jgeewax @googlebot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.