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):
4040def run_cmi_script (script_path : Path ):
4141 """General runner for example scripts with a main()."""
4242 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" )
4445 module .main ()
Original file line number Diff line number Diff line change 33import pytest
44from conftest import __examples_dir__ , run_cmi_script
55
6+ chapter = "ch03NiModelling"
7+ chapter_dir = Path (__examples_dir__ ) / chapter
8+ example_scripts = list (chapter_dir .rglob ("*.py" ))
69
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 ):
1815 run_cmi_script (script_path )
Original file line number Diff line number Diff line change 33import pytest
44from conftest import __examples_dir__ , run_cmi_script
55
6+ chapter = "ch05Fit2Phase"
7+ chapter_dir = Path (__examples_dir__ ) / chapter
8+ example_scripts = list (chapter_dir .rglob ("*.py" ))
69
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 ):
1515 run_cmi_script (script_path )
Original file line number Diff line number Diff line change 33import pytest
44from conftest import __examples_dir__ , run_cmi_script
55
6+ chapter = "ch06RefineCrystalStructureGen"
7+ chapter_dir = Path (__examples_dir__ ) / chapter
8+ example_scripts = list (chapter_dir .rglob ("*.py" ))
69
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 ):
1615 run_cmi_script (script_path )
Original file line number Diff line number Diff line change 33import pytest
44from conftest import __examples_dir__ , run_cmi_script
55
6+ chapter = "ch07StructuralPhaseTransitions"
7+ chapter_dir = Path (__examples_dir__ ) / chapter
8+ example_scripts = list (chapter_dir .rglob ("*.py" ))
69
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 ):
1615 run_cmi_script (script_path )
Original file line number Diff line number Diff line change 33import pytest
44from conftest import __examples_dir__ , run_cmi_script
55
6+ chapter = "ch08NPRefinement"
7+ chapter_dir = Path (__examples_dir__ ) / chapter
8+ example_scripts = list (chapter_dir .rglob ("*.py" ))
69
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 ):
1615 run_cmi_script (script_path )
Original file line number Diff line number Diff line change 33import pytest
44from conftest import __examples_dir__ , run_cmi_script
55
6+ chapter = "ch11ClusterXYZ"
7+ chapter_dir = Path (__examples_dir__ ) / chapter
8+ example_scripts = list (chapter_dir .rglob ("*.py" ))
69
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 ):
1515 run_cmi_script (script_path )
You can’t perform that action at this time.
0 commit comments