From 57132de998b8b4d7ce6c7ede1f027744ef10b783 Mon Sep 17 00:00:00 2001 From: Peter Sharpe Date: Wed, 21 May 2025 11:40:22 -0400 Subject: [PATCH 1/2] Update test_runner.py to include SPDX license headers and refactor script file collection using pathlib to fix collection errors. --- docs/test_runner.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/docs/test_runner.py b/docs/test_runner.py index cee079e2fa..29eb056551 100644 --- a/docs/test_runner.py +++ b/docs/test_runner.py @@ -1,18 +1,34 @@ -import os +# SPDX-FileCopyrightText: Copyright (c) 2023 - 2024 NVIDIA CORPORATION & AFFILIATES. +# SPDX-FileCopyrightText: All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from pathlib import Path import subprocess import pytest # Collecting all the Python files in the scripts directory -script_files = [f for f in os.listdir("test_scripts/") if f.endswith(".py")] +test_scripts_dir = Path(__file__).parent / "test_scripts" +script_files = [f for f in test_scripts_dir.glob("*.py")] + -# print(script_files) @pytest.mark.parametrize("script_file", script_files) def test_script_execution(script_file): """Test if a script runs without error.""" - filepath = os.path.join("test_scripts/", script_file) - print(filepath) - result = subprocess.run(["python", filepath], capture_output=True, text=True) + print(f"Running {script_file}") + result = subprocess.run(["python", script_file], capture_output=True, text=True) # Check that the script executed successfully assert ( From 90594daeb4ac2bb243df5f84daa825a02e991a3c Mon Sep 17 00:00:00 2001 From: Peter Sharpe Date: Wed, 21 May 2025 12:06:55 -0400 Subject: [PATCH 2/2] Temporary fix for missing PhysicsNeMo-Sym dependency (should not be required, but currently is) --- docs/test_scripts/test_custom_model_demo_1.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/test_scripts/test_custom_model_demo_1.py b/docs/test_scripts/test_custom_model_demo_1.py index 55d136bd26..1ef24f136a 100644 --- a/docs/test_scripts/test_custom_model_demo_1.py +++ b/docs/test_scripts/test_custom_model_demo_1.py @@ -70,11 +70,14 @@ class MdlsUNetMetaData(ModelMetaData): # [physicsnemo model] # [physicsnemo sym model] - -from typing import Dict, Optional - -from physicsnemo.sym.key import Key -from physicsnemo.sym.models.arch import Arch +try: + from physicsnemo.sym.key import Key + from physicsnemo.sym.models.arch import Arch +except ImportError as e: + raise ImportError( + "This optional test depends on the `physicsnemo.sym` package.\n" + "If desired, you can install it with instructions from https://github.com/NVIDIA/physicsnemo-sym." + ) from e class MdlsSymUNet(Arch): @@ -91,7 +94,7 @@ def __init__( self.mdls_model = MdlsUNet(in_channels, out_channels) # MdlsUNet defined above - def forward(self, dict_tensor: Dict[str, torch.Tensor]): + def forward(self, dict_tensor: dict[str, torch.Tensor]): x = self.concat_input( dict_tensor, self.input_key_dict,