-
Notifications
You must be signed in to change notification settings - Fork 45
new refactor assertions documentation for clarity #353
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
Open
Kah2412
wants to merge
4
commits into
askimed:main
Choose a base branch
from
Kah2412:patch-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,76 +1,82 @@ | ||
| # Files | ||
| Files | ||
|
|
||
| ## md5 Checksum | ||
| md5 Checksum | ||
|
|
||
| nf-test extends `path` by a `md5` property that can be used to compare the file content with an expected checksum: | ||
| nf-test extends path by a md5 property that can be used to compare the file content with an expected checksum: | ||
|
|
||
| ```Groovy | ||
| assert path(process.out.out_ch.get(0)).md5 == "64debea5017a035ddc67c0b51fa84b16" | ||
| ``` | ||
| Note that for gzip compressed files, the `md5` property is calculated after gunzipping the file contents, whereas for other filetypes the `md5` property is directly | ||
| calculated on the file itself. | ||
|
|
||
| ## JSON Files | ||
| nf-test supports comparison of JSON files and keys within JSON files. | ||
| To assert that two JSON files contain the same keys and values: | ||
| ```Groovy | ||
| assert path(process.out.out_ch.get(0)).json == path('./some.json').json | ||
| ``` | ||
| Individual keys can also be asserted: | ||
|
|
||
| ```Groovy | ||
| assert path(process.out.out_ch.get(0)).json.key == "value" | ||
| ``` | ||
| Note that for gzip compressed files, the md5 property is calculated after gunzipping the file contents, whereas for other filetypes the md5 property is directly calculated on the file itself. | ||
|
|
||
| ## YAML Files | ||
| nf-test supports comparison of YAML files and keys within YAML files. | ||
| To assert that two YAML files contain the same keys and values: | ||
| ```Groovy | ||
| assert path(process.out.out_ch.get(0)).yaml == path('./some.yaml').yaml | ||
| ``` | ||
| Individual keys can also be asserted: | ||
| JSON Files | ||
|
|
||
| ```Groovy | ||
| assert path(process.out.out_ch.get(0)).yaml.key == "value" | ||
| ``` | ||
| nf-test supports comparison of JSON files and specific fields within them. To assert that two JSON files are identical: | ||
|
|
||
| ## GZip Files | ||
| assert path(process.out.out_ch.get(0)).json == path('./expected_output.json').json | ||
|
Collaborator
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. This should be a codeblock |
||
|
|
||
| nf-test extends `path` by a `linesGzip` property that can be used to read gzip compressed files. | ||
|
|
||
| To verify a specific field, use dot notation. For example, if your JSON contains { "tool": "nf-test", "version": "1.0" }: | ||
|
|
||
| ```Groovy | ||
| assert path(process.out.out_ch.get(0)).linesGzip.size() == 5 | ||
| assert path(process.out.out_ch.get(0)).linesGzip.contains("Line Content") | ||
| ``` | ||
| // Given a JSON output file with content: { "tool": "nf-test", "version": "1.0" } | ||
| // Use dot notation to access the value of a specific field by name: | ||
| assert path(process.out.out_ch.get(0)).json.tool == "nf-test" | ||
| assert path(process.out.out_ch.get(0)).json.version == "1.0" | ||
|
|
||
|
|
||
| ### Filter lines | ||
| The returned array can also be filtered by lines. | ||
| YAML Files | ||
|
|
||
| ```Groovy | ||
| def lines = path(process.out.gzip.get(0)).linesGzip[0..5] | ||
| assert lines.size() == 6 | ||
| def lines = path(process.out.gzip.get(0)).linesGzip[0] | ||
| assert lines.equals("MY_HEADER") | ||
| ``` | ||
| Similarly, nf-test supports comparison for YAML files. To assert that two YAML files contain the same keys and values: | ||
|
|
||
| assert path(process.out.out_ch.get(0)).yaml == path('./expected_output.yaml').yaml | ||
|
|
||
|
|
||
| Individual keys can also be asserted using the same semantic logic as JSON: | ||
|
|
||
| // For a YAML structure like: | ||
| // process: | ||
| // tool: nf-test | ||
| assert path(process.out.out_ch.get(0)).yaml.process.tool == "nf-test" | ||
|
|
||
|
|
||
| GZip Files | ||
|
|
||
| nf-test extends path with a linesGzip property to read compressed files (common in bioinformatics, like .fastq.gz). | ||
|
|
||
| // Check the number of lines in a compressed FASTQ | ||
| assert path(process.out.out_ch.get(0)).linesGzip.size() == 400 | ||
|
|
||
| // Verify if a specific sequence or ID exists | ||
| assert path(process.out.out_ch.get(0)).linesGzip.contains("@read_id_001") | ||
|
|
||
|
|
||
| Filter lines | ||
|
|
||
| The returned array from a GZip file can also be filtered by lines to inspect specific ranges. | ||
|
|
||
| // Get the first 4 lines (one FASTQ record) | ||
| def record = path(process.out.gzip.get(0)).linesGzip[0..3] | ||
| assert record.size() == 4 | ||
|
|
||
| // Check if the first line is a valid header | ||
| assert record[0].startsWith("@") | ||
|
|
||
|
|
||
| Grep lines | ||
|
|
||
| ### Grep lines | ||
| nf-test also provides the possibility to grep only specific lines with the advantage that only a subset of lines need to be read (especially helpful for larger files). | ||
|
|
||
| ```Groovy | ||
| def lines = path(process.out.gzip.get(0)).grepLinesGzip(0,5) | ||
| // Grep lines 0 to 5 efficiently | ||
| def lines = path(process.out.gzip.get(0)).grepLinesGzip(0, 5) | ||
| assert lines.size() == 6 | ||
| def lines = path(process.out.gzip.get(0)).grepLineGzip(0) | ||
| assert lines.equals("MY_HEADER") | ||
| ``` | ||
|
|
||
| // Verify a specific header line content | ||
| def header = path(process.out.gzip.get(0)).grepLineGzip(0) | ||
| assert header.contains("instrument_id") | ||
|
|
||
|
|
||
| Snapshot Support | ||
|
|
||
| ### Snapshot Support | ||
| The possibility of filter lines from a *.gz file can also be combined with the snapshot functionality. | ||
| The possibility of filter lines from a *.gz file can also be combined with the snapshot functionality to ensure consistency. | ||
|
|
||
| ```Groovy | ||
| assert snapshot( | ||
| path(process.out.gzip.get(0)).linesGzip[0] | ||
| ).match() | ||
| ``` | ||
| assert snapshot(path(process.out.gzip.get(0)).linesGzip[0]).match() | ||
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.
This codeblock isn't closed. You can check your changes locally by running
mkdocs serveif you installed mkdocs :)