-
Notifications
You must be signed in to change notification settings - Fork 24
Adding simple unit tests that use the full CLI #46
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9d5d5aa
Adding simple tests that run the full CLI.
494c59b
Merge branch 'master' into cli_test
f13b90d
Updating from master.
c7490dc
Just using a symlink to avoid duplication.
a0f21fb
Fixing ruff format errors.
784b217
Apply suggestion from @henryiii
henryiii dcb0c0d
Refactor cli tests to improve file handling
henryiii cd5402a
Add import for sys module in cli_test.py
henryiii e392108
Refactor test_simple_header_cli with parameterization
henryiii 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
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 |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| from pathlib import Path | ||
| from tempfile import NamedTemporaryFile | ||
| from os import system | ||
|
|
||
| DIR = Path(__file__).absolute().parents[0] | ||
|
|
||
| expected = """\ | ||
| /* | ||
| This file contains docstrings for use in the Python bindings. | ||
| Do not edit! They were automatically extracted by pybind11_mkdoc. | ||
| */ | ||
|
|
||
| #define MKD_EXPAND(x) x | ||
| #define MKD_COUNT(_1, _2, _3, _4, _5, _6, _7, COUNT, ...) COUNT | ||
| #define MKD_VA_SIZE(...) MKD_EXPAND(MKD_COUNT(__VA_ARGS__, 7, 6, 5, 4, 3, 2, 1, 0)) | ||
| #define MKD_CAT1(a, b) a ## b | ||
| #define MKD_CAT2(a, b) MKD_CAT1(a, b) | ||
| #define MKD_DOC1(n1) mkd_doc_##n1 | ||
| #define MKD_DOC2(n1, n2) mkd_doc_##n1##_##n2 | ||
| #define MKD_DOC3(n1, n2, n3) mkd_doc_##n1##_##n2##_##n3 | ||
| #define MKD_DOC4(n1, n2, n3, n4) mkd_doc_##n1##_##n2##_##n3##_##n4 | ||
| #define MKD_DOC5(n1, n2, n3, n4, n5) mkd_doc_##n1##_##n2##_##n3##_##n4##_##n5 | ||
| #define MKD_DOC7(n1, n2, n3, n4, n5, n6, n7) mkd_doc_##n1##_##n2##_##n3##_##n4##_##n5##_##n6##_##n7 | ||
| #define DOC(...) MKD_EXPAND(MKD_EXPAND(MKD_CAT2(MKD_DOC, MKD_VA_SIZE(__VA_ARGS__)))(__VA_ARGS__)) | ||
|
|
||
| #if defined(__GNUG__) | ||
| #pragma GCC diagnostic push | ||
| #pragma GCC diagnostic ignored "-Wunused-variable" | ||
| #endif | ||
|
|
||
|
|
||
| static const char *mkd_doc_RootLevelSymbol = | ||
| R"doc(Root-level symbol. Magna fermentum iaculis eu non diam phasellus | ||
| vestibulum.)doc"; | ||
|
|
||
| static const char *mkd_doc_drake_MidLevelSymbol = | ||
| R"doc(1. Begin first ordered list element. Rutrum quisque non tellus orci ac | ||
| auctor. End first ordered list element. 2. Begin second ordered list | ||
| element. Ipsum faucibus vitae aliquet nec. Ligula ullamcorper | ||
| malesuada proin libero. End second ordered list element. 3. Begin | ||
| third ordered list element. Dictum sit amet justo donec enim. Pharetra | ||
| convallis posuere morbi leo urna molestie. End third ordered list | ||
| element. | ||
|
|
||
| Senectus et netus et malesuada fames ac. Tincidunt lobortis feugiat | ||
| vivamus at augue eget arcu dictum varius.)doc"; | ||
|
|
||
| #if defined(__GNUG__) | ||
| #pragma GCC diagnostic pop | ||
| #endif | ||
|
|
||
| """ | ||
|
|
||
|
|
||
| def test_simple_header_cli(): | ||
| # Run pybind11-mkdoc and put the output in a temp file | ||
| tf = NamedTemporaryFile(suffix=".h") | ||
| header = DIR / "sample_header_docs" / "sample_header.h" | ||
| exit_code = system(f"python -m pybind11_mkdoc -o {tf.name} {header}") | ||
|
|
||
| # Ensure pybind11-mkdoc ran successfully | ||
| assert exit_code == 0 | ||
|
|
||
| # Ensure the header file matches | ||
| with open(tf.name, "r") as f: | ||
| res = f.read() | ||
|
|
||
| assert res == expected | ||
|
|
||
| def test_simple_header_with_spaces_cli(): | ||
| # Run pybind11-mkdoc and put the output in a temp file | ||
| tf = NamedTemporaryFile(suffix=".h") | ||
| header = DIR / "sample_header_docs" / "sample header with spaces.h" | ||
| exit_code = system(f"python -m pybind11_mkdoc -o {tf.name} \"{header}\"") | ||
|
|
||
| # Ensure pybind11-mkdoc ran successfully | ||
| assert exit_code == 0 | ||
|
|
||
| # Ensure the header file matches | ||
| with open(tf.name, "r") as f: | ||
| res = f.read() | ||
|
|
||
| assert res == expected | ||
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| sample_header.h |
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.
Uh oh!
There was an error while loading. Please reload this page.