From bc24f3449c6ae080659d6766f892a64ac9ca4488 Mon Sep 17 00:00:00 2001 From: NicolaCourtier <45851982+NicolaCourtier@users.noreply.github.com> Date: Tue, 10 Dec 2024 09:39:50 +0000 Subject: [PATCH] Loop over subfolders to test examples (#586) --- examples/scripts/battery_parameterisation/ecm_CMAES.py | 4 ++-- examples/scripts/getting_started/BPX_spm.py | 4 +--- tests/examples/test_examples.py | 7 ++++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/examples/scripts/battery_parameterisation/ecm_CMAES.py b/examples/scripts/battery_parameterisation/ecm_CMAES.py index 01d8dca0..f426eed2 100644 --- a/examples/scripts/battery_parameterisation/ecm_CMAES.py +++ b/examples/scripts/battery_parameterisation/ecm_CMAES.py @@ -4,7 +4,7 @@ # Import the ECM parameter set from JSON parameter_set = pybop.ParameterSet( - json_path="examples/scripts/parameters/initial_ecm_parameters.json" + json_path="examples/parameters/initial_ecm_parameters.json" ) parameter_set.import_parameters() @@ -81,7 +81,7 @@ # Export the parameters to JSON parameter_set.export_parameters( - "examples/scripts/parameters/fit_ecm_parameters.json", fit_params=parameters + "examples/parameters/fit_ecm_parameters.json", fit_params=parameters ) # Plot the time series diff --git a/examples/scripts/getting_started/BPX_spm.py b/examples/scripts/getting_started/BPX_spm.py index 49087da8..1fde8923 100644 --- a/examples/scripts/getting_started/BPX_spm.py +++ b/examples/scripts/getting_started/BPX_spm.py @@ -3,9 +3,7 @@ import pybop # Define model -bpx_parameters = pybop.ParameterSet( - json_path="examples/scripts/parameters/example_BPX.json" -) +bpx_parameters = pybop.ParameterSet(json_path="examples/parameters/example_BPX.json") parameter_set = bpx_parameters.import_from_bpx() model = pybop.lithium_ion.SPM(parameter_set=parameter_set) diff --git a/tests/examples/test_examples.py b/tests/examples/test_examples.py index 2bebc6fc..f3adbfea 100644 --- a/tests/examples/test_examples.py +++ b/tests/examples/test_examples.py @@ -16,9 +16,10 @@ def list_of_examples(): path_to_example_scripts = os.path.join( pybop.script_path, "..", "examples", "scripts" ) - for example in os.listdir(path_to_example_scripts): - if example.endswith(".py"): - examples_list.append(os.path.join(path_to_example_scripts, example)) + for dirpath, _, filenames in os.walk(path_to_example_scripts): + for file in filenames: + if file.endswith(".py"): + examples_list.append(os.path.join(dirpath, file)) return examples_list @pytest.mark.parametrize("example", list_of_examples())