-
Notifications
You must be signed in to change notification settings - Fork 179
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
test(snapshot): major improvements #15350
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fdaef32
snapshots updated from edge to against 7.3.0
y3rsh 433f06c
add PL 2.18 protocols
y3rsh 045b096
format
y3rsh 9370ef8
prep for version switch
y3rsh ba813e2
test(snapshot): analysis changes 7.3.0 to 7.3.1-alpha.0
y3rsh a2096b8
Merge branch 'edge' into 7.3.1-shapshot-testing-2.19-protocols
y3rsh cf87a95
update snapshots
y3rsh c8d555e
Merge branch 'edge' into 7.3.1-shapshot-testing-2.19-protocols
y3rsh 299edfc
all the snapshots
y3rsh 543c4e1
fix duplicates
y3rsh dc2ddd0
move document and get rid of env
y3rsh a763393
Merge branch 'edge' into 7.3.1-shapshot-testing-2.19-protocols
y3rsh d09e7be
replaced changing values
y3rsh 9216f48
remove comment
y3rsh 98444ed
oh ya
y3rsh 3031573
timestamps back in
y3rsh e483e56
Update .eslintignore
y3rsh 1a9c237
Update .github/workflows/analyses-snapshot-test.yaml
y3rsh 71baa3d
experiment for js-lint
y3rsh bac3633
more folders excluded
y3rsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,12 @@ name: Analyses Snapshot Test | |
on: | ||
workflow_dispatch: | ||
inputs: | ||
TARGET: | ||
description: 'Target branch or tag' | ||
ANALYSIS_REF: | ||
description: 'Branch or tag that provides the analysis output at test runtime' | ||
required: true | ||
default: 'edge' | ||
TEST_SOURCE: | ||
description: 'Target for the test code' | ||
SNAPSHOT_REF: | ||
description: 'Branch or tag that provides the snapshot and test code at test runtime' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This is something that has always confused me every time I go to run something. So being a bit verbose would be helpful here. If you can, you might provide a link to the README |
||
required: true | ||
default: 'edge' | ||
schedule: | ||
|
@@ -28,57 +28,57 @@ jobs: | |
timeout-minutes: 15 | ||
runs-on: ubuntu-latest | ||
env: | ||
TARGET: ${{ github.event.inputs.TARGET || github.head_ref || 'edge' }} | ||
TEST_SOURCE: ${{ github.event.inputs.TEST_SOURCE || github.head_ref || 'edge' }} | ||
ANALYSIS_REF: ${{ github.event.inputs.ANALYSIS_REF || github.head_ref || 'edge' }} | ||
SNAPSHOT_REF: ${{ github.event.inputs.SNAPSHOT_REF || github.head_ref || 'edge' }} | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ env.TEST_SOURCE }} | ||
ref: ${{ env.SNAPSHOT_REF }} | ||
|
||
- name: Docker Build | ||
working-directory: app-testing | ||
working-directory: analyses-snapshot-testing | ||
run: make build-opentrons-analysis | ||
|
||
- name: Set up Python 3.12 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.12' | ||
cache: 'pipenv' | ||
cache-dependency-path: app-testing/Pipfile.lock | ||
cache-dependency-path: analyses-snapshot-testing/Pipfile.lock | ||
|
||
- name: Setup Python Dependencies | ||
working-directory: app-testing | ||
working-directory: analyses-snapshot-testing | ||
run: make setup | ||
|
||
- name: Run Test | ||
id: run_test | ||
working-directory: app-testing | ||
working-directory: analyses-snapshot-testing | ||
run: make snapshot-test | ||
|
||
- name: Upload Report | ||
if: '!cancelled()' | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: test-report | ||
path: app-testing/results/ | ||
path: analyses-snapshot-testing/results/ | ||
|
||
- name: Handle Test Failure | ||
if: failure() | ||
working-directory: app-testing | ||
working-directory: analyses-snapshot-testing | ||
run: make snapshot-test-update | ||
|
||
- name: Create Snapshot update Request | ||
id: create-pull-request | ||
if: failure() | ||
uses: peter-evans/create-pull-request@v5 | ||
with: | ||
commit-message: 'fix(app-testing): snapshot failure capture' | ||
title: 'fix(app-testing): snapshot failure capture' | ||
body: 'This PR is an automated snapshot update request. Please review the changes and merge if they are acceptable or find you bug and fix it.' | ||
branch: 'app-testing/${{ env.TARGET }}-from-${{ env.TEST_SOURCE}}' | ||
base: ${{ env.TEST_SOURCE}} | ||
commit-message: 'fix(analyses-snapshot-testing): snapshot failure capture' | ||
title: 'fix(analyses-snapshot-testing): ${{ env.ANALYSIS_REF }} snapshot failure capture' | ||
body: 'This PR is an automated snapshot update request. Please review the changes and merge if they are acceptable or find your bug and fix it.' | ||
branch: 'analyses-snapshot-testing/${{ env.ANALYSIS_REF }}-from-${{ env.SNAPSHOT_REF}}' | ||
base: ${{ env.SNAPSHOT_REF}} | ||
|
||
- name: Comment on PR | ||
if: failure() && github.event_name == 'pull_request' | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Analyses Generation and Snapshot Testing | ||
|
||
## Setup | ||
|
||
1. Follow the instructions in [DEV_SETUP.md](../DEV_SETUP.md) | ||
1. `cd analyses-snapshot-testing` | ||
1. use pyenv to install python 3.12 and set it as the local python version for this directory | ||
1. `make setup` | ||
1. Have docker installed and ready | ||
|
||
## Concepts | ||
|
||
- If working locally the branch you have checked out is the test code/snapshots you are working with. | ||
- In CI this is the `SNAPSHOT_REF`. This is the branch or tag of the test code/snapshots that analyses generated will be compared to. | ||
- The `ANALYSIS_REF` is the branch or tag that you want analyses generated from. | ||
|
||
## Running the tests locally | ||
|
||
- Compare the current branch snapshots to analyses generated from the edge branch | ||
- `make build-opentrons-analysis ANALYSIS_REF=edge` this builds a docker image named and tagged `opentrons-analysis:edge` | ||
- this pulls the latest edge every time it builds! | ||
- `make snapshot-test ANALYSIS_REF=edge` | ||
- This runs the test. The test: | ||
- Spins up a container from the `opentrons-analysis:edge` image. ANALYSIS_REF=edge specifies the image to use. | ||
- Analyses as .json files are generated for all protocols defined in [protocols.py](./automation/data/protocols.py) and [protocols_with_overrides.py](./automation/data/protocols_with_overrides.py) | ||
- the test compares the generated analyses to the snapshots in the [./tests/**snapshots**/](./tests/__snapshots__/) directory | ||
|
||
## Updating the snapshots | ||
|
||
- Assuming you have already built the `opentrons-analysis:edge` image | ||
- `make snapshot-test-update ANALYSIS_REF=edge` | ||
- This will update the snapshots in the [./tests/**snapshots**/](./tests/__snapshots__/) directory with the analyses generated from the edge branch | ||
|
||
## Running the tests against specific protocols | ||
|
||
> We are omitting ANALYSIS_REF=edge because we can, it is the default in the Makefile | ||
|
||
- `make snapshot-test PROTOCOL_NAMES=Flex_S_v2_19_Illumina_DNA_PCR_Free OVERRIDE_PROTOCOL_NAMES=none` | ||
- `make snapshot-test PROTOCOL_NAMES=none OVERRIDE_PROTOCOL_NAMES=Flex_X_v2_18_NO_PIPETTES_Overrides_BadTypesInRTP` | ||
- `make snapshot-test PROTOCOL_NAMES="Flex_S_v2_19_Illumina_DNA_PCR_Free,OT2_S_v2_18_P300M_P20S_HS_TC_TM_SmokeTestV3" OVERRIDE_PROTOCOL_NAMES=none` |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
54 changes: 54 additions & 0 deletions
54
analyses-snapshot-testing/automation/data/protocol_registry.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from typing import Optional | ||
|
||
from automation.data.protocol import Protocol | ||
from automation.data.protocol_with_overrides import ProtocolWithOverrides | ||
from automation.data.protocols import Protocols | ||
from automation.data.protocols_with_overrides import ProtocolsWithOverrides | ||
|
||
ALL_PROTOCOLS = "all" | ||
|
||
|
||
class ProtocolRegistry: | ||
def __init__(self, protocol_names: str = ALL_PROTOCOLS, override_protocol_names: str = ALL_PROTOCOLS) -> None: | ||
self.protocols: Protocols = Protocols() | ||
self.protocols_with_overrides: ProtocolsWithOverrides = ProtocolsWithOverrides() | ||
self.protocol_names = protocol_names | ||
self.override_protocol_names = override_protocol_names | ||
self.protocols_to_test: Optional[list[Protocol]] = self._what_protocols() | ||
|
||
def _what_protocols(self) -> Optional[list[Protocol]]: | ||
protocols_to_test: list[Protocol] = [] | ||
|
||
if self.protocol_names.lower() == ALL_PROTOCOLS: | ||
protocols_to_test.extend(self.all_defined_protocols()) | ||
elif self.protocol_names.lower() == "none": | ||
pass | ||
else: | ||
for protocol_name in [x.strip() for x in self.protocol_names.split(",")]: | ||
protocol: Protocol = getattr(self.protocols, protocol_name) # raises | ||
protocols_to_test.append(protocol) | ||
|
||
if self.override_protocol_names.lower() == ALL_PROTOCOLS: | ||
protocols_to_test.extend(self.all_defined_protocols_with_overrides()) | ||
elif self.override_protocol_names.lower() == "none": | ||
pass | ||
else: | ||
for protocol_with_overrides__name in [x.strip() for x in self.override_protocol_names.split(",")]: | ||
protocol_with_overrides: ProtocolWithOverrides = getattr( | ||
self.protocols_with_overrides, protocol_with_overrides__name | ||
) # raises | ||
if protocol_with_overrides.protocols is not None: | ||
protocols_to_test.extend(protocol_with_overrides.protocols) | ||
if protocols_to_test == []: | ||
return None | ||
return protocols_to_test | ||
|
||
def all_defined_protocols(self) -> list[Protocol]: | ||
return [getattr(self.protocols, prop) for prop in dir(self.protocols) if "__" not in prop] | ||
|
||
def all_defined_protocols_with_overrides(self) -> list[Protocol]: | ||
protocols_with_overrides = [ | ||
getattr(self.protocols_with_overrides, prop) for prop in dir(self.protocols_with_overrides) if "__" not in prop | ||
] | ||
# Flatten the list of lists into a single list of protocols | ||
return [protocol for protocol_with_overrides in protocols_with_overrides for protocol in protocol_with_overrides.protocols] |
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Add something like
what ref you want to compare snaphsot results to