-
Notifications
You must be signed in to change notification settings - Fork 23
Improve test coverage for tools
#365
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 7 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
8d34ebd
Exclude tests from test coverage report
sondrebr 90e115c
Improved config file handling when running pytest
sondrebr 3164f0c
Update run_cmd and run_subprocess tests
sondrebr fbda75a
Add tests for tools/args.py
sondrebr 78322d1
Add tests for tools/build_params.py
sondrebr 55e4836
Add tests for tools/commands.py
sondrebr ff5bb3d
Add "Third party imports" comment for pytest
sondrebr 44e89a0
Fix hound issues
sondrebr 876b662
Additional tests for tools/job_metadata.py
sondrebr 2a303e7
Add tests for tools/logging.py
sondrebr 8314252
Add tests for tools/permissions.py
sondrebr 13c4039
Replace tmpdir (legacy) with tmp_path
sondrebr 0f47252
Apply suggestion from code review
sondrebr cbacfa2
Update conftest.py authors
sondrebr def659e
Apply suggested formatting change
sondrebr 387d4d7
Add test cases for contains_any_bot_command
sondrebr e0bbc93
Add test cases for get_bot_command
sondrebr 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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [run] | ||
| omit = tests/* |
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
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
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
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,85 @@ | ||
| # Tests for 'tools/args.py' of the EESSI build-and-deploy bot, | ||
| # see https://github.com/EESSI/eessi-bot-software-layer | ||
| # | ||
| # The bot helps with requests to add software installations to the | ||
| # EESSI software layer, see https://github.com/EESSI/software-layer | ||
| # | ||
| # author: Sondre Bergsvaag Risanger (@sondrebr) | ||
| # | ||
| # license: GPLv2 | ||
| # | ||
|
|
||
| # Standard library imports | ||
| from argparse import Namespace | ||
| from contextlib import nullcontext | ||
|
|
||
| # Third party imports (anything installed into the local Python environment) | ||
| import pytest | ||
|
|
||
| # Local application imports (anything from EESSI/eessi-bot-software-layer) | ||
| from tools import args | ||
|
|
||
|
|
||
| # Test parse_common_args() | ||
| @pytest.mark.parametrize("test_args,expected_parsed,expected_unknown", [ | ||
| # No args | ||
| ([], Namespace(debug=False), []), | ||
|
|
||
| # Short-form args | ||
| (["-d"], Namespace(debug=True), []), | ||
|
|
||
| # Long-form args | ||
| (["--debug"], Namespace(debug=True), []), | ||
|
|
||
| # Unknown args | ||
| (["-u", "--unknown"], Namespace(debug=False), ["-u", "--unknown"]), | ||
| ]) | ||
| def test_parse_common_args(test_args, expected_parsed, expected_unknown): | ||
| parsed_args, unknown = args.parse_common_args(test_args) | ||
|
|
||
| assert parsed_args == expected_parsed | ||
| assert sorted(unknown) == sorted(expected_unknown) | ||
|
|
||
|
|
||
| # Test event_handler_parse() | ||
| @pytest.mark.parametrize("test_args,expectation", [ | ||
| # No args | ||
| ([], nullcontext(Namespace(debug=False, build=False, test=False, cron=False, file=None, port=3000))), | ||
|
|
||
| # Short-form args | ||
| (["-d", "-b", "-t", "-c", "-f", "file.json", "-p", "8000"], | ||
| nullcontext(Namespace(debug=True, build=True, test=True, cron=True, file="file.json", port="8000"))), | ||
|
|
||
| # Long-form args | ||
| (["--debug", "--build", "--test", "--cron", "--file", "file2.json", "--port", "9000"], | ||
| nullcontext(Namespace(debug=True, build=True, test=True, cron=True, file="file2.json", port="9000"))), | ||
|
|
||
| # Unknown args - should fail and exit | ||
| (["-u"], pytest.raises(SystemExit)), | ||
| (["--unknown"], pytest.raises(SystemExit)), | ||
| ]) | ||
| def test_event_handler_parse_known_args(test_args, expectation): | ||
| with expectation as expected: | ||
| assert args.event_handler_parse(test_args) == expected | ||
|
|
||
|
|
||
| # Test job_manager_parse() | ||
| @pytest.mark.parametrize("test_args,expectation", [ | ||
| # No args | ||
| ([], nullcontext(Namespace(debug=False, max_manager_iterations=-1, jobs=None))), | ||
|
|
||
| # Short-form args | ||
| (["-d", "-i", "0", "-j", "17"], | ||
| nullcontext(Namespace(debug=True, max_manager_iterations="0", jobs="17"))), | ||
|
|
||
| # Long-form args | ||
| (["--debug", "--max-manager-iterations", "10", "--jobs", "4,18,48"], | ||
| nullcontext(Namespace(debug=True, max_manager_iterations="10", jobs="4,18,48"))), | ||
|
|
||
| # Unknown args - should fail and exit | ||
| (["-u"], pytest.raises(SystemExit)), | ||
| (["--unknown"], pytest.raises(SystemExit)), | ||
| ]) | ||
| def test_job_manager_parse_known_args(test_args, expectation): | ||
| with expectation as expected: | ||
| assert args.job_manager_parse(test_args) == 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,43 @@ | ||
| # Tests for 'tools/build_params.py' of the EESSI build-and-deploy bot, | ||
| # see https://github.com/EESSI/eessi-bot-software-layer | ||
| # | ||
| # The bot helps with requests to add software installations to the | ||
| # EESSI software layer, see https://github.com/EESSI/software-layer | ||
| # | ||
| # author: Sondre Bergsvaag Risanger (@sondrebr) | ||
| # | ||
| # license: GPLv2 | ||
| # | ||
|
|
||
| # Standard library imports | ||
| from contextlib import nullcontext | ||
|
|
||
| # Third party imports (anything installed into the local Python environment) | ||
| import pytest | ||
|
|
||
| # Local application imports (anything from EESSI/eessi-bot-software-layer) | ||
| from tools import build_params | ||
|
|
||
|
|
||
| # Test EESSIBotBuildParams class | ||
| @pytest.mark.parametrize("build_parameters,expectation", [ | ||
| # Test value error | ||
| ("notaparam", pytest.raises(build_params.EESSIBotBuildParamsValueError)), | ||
|
|
||
| # Test name error | ||
| ("thisparam=doesnotexist", pytest.raises(build_params.EESSIBotBuildParamsNameError)), | ||
|
|
||
| # Test complete component names | ||
| ("architecture=x86_64/amd/zen4,accelerator=nvidia/cc80", | ||
| nullcontext({"architecture": "x86_64/amd/zen4", "accelerator": "nvidia/cc80"})), | ||
|
|
||
| # Test shortened component names | ||
| ("arch=aarch64/nvidia/grace,accel=nvidia/cc90", | ||
| nullcontext({"architecture": "aarch64/nvidia/grace", "accelerator": "nvidia/cc90"})), | ||
| ]) | ||
| def test_EESSIBotBuildParams(build_parameters, expectation): | ||
| with expectation as expected_params: | ||
| params = build_params.EESSIBotBuildParams(build_parameters) | ||
| # Verify that the resulting object contains the expected items | ||
| for name, expected_value in expected_params.items(): | ||
| assert params[name] == expected_value |
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.
Uh oh!
There was an error while loading. Please reload this page.