File tree Expand file tree Collapse file tree 7 files changed +50
-55
lines changed Expand file tree Collapse file tree 7 files changed +50
-55
lines changed Original file line number Diff line number Diff line change @@ -40,5 +40,6 @@ def load_module_from_path(path: Path):
40
40
def run_cmi_script (script_path : Path ):
41
41
"""General runner for example scripts with a main()."""
42
42
module = load_module_from_path (script_path )
43
- assert hasattr (module , "main" ), f"{ script_path } has no main() function"
43
+ if not hasattr (module , "main" ):
44
+ pytest .skip (f"{ script_path } has no main() function" )
44
45
module .main ()
Original file line number Diff line number Diff line change 3
3
import pytest
4
4
from conftest import __examples_dir__ , run_cmi_script
5
5
6
+ chapter = "ch03NiModelling"
7
+ chapter_dir = Path (__examples_dir__ ) / chapter
8
+ example_scripts = list (chapter_dir .rglob ("*.py" ))
6
9
7
- @pytest .mark .parametrize (
8
- "relative_path" ,
9
- [
10
- f"{ __examples_dir__ } /ch03NiModelling"
11
- + "/solutions/diffpy-cmi/fitBulkNi.py" ,
12
- f"{ __examples_dir__ } /ch03NiModelling"
13
- + "/solutions/diffpy-cmi/fitNPPt.py" ,
14
- ],
15
- )
16
- def test_ch03_examples (relative_path ):
17
- script_path = Path (__file__ ).parent .parent / relative_path
10
+
11
+ # Runs all example scripts in chapter 3, skips files in main() is not defined.
12
+ # Passes if script runs without error.
13
+ @pytest .mark .parametrize ("script_path" , example_scripts , ids = lambda p : p .name )
14
+ def test_ch03_examples (script_path ):
18
15
run_cmi_script (script_path )
Original file line number Diff line number Diff line change 3
3
import pytest
4
4
from conftest import __examples_dir__ , run_cmi_script
5
5
6
+ chapter = "ch05Fit2Phase"
7
+ chapter_dir = Path (__examples_dir__ ) / chapter
8
+ example_scripts = list (chapter_dir .rglob ("*.py" ))
6
9
7
- @pytest .mark .parametrize (
8
- "relative_path" ,
9
- [
10
- f"{ __examples_dir__ } /ch05Fit2Phase/solutions/diffpy-cmi/fit2P.py" ,
11
- ],
12
- )
13
- def test_ch05_examples (relative_path ):
14
- script_path = Path (__file__ ).parent .parent / relative_path
10
+
11
+ # Runs all example scripts in chapter 5, skips files in main() is not defined.
12
+ # Passes if script runs without error.
13
+ @pytest .mark .parametrize ("script_path" , example_scripts , ids = lambda p : p .name )
14
+ def test_ch03_examples (script_path ):
15
15
run_cmi_script (script_path )
Original file line number Diff line number Diff line change 3
3
import pytest
4
4
from conftest import __examples_dir__ , run_cmi_script
5
5
6
+ chapter = "ch06RefineCrystalStructureGen"
7
+ chapter_dir = Path (__examples_dir__ ) / chapter
8
+ example_scripts = list (chapter_dir .rglob ("*.py" ))
6
9
7
- @pytest .mark .parametrize (
8
- "relative_path" ,
9
- [
10
- f"{ __examples_dir__ } /ch06RefineCrystalStructureGen"
11
- + "/solutions/diffpy-cmi/fitCrystalGen.py" ,
12
- ],
13
- )
14
- def test_ch06_examples (relative_path ):
15
- script_path = Path (__file__ ).parent .parent / relative_path
10
+
11
+ # Runs all example scripts in chapter 6, skips files in main() is not defined.
12
+ # Passes if script runs without error.
13
+ @pytest .mark .parametrize ("script_path" , example_scripts , ids = lambda p : p .name )
14
+ def test_ch03_examples (script_path ):
16
15
run_cmi_script (script_path )
Original file line number Diff line number Diff line change 3
3
import pytest
4
4
from conftest import __examples_dir__ , run_cmi_script
5
5
6
+ chapter = "ch07StructuralPhaseTransitions"
7
+ chapter_dir = Path (__examples_dir__ ) / chapter
8
+ example_scripts = list (chapter_dir .rglob ("*.py" ))
6
9
7
- @pytest .mark .parametrize (
8
- "relative_path" ,
9
- [
10
- f"{ __examples_dir__ } /ch07StructuralPhaseTransitions"
11
- + "/solutions/diffpy-cmi/fitTSeries.py" ,
12
- ],
13
- )
14
- def test_ch07_examples (relative_path ):
15
- script_path = Path (__file__ ).parent .parent / relative_path
10
+
11
+ # Runs all example scripts in chapter 7, skips files in main() is not defined.
12
+ # Passes if script runs without error.
13
+ @pytest .mark .parametrize ("script_path" , example_scripts , ids = lambda p : p .name )
14
+ def test_ch03_examples (script_path ):
16
15
run_cmi_script (script_path )
Original file line number Diff line number Diff line change 3
3
import pytest
4
4
from conftest import __examples_dir__ , run_cmi_script
5
5
6
+ chapter = "ch08NPRefinement"
7
+ chapter_dir = Path (__examples_dir__ ) / chapter
8
+ example_scripts = list (chapter_dir .rglob ("*.py" ))
6
9
7
- @pytest .mark .parametrize (
8
- "relative_path" ,
9
- [
10
- f"{ __examples_dir__ } /ch08NPRefinement"
11
- + "/solutions/diffpy-cmi/fitCdSeNP.py" ,
12
- ],
13
- )
14
- def test_ch08_examples (relative_path ):
15
- script_path = Path (__file__ ).parent .parent / relative_path
10
+
11
+ # Runs all example scripts in chapter 8, skips files in main() is not defined.
12
+ # Passes if script runs without error.
13
+ @pytest .mark .parametrize ("script_path" , example_scripts , ids = lambda p : p .name )
14
+ def test_ch03_examples (script_path ):
16
15
run_cmi_script (script_path )
Original file line number Diff line number Diff line change 3
3
import pytest
4
4
from conftest import __examples_dir__ , run_cmi_script
5
5
6
+ chapter = "ch11ClusterXYZ"
7
+ chapter_dir = Path (__examples_dir__ ) / chapter
8
+ example_scripts = list (chapter_dir .rglob ("*.py" ))
6
9
7
- @pytest .mark .parametrize (
8
- "relative_path" ,
9
- [
10
- f"{ __examples_dir__ } /ch11ClusterXYZ/solutions/diffpy-cmi/fitCdSeNP.py" ,
11
- ],
12
- )
13
- def test_ch11_examples (relative_path ):
14
- script_path = Path (__file__ ).parent .parent / relative_path
10
+
11
+ # Runs all example scripts in chapter 11, skips files in main() is not defined.
12
+ # Passes if script runs without error.
13
+ @pytest .mark .parametrize ("script_path" , example_scripts , ids = lambda p : p .name )
14
+ def test_ch03_examples (script_path ):
15
15
run_cmi_script (script_path )
You can’t perform that action at this time.
0 commit comments