1import unittest
2from unittest.mock import mock_open, patch
3from secret import validate_recipe, RuinedNikuldenDinnerError
4
5
6class TestNikuldenValidator(unittest.TestCase):
7
8 def test_valid_recipe(self):
9 # Case containing 1/4 special words
10 recipe_content = "Тази рецепта съдържа риба и зеленчуци."
11 with patch("builtins.open", mock_open(read_data=recipe_content)):
12 self.assertTrue(validate_recipe("valid_recipe.txt"))
13
14 # Case containing 1/4 special words
15 recipe_content = "Тази рецепта е с рибена глава."
16 with patch("builtins.open", mock_open(read_data=recipe_content)):
17 self.assertTrue(validate_recipe("valid_recipe.txt"))
18
19 # Case containing 1/4 special words
20 recipe_content = "Тази рецепта съдържа сьонга."
21 with patch("builtins.open", mock_open(read_data=recipe_content)):
22 self.assertTrue(validate_recipe("valid_recipe.txt"))
23
24 # Case containing 1/4 special words
25 recipe_content = "Тази рецепта съдържа шаран."
26 with patch("builtins.open", mock_open(read_data=recipe_content)):
27 self.assertTrue(validate_recipe("valid_recipe.txt"))
28
29 # Case-insensitive
30 recipe_content = "Тази рецепта съдържа шАрАн."
31 with patch("builtins.open", mock_open(read_data=recipe_content)):
32 self.assertTrue(validate_recipe("valid_recipe.txt"))
33
34 def test_invalid_recipe(self):
35 recipe_content = "Тази рецепта съдържа човешко месо."
36 with patch("builtins.open", mock_open(read_data=recipe_content)):
37 self.assertFalse(validate_recipe("invalid_recipe.txt"))
38
39 recipe_content = "Тази рецепта съдържа шараннннн."
40 with patch("builtins.open", mock_open(read_data=recipe_content)):
41 self.assertFalse(validate_recipe("invalid_recipe.txt"))
42
43 recipe_content = "Тази рецепта съдържа сьомга."
44 with patch("builtins.open", mock_open(read_data=recipe_content)):
45 self.assertFalse(validate_recipe("invalid_recipe.txt"))
46
47 def test_bad_recipe_file(self):
48 with patch("builtins.open", side_effect=OSError):
49 with self.assertRaises(RuinedNikuldenDinnerError):
50 validate_recipe("bad_file.txt")
51
52 with patch("builtins.open", side_effect=IOError):
53 with self.assertRaises(RuinedNikuldenDinnerError):
54 validate_recipe("bad_file.txt")
....
----------------------------------------------------------------------
Ran 4 tests in 0.040s
OK
07.12.2024 13:00