-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add test to reproduce issue Signed-off-by: Fabrice Normandin <normandf@mila.quebec> * Bugfix for mila code in WSL Signed-off-by: Fabrice Normandin <normandf@mila.quebec> * Fix issue in pre-commit hook - PyCQA/docformatter#289 - PyCQA/docformatter#287 Signed-off-by: Fabrice Normandin <normandf@mila.quebec> * Remove unnecessary mock for RemoteV2 in test Signed-off-by: Fabrice Normandin <normandf@mila.quebec> * Remove unnecessary xfail mark on Windows Signed-off-by: Fabrice Normandin <normandf@mila.quebec> * Adjust the regression test files following changes Signed-off-by: Fabrice Normandin <normandf@mila.quebec> * Add xfail for flaky integration test Signed-off-by: Fabrice Normandin <normandf@mila.quebec> --------- Signed-off-by: Fabrice Normandin <normandf@mila.quebec>
- Loading branch information
Showing
6 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 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,64 @@ | ||
"""Unit tests for the `milatools.cli.code` module. | ||
TODO: There are quite a few tests in `tests/integration/test_code.py` that could be | ||
moved here, since some of them aren't exactly "integration" tests. | ||
""" | ||
|
||
from unittest.mock import AsyncMock, Mock | ||
|
||
import pytest | ||
|
||
import milatools.cli.code | ||
import milatools.cli.utils | ||
from milatools.cli.utils import running_inside_WSL | ||
from milatools.utils.compute_node import ComputeNode | ||
from milatools.utils.local_v2 import LocalV2 | ||
|
||
|
||
@pytest.fixture | ||
def pretend_to_be_in_WSL( | ||
request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch | ||
): | ||
# By default, pretend to be in WSL. Indirect parametrization can be used to | ||
# overwrite this value for a given test (as is done below). | ||
in_wsl = getattr(request, "param", True) | ||
|
||
_mock_running_inside_WSL = Mock(spec=running_inside_WSL, return_value=in_wsl) | ||
monkeypatch.setattr( | ||
milatools.cli.utils, | ||
running_inside_WSL.__name__, # type: ignore | ||
_mock_running_inside_WSL, | ||
) | ||
monkeypatch.setattr( | ||
milatools.cli.code, | ||
running_inside_WSL.__name__, # type: ignore | ||
_mock_running_inside_WSL, | ||
) | ||
return in_wsl | ||
|
||
|
||
@pytest.mark.parametrize("pretend_to_be_in_WSL", [True, False], indirect=True) | ||
@pytest.mark.asyncio | ||
async def test_code_from_WSL( | ||
monkeypatch: pytest.MonkeyPatch, pretend_to_be_in_WSL: bool | ||
): | ||
# Mock the LocalV2 class so that we can inspect the call to `LocalV2.run_async`. | ||
mock_localv2 = Mock(spec=LocalV2) | ||
monkeypatch.setattr(milatools.cli.code, LocalV2.__name__, mock_localv2) | ||
|
||
await milatools.cli.code.launch_vscode_loop( | ||
"code", Mock(spec=ComputeNode, hostname="foo"), "/bob/path" | ||
) | ||
assert isinstance(mock_localv2.run_async, AsyncMock) | ||
mock_localv2.run_async.assert_called_once_with( | ||
( | ||
*(("powershell.exe",) if pretend_to_be_in_WSL else ()), | ||
"code", | ||
"--new-window", | ||
"--wait", | ||
"--remote", | ||
"ssh-remote+foo", | ||
"/bob/path", | ||
), | ||
display=True, | ||
) |
This file contains 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 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 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