-
Notifications
You must be signed in to change notification settings - Fork 20
test: expand coverage and add bug fix test #2103
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 all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d0bc4e0
test: expand coverage and add bug fix test
RyanJWard 4523749
chore: adding changelog file 2103.test.md [dependabot-skip]
pyansys-ci-bot b086c22
removing failing parameters
RyanJWard 146ad66
Merge branch 'test/bug_fix_test_plus_expanded_coverage' of https://gi…
RyanJWard 393bad3
remove test, it worked locally
RyanJWard 6ad82b1
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] f42d5b4
more bug fix tests
RyanJWard 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 @@ | ||
Expand coverage and add bug fix test |
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
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,133 @@ | ||
# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates. | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
|
||
import pytest | ||
|
||
from ansys.geometry.core.connection.launcher import ( | ||
_launch_with_automatic_detection, | ||
_launch_with_launchmode, | ||
) | ||
|
||
|
||
def dummy_launcher(**kwargs): | ||
"""Dummy launcher function to simulate a launch without actually doing anything.""" | ||
return f"Dummy launcher called with args: {kwargs}" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"mode,expected_result", | ||
[ | ||
("pypim", "Dummy launcher called with args: {}"), | ||
("docker", "Dummy launcher called with args: {}"), | ||
("core_service", "Dummy launcher called with args: {}"), | ||
("geometry_service", "Dummy launcher called with args: {}"), | ||
("spaceclaim", "Dummy launcher called with args: {}"), | ||
("discovery", "Dummy launcher called with args: {}"), | ||
], | ||
) | ||
def test_launch_with_launchmode_no_launch(monkeypatch, mode, expected_result): | ||
"""Test _launch_with_launchmode without actually launching anything.""" | ||
|
||
# Override the launch functions with the dummy_launcher | ||
monkeypatch.setattr( | ||
"ansys.geometry.core.connection.launcher.launch_remote_modeler", dummy_launcher | ||
) | ||
monkeypatch.setattr( | ||
"ansys.geometry.core.connection.launcher.launch_docker_modeler", dummy_launcher | ||
) | ||
monkeypatch.setattr( | ||
"ansys.geometry.core.connection.launcher.launch_modeler_with_core_service", dummy_launcher | ||
) | ||
monkeypatch.setattr( | ||
"ansys.geometry.core.connection.launcher.launch_modeler_with_geometry_service", | ||
dummy_launcher, | ||
) | ||
monkeypatch.setattr( | ||
"ansys.geometry.core.connection.launcher.launch_modeler_with_spaceclaim", dummy_launcher | ||
) | ||
monkeypatch.setattr( | ||
"ansys.geometry.core.connection.launcher.launch_modeler_with_discovery", dummy_launcher | ||
) | ||
RobPasMue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Call the function and verify the result | ||
result = _launch_with_launchmode(mode) | ||
assert result == expected_result | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"invalid_mode,expected_exception", | ||
[ | ||
("invalid_mode", ValueError), | ||
("", ValueError), | ||
(None, TypeError), # Expect TypeError for None | ||
], | ||
) | ||
def test_launch_with_launchmode_invalid_mode(monkeypatch, invalid_mode, expected_exception): | ||
"""Test _launch_with_launchmode with invalid modes.""" | ||
with pytest.raises( | ||
expected_exception, match="Invalid launch mode|The launch mode must be a string" | ||
): | ||
_launch_with_launchmode(invalid_mode) | ||
|
||
|
||
def dummy_launch_docker_modeler(**kwargs): | ||
"""Dummy function to simulate launching the Docker modeler.""" | ||
return "Dummy Docker Modeler Launched" | ||
|
||
|
||
def test_launch_with_docker_detection(monkeypatch): | ||
"""Test Docker detection and fallback logic without launching anything.""" | ||
|
||
# Simulate Docker being available | ||
monkeypatch.setattr("ansys.geometry.core.connection.docker_instance._HAS_DOCKER", True) | ||
monkeypatch.setattr( | ||
"ansys.geometry.core.connection.docker_instance.LocalDockerInstance.is_docker_installed", | ||
lambda: True, | ||
) | ||
|
||
# Replace the launch_docker_modeler function with a dummy function | ||
monkeypatch.setattr( | ||
"ansys.geometry.core.connection.launcher.launch_docker_modeler", | ||
dummy_launch_docker_modeler, | ||
) | ||
|
||
# Call the function and verify the result | ||
result = _launch_with_automatic_detection() | ||
assert result == "Dummy Docker Modeler Launched" | ||
|
||
|
||
def test_docker_not_available(monkeypatch): | ||
"""Test fallback logic when Docker is not available.""" | ||
|
||
# Simulate Docker not being available | ||
monkeypatch.setattr("ansys.geometry.core.connection.docker_instance._HAS_DOCKER", False) | ||
|
||
# Replace the launch_docker_modeler function with a dummy function | ||
monkeypatch.setattr( | ||
"ansys.geometry.core.connection.launcher.launch_docker_modeler", | ||
dummy_launch_docker_modeler, | ||
) | ||
|
||
# Call the function and verify that it raises NotImplementedError | ||
with pytest.raises(NotImplementedError, match="Geometry service cannot be initialized."): | ||
_launch_with_automatic_detection() |
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.