Repository navigation
test: Convert the ethdebug schema conformity tests to unittest #17055
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| # Runs the tests validating the compiler's ethdebug output against the ethdebug/format schemas. | ||
| # Any test suite located in test/ethdebugSchemaTests/ will be executed automatically by this script. | ||
|
|
||
| import sys | ||
| from argparse import ArgumentParser | ||
| from dataclasses import dataclass | ||
| from pathlib import Path | ||
| from unittest import TestLoader, TestSuite, TextTestRunner | ||
|
|
||
| TEST_DIR = Path(__file__).parent / "ethdebugSchemaTests" | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class Config: | ||
| solc_path: Path | ||
|
|
||
|
|
||
| def test_cases(test_suite): | ||
| for test in test_suite: | ||
| if isinstance(test, TestSuite): | ||
| yield from test_cases(test) | ||
| else: | ||
| yield test | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| parser = ArgumentParser(description="Validate the compiler's ethdebug output against the ethdebug/format schemas.") | ||
| parser.add_argument("--solc-binary-path", type=Path, required=True, help="Path to the solidity compiler binary.") | ||
| parser.add_argument( | ||
| "-k", | ||
| dest="patterns", | ||
| action="append", | ||
| default=[], | ||
| help="Only run the tests whose name matches the pattern, as with `python -m unittest -k`. Can be repeated.", | ||
| ) | ||
| options = parser.parse_args() | ||
| assert options.solc_binary_path.is_file(), f"Not a file: {options.solc_binary_path}" | ||
|
|
||
| config = Config(solc_path=options.solc_binary_path) | ||
|
|
||
| # This is equivalent to `python -m unittest discover --start-directory $TEST_DIR -k ...`, | ||
| # with every test case class given the configuration. | ||
| test_loader = TestLoader() | ||
| assert test_loader.testNamePatterns is None | ||
| if len(options.patterns) > 0: | ||
| # Unlike `-k`, testNamePatterns matches a pattern without wildcards against the whole | ||
| # test name, so wrap such a pattern in wildcards to match it as a substring like `-k` does. | ||
| test_loader.testNamePatterns = [ | ||
| pattern if "*" in pattern else f"*{pattern}*" | ||
|
djolertrk marked this conversation as resolved.
Resolved
|
||
| for pattern in options.patterns | ||
| ] | ||
| test_suite = test_loader.discover(start_dir=TEST_DIR) | ||
| for test_case in test_cases(test_suite): | ||
| type(test_case).config = config | ||
| result = TextTestRunner().run(test_suite) | ||
|
|
||
| if not result.wasSuccessful(): | ||
| sys.exit(1) | ||
|
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.
I find
Yes, that's definitely a pain.
You can use
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.
I'm open to be convinced by good arguments so let's talk it through.
This is how the trade-off looks to me: Good:
Bad:
Member
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. Just to not leave this open after you spend some time thinking about it and writing it up: Aside from the additional infrastructure we maintain ourselves (custom runner, config convention, |
Uh oh!
There was an error while loading. Please reload this page.