Skip to content

Commit 4b60d8a

Browse files
committed
add test for ValueError
1 parent 9c9fdc3 commit 4b60d8a

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/diffpy/srfit/fitbase/fitrecipe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ def initialize_recipe_with_recipe(self, recipe_object):
11621162
if not isinstance(recipe_object, FitRecipe):
11631163
raise ValueError(
11641164
"The input recipe_object must be a FitRecipe, "
1165-
f"but got {type(recipe_object)}"
1165+
f"but got {type(recipe_object)}."
11661166
)
11671167

11681168
for contrib_object in recipe_object._contributions.values():

tests/test_fitrecipe.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,19 @@ def test_initialize_recipe_from_recipe(build_recipe_two_contributions):
514514
assert sorted(list(expected_values)) == sorted(list(actual_values))
515515

516516

517+
def test_initialize_recipe_from_recipe_bad(build_recipe_two_contributions):
518+
# Case: User tries to initialize a FitRecipe from a non recipe object
519+
# expected: raised ValueError with message
520+
recipe_bad = 12345 # not a FitRecipe object
521+
recipe2 = FitRecipe()
522+
msg = (
523+
"The input recipe_object must be a FitRecipe, "
524+
"but got <class 'int'>."
525+
)
526+
with pytest.raises(ValueError, match=msg):
527+
recipe2.initialize_recipe_with_recipe(recipe_bad)
528+
529+
517530
# def test_initialize_recipe_from_results(build_recipe_one_contribution):
518531
# # Case: User initializes a FitRecipe from a FitResults object or
519532
# # results file

0 commit comments

Comments
 (0)