Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[components] Components setup integration test #27375

Merged
merged 11 commits into from
Jan 31, 2025

Conversation

benpankow
Copy link
Member

@benpankow benpankow commented Jan 25, 2025

Summary

Builds a little docs integration testing framework which allows us to define a series of steps that either:

  1. Run a command
    run_command_and_snippet_output(
        cmd="dg code-location scaffold jaffle-platform",
        snippet_path=COMPONENTS_SNIPPETS_DIR / f"{next_snip_no()}-scaffold.txt",
        update_snippets=update_snippets,
        snippet_replace_regex=[
            # Mask tempdir path of `/whatever/folder/jaffle-platform` with `/.../jaffle-platform`
            (r" \/.*?\/jaffle-platform", " /.../jaffle-platform")
        ],
    )
  • Check the contents of a file
    check_file(
        "pyproject.toml",
        COMPONENTS_SNIPPETS_DIR / f"{next_snip_no()}-pyproject.toml",
        update_snippets=update_snippets,
    )
  • Update the contents of a file
    create_file(
        file_path=Path("jaffle_platform") / "components" / "ingest_files" / "replication.yaml",
        snippet_path=COMPONENTS_SNIPPETS_DIR / f"{next_snip_no()}-replication.yaml",
        contents="""
    ### foo bar
    """,
    )

Each step corresponds to a docs snippet file. By default, (tox -e docs_snapshot_test, run as part of BK CI) these tests ensure that output of each of these steps is identical to the snippet file. The tests will fail if the docs guide breaks or the output of any of the commands changes.

The test suite can also be run in a snippet update mode (tox -e docs_snapshot_update), which will update each of the snippets to match the actual output of each step, which we can use whenever we update the docs steps or the code it's using.

Also has some utilities for masking or removing parts of files/output we don't care about, or which might vary (e.g. timestamps, filepaths etc)

See https://github.com/dagster-io/dagster/pull/27375/files#diff-22c4df2c53a911cdff63776be42c290bca0a8f3d2c6134c27f48a40b0aba4692 for the example

Test Plan

New test suite.

@benpankow
Copy link
Member Author

benpankow commented Jan 25, 2025

@benpankow benpankow force-pushed the benpankow/components-docs-test branch from 0b7d96e to 9b7bbd9 Compare January 27, 2025 19:12
@benpankow benpankow changed the title [wip] docs integration test [components] Components setup integration test Jan 27, 2025
@benpankow benpankow force-pushed the benpankow/components-docs-test branch from 9b7bbd9 to 60ead8d Compare January 27, 2025 19:16
@benpankow benpankow marked this pull request as ready for review January 27, 2025 19:23
@benpankow benpankow requested a review from neverett as a code owner January 27, 2025 19:23
Copy link
Member

@schrockn schrockn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool.

Is the only way to refresh the generate snippets is to run the tests?

@benpankow
Copy link
Member Author

benpankow commented Jan 27, 2025

Is the only way to refresh the generate snippets is to run the tests?

Right now yes, main reason being that tox gives us a nice self-contained Python environment, but no reason you couldn't invoke the Python fn directly outside of a pytest context as long as your env was set up prooperly.

@benpankow benpankow requested a review from schrockn January 27, 2025 21:31
@benpankow benpankow force-pushed the benpankow/components-docs-test branch from a855a0c to 417fe1a Compare January 27, 2025 21:33
Copy link
Member

@schrockn schrockn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be very helpful to have a makefile somewhere that has an entry like regenerate_snippets even if it just invokes the test. Pretty unintuitive as is and you have to just magically know. Makefile is a good way to document this tribal knowledge

@benpankow
Copy link
Member Author

It would be very helpful to have a makefile somewhere that has an entry like regenerate_snippets even if it just invokes the test. Pretty unintuitive as is and you have to just magically know. Makefile is a good way to document this tribal knowledge

Agreed, added a couple Makefile commands in the docs folder.

@benpankow benpankow requested a review from schrockn January 27, 2025 22:10
@benpankow benpankow force-pushed the benpankow/components-docs-test branch 3 times, most recently from 69ea005 to abb9f78 Compare January 28, 2025 00:15
@benpankow benpankow force-pushed the benpankow/components-docs-test branch from fb2c492 to 9c38ec4 Compare January 31, 2025 21:57
@benpankow benpankow force-pushed the benpankow/components-docs-test branch from 1b390a5 to 090ec80 Compare January 31, 2025 23:10
@benpankow benpankow merged commit 4deeb57 into master Jan 31, 2025
6 of 7 checks passed
@benpankow benpankow deleted the benpankow/components-docs-test branch January 31, 2025 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants