2222from diffpy .srfit .fitbase .fitrecipe import FitRecipe
2323from diffpy .srfit .fitbase .fitresults import FitResults , initializeRecipe
2424
25+ # The fit results from the recipe fixture in conftest.py
26+ expected_fitresults = """\
27+ Some quantities invalid due to missing profile uncertainty
28+ Overall (Chi2 and Reduced Chi2 invalid)
29+ ------------------------------------------------------------------------------
30+ Residual 0.00000000
31+ Contributions 0.00000000
32+ Restraints 0.00000000
33+ Chi2 0.00000000
34+ Reduced Chi2 0.00000000
35+ Rw 0.00000000
36+
37+ Variables (Uncertainties invalid)
38+ ------------------------------------------------------------------------------
39+ """
40+ expected_refined_variables = ["amplitude" , "wave_number" , "phase_shift" ]
41+
2542
2643def optimize_recipe (recipe ):
2744 recipe .fithooks [0 ].verbose = 0
@@ -30,13 +47,58 @@ def optimize_recipe(recipe):
3047 leastsq (residuals , values )
3148
3249
33- def test_compare_old_formatResults_with_new (build_recipe_one_contribution ):
50+ def test_formatResults (build_recipe_one_contribution ):
51+ recipe = build_recipe_one_contribution
52+ optimize_recipe (recipe )
53+ results = FitResults (recipe )
54+ actual_results_string = results .formatResults ()
55+ # Because slight variations in refinement, just check
56+ # that the header of the results are the same.
57+ assert expected_fitresults .strip () in actual_results_string .strip ()
58+ # check if the refined variables are in the results
59+ for expected_var in expected_refined_variables :
60+ assert expected_var in actual_results_string .strip ()
61+
62+
63+ def test_get_results_string (build_recipe_one_contribution ):
64+ recipe = build_recipe_one_contribution
65+ optimize_recipe (recipe )
66+ results = FitResults (recipe )
67+ actual_results_string = results .get_results_string ()
68+ # Because slight variations in refinement, just check
69+ # that the header of the results are the same.
70+ assert expected_fitresults .strip () in actual_results_string .strip ()
71+ # check if the refined variables are in the results
72+ for expected_var in expected_refined_variables :
73+ assert expected_var in actual_results_string .strip ()
74+
75+
76+ def test_printResults (build_recipe_one_contribution , capsys ):
77+ recipe = build_recipe_one_contribution
78+ optimize_recipe (recipe )
79+ results = FitResults (recipe )
80+ results .printResults ()
81+ actual_results = capsys .readouterr ().out
82+ # Because slight variations in refinement, just check
83+ # that the header of the results are the same.
84+ assert expected_fitresults .strip () in actual_results .strip ()
85+ # check if the refined variables are in the results
86+ for expected_var in expected_refined_variables :
87+ assert expected_var in actual_results .strip ()
88+
89+
90+ def test_print_results (build_recipe_one_contribution , capsys ):
3491 recipe = build_recipe_one_contribution
3592 optimize_recipe (recipe )
3693 results = FitResults (recipe )
37- results_dep = results .formatResults ()
38- results_new = results .get_results_string ()
39- assert results_dep == results_new
94+ results .print_results ()
95+ actual_results = capsys .readouterr ().out
96+ # Because slight variations in refinement, just check
97+ # that the header of the results are the same.
98+ assert expected_fitresults .strip () in actual_results .strip ()
99+ # check if the refined variables are in the results
100+ for expected_var in expected_refined_variables :
101+ assert expected_var in actual_results .strip ()
40102
41103
42104def testInitializeFromFileName (datafile ):
0 commit comments