-
Notifications
You must be signed in to change notification settings - Fork 0
Add testing for deploy and unit testing #17
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
Conversation
Add additional tests targeting deploy testing and unit testing focusing on usability and robustness. * **Unit Tests** - Add `cacts/tests/test_build_type.py` to test `BuildType` class, covering initialization, parameter updates, `expand_variables`, `evaluate_commands`, and `str_to_bool` methods. - Add `cacts/tests/test_cacts.py` to test `Driver` class, covering initialization, `run`, `generate_cmake_config`, `generate_ctest_cmd` methods, and `parse_command_line` function. - Add `cacts/tests/test_machine.py` to test `Machine` class, covering initialization, parameter updates, and `uses_gpu` method. - Add `cacts/tests/test_project.py` to test `Project` class, covering initialization, parameter updates, and `__post_init__` method. - Add `cacts/tests/test_utils.py` to test utility functions in `utils.py`, covering `expect`, `run_cmd`, `run_cmd_no_fail`, `expand_variables`, `evaluate_commands`, `str_to_bool`, and `is_git_repo` functions. * **Shell-based Tests** - Add `cacts/tests/test_deploy.sh` to cover deployment scenarios, including installing dependencies, running the application, and verifying the application's output and behavior. * **CI Pipeline** - Update `.github/workflows/test.yaml` to include the new test files in the CI pipeline. - Add a new step to run the shell-based test script `test_deploy.sh`. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/E3SM-Project/cacts?shareId=XXXX-XXXX-XXXX-XXXX).
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.
Pull Request Overview
This PR adds a comprehensive suite of tests for deploy functionality and the core classes of the project to improve robustness and usability.
- Added unit tests covering BuildType, Project, Machine, Driver, and various utility functions.
- Introduced shell-based deployment tests.
- Updated the CI pipeline to include the new tests.
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
cacts/tests/test_utils.py | Adds tests for utility functions including shell command execution and variable expansion. |
cacts/tests/test_project.py | Introduces tests for the Project class covering initialization and post-initialization. |
cacts/tests/test_machine.py | Implements tests for Machine functionality including GPU usage verification. |
cacts/tests/test_cacts.py | Provides tests for the Driver class and command-line parsing functions. |
cacts/tests/test_build_type.py | Tests BuildType functionality including initialization, variable expansion, and command evaluation. |
.github/workflows/test.yaml | Updates the CI pipeline to install dependencies and run both Python and shell-based tests. |
Files not reviewed (1)
- cacts/tests/test_deploy.sh: Language not supported
Comments suppressed due to low confidence (2)
cacts/tests/test_utils.py:9
- The test assumes that run_cmd trims newline characters from the echo output; please verify that this behavior is consistent across different shell environments.
stat, output, errput = run_cmd("echo Hello, World!")
cacts/tests/test_build_type.py:41
- Verify that the merging logic for cmake_args between the default and test_build specifications is intentional and handles potential key conflicts appropriately.
assert build_type.cmake_args == {'arg1': 'value1', 'arg2': 'value2'}
* **Run tests** - Update the `Run tests` step to use `uv` to run `pytest` * **Run shell-based deployment tests** - Update the `Run shell-based deployment tests` step to use `uv` to run `test_deploy.sh` * **Remove Install dependencies step** - Remove the step to install `uv` and set the python version
else: | ||
return cpu_count | ||
if platform.system() == "Darwin": # macOS | ||
cpu_count = os.cpu_count() # Fallback for macOS |
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 returns all the cpus on the node. We may not want this.
@@ -0,0 +1,4 @@ | |||
from . import main |
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.
doesn't the pyproject.toml file already define the cacts
program?
project = types.SimpleNamespace(name="TestProject") | ||
machine = types.SimpleNamespace(name="TestMachine", env_setup=["echo 'Setting up environment'"]) | ||
builds_specs = { | ||
'default': { |
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.
We should add some ${}
and $()
syntax in the specs, to make sure that evaluate_commands and expand_variables work correctly.
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.
Also, given that ${}
allow to execute py code, we should prob call it evaluate_py_expressions
, and evaluate_commands
should be evaluate_sh_expressions
...or something. But that can wait.
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.
I mean, we do have unit tests for expand/evaluate, but I wonder if that's enough, or if we should verify they are used correctly in the BT init...
def machine(): | ||
project = MockProject() | ||
machines_specs = { | ||
'default': { |
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.
maybe we can add some ${}
and $()
here too, and check that Machine init does the expansion correctly..
def test_run_cmd_no_fail(): | ||
output = run_cmd_no_fail("echo Hello, World!") | ||
assert output == "Hello, World!" | ||
|
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.
I would also test that
with pytest.raises(RuntimeError): | |
run_cmd_no_fail("false") | |
to check that this throws.
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 is great! I have some comments. Not sure how much we want to refine now. Maybe it's better to add something now, and expand later..
Add additional tests targeting deploy testing and unit testing focusing on usability and robustness.
Unit Tests
cacts/tests/test_build_type.py
to testBuildType
class, covering initialization, parameter updates,expand_variables
,evaluate_commands
, andstr_to_bool
methods.cacts/tests/test_cacts.py
to testDriver
class, covering initialization,run
,generate_cmake_config
,generate_ctest_cmd
methods, andparse_command_line
function.cacts/tests/test_machine.py
to testMachine
class, covering initialization, parameter updates, anduses_gpu
method.cacts/tests/test_project.py
to testProject
class, covering initialization, parameter updates, and__post_init__
method.cacts/tests/test_utils.py
to test utility functions inutils.py
, coveringexpect
,run_cmd
,run_cmd_no_fail
,expand_variables
,evaluate_commands
,str_to_bool
, andis_git_repo
functions.Shell-based Tests
cacts/tests/test_deploy.sh
to cover deployment scenarios, including installing dependencies, running the application, and verifying the application's output and behavior.CI Pipeline
.github/workflows/test.yaml
to include the new test files in the CI pipeline.test_deploy.sh
.For more details, open the Copilot Workspace session.