Open
Description
Problem
The load_expected_versions()
function in test notebooks lacks proper error handling for common failure scenarios:
- FileNotFoundError: When
expected_versions.json
is not found - JSONDecodeError: When the JSON file is malformed or contains invalid JSON
Current Code Pattern
def load_expected_versions() -> dict:
lock_file = Path('./expected_versions.json')
data = {}
with open(lock_file, 'r') as file:
data = json.load(file)
return data
Proposed Solution
Add proper exception handling to provide clearer error messages:
def load_expected_versions() -> dict:
lock_file = Path('./expected_versions.json')
try:
with open(lock_file, 'r') as f:
return json.load(f)
except FileNotFoundError:
raise FileNotFoundError(f"expected_versions.json not found in {lock_file.parent}")
except json.JSONDecodeError as e:
raise ValueError(f"Invalid JSON in expected_versions.json: {e}")
Scope
This improvement should be applied systematically across all test notebook files that contain this pattern.
Context
- Original discussion: RHOAIENG-27434: Create Rocm Tensorflow Python 3.12 Image #1259 (comment)
- Identified in:
jupyter/rocm/tensorflow/ubi9-python-3.12/test/test_notebook.ipynb
- Related to issue Improve error handling in get_expected_version() functions across test notebooks #1243 which covers error handling in
get_expected_version()
function
Acceptance Criteria
- Identify all test notebook files with the
load_expected_versions()
pattern - Update all instances to include proper error handling for FileNotFoundError and JSONDecodeError
- Ensure consistent error messaging across all files
- Verify tests still pass with improved error handling
- Consider whether to fail gracefully or provide fallback behavior in test scenarios
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status