-
Notifications
You must be signed in to change notification settings - Fork 716
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: wei-chenglai <[email protected]>
- Loading branch information
Showing
10 changed files
with
69 additions
and
146 deletions.
There are no files selected for viewing
File renamed without changes.
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
File renamed without changes.
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
Empty file.
Empty file.
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 |
---|---|---|
@@ -1,6 +0,0 @@ | ||
import os | ||
import sys | ||
|
||
sys.path.insert( | ||
0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../")) | ||
) | ||
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,55 @@ | ||
import os | ||
import shutil | ||
import tempfile | ||
|
||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def setup_temp_path(monkeypatch): | ||
"""Creates temporary directory and patches path constant. | ||
This fixture: | ||
1. Creates a temporary directory | ||
2. Allows configuration of path constant | ||
3. Handles automatic cleanup after tests | ||
4. Restores original environment state | ||
Args: | ||
monkeypatch: pytest fixture for modifying objects | ||
Returns: | ||
function: A configurator that accepts path_var (str) and returns temp_dir path | ||
Usage: | ||
def test_something(setup_temp_path): | ||
temp_dir = setup_temp_path("MODEL_PATH") | ||
# temp_dir is created and MODEL_PATH is patched | ||
# cleanup happens automatically after test | ||
""" | ||
# Setup | ||
original_env = dict(os.environ) | ||
current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
temp_dir = tempfile.mkdtemp(dir=current_dir) | ||
|
||
def configure_path(path_var: str): | ||
"""Configure path variable in kubeflow.training""" | ||
import kubeflow.training as training | ||
|
||
monkeypatch.setattr(training, path_var, temp_dir) | ||
return temp_dir | ||
|
||
yield configure_path | ||
|
||
# Cleanup temp directory after test | ||
shutil.rmtree(temp_dir, ignore_errors=True) | ||
os.environ.clear() | ||
os.environ.update(original_env) | ||
|
||
|
||
def verify_downloaded_files(dir_path, expected_files): | ||
"""Verify downloaded files""" | ||
if expected_files: | ||
actual_files = set(os.listdir(dir_path)) | ||
missing_files = set(expected_files) - actual_files | ||
assert not missing_files, f"Missing expected files: {missing_files}" |