1import unittest
2from unittest.mock import mock_open, patch
3from secret import validate_recipe, RuinedNikuldenDinnerError
4
5class TestNikuldenValidator(unittest.TestCase):
6 """Test all requirements related to the function that identify specific keywords in recipe files."""
7 def test_valid_recipe(self):
8 """Test with valid recipes."""
9 valid_recipe = "С шаран или рибена супа ще почерпи Ники? Той е ценител на лукса - Сьонга ще е."
10 with patch("builtins.open", mock_open(read_data=valid_recipe)):
11 self.assertTrue(validate_recipe("valid_file.txt"))
12
13 def test_invalid_recipe(self):
14 """Test with invalid recipes."""
15 invalid_recipe = "Мислех този Никулден да минем с цаца, но Ники иска сьомга."
16 with patch("builtins.open", mock_open(read_data=invalid_recipe)):
17 self.assertFalse(validate_recipe("invalid_file.txt"))
18
19 def test_bad_recipe_file(self):
20 """Test with problem with read from file (OSError or IOError)."""
21 with patch("builtins.open", side_effect=OSError):
22 with self.assertRaises(RuinedNikuldenDinnerError):
23 validate_recipe("dummy.txt")
24
25if __name__ == '__main__':
26 unittest.main()
F.F.
======================================================================
FAIL: test_naive_in_validator (test.TestTestNikuldenValidator.test_naive_in_validator)
Test with implementation missing word splits.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 92, in test_naive_in_validator
self.assertFalse(result.wasSuccessful(),
AssertionError: True is not false : Expecting test_invalid_recipe to fail with an implementation missing word splits.
======================================================================
FAIL: test_no_lower_validator (test.TestTestNikuldenValidator.test_no_lower_validator)
Test with implementation missing lower.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 62, in test_no_lower_validator
self.assertFalse(result.wasSuccessful(),
AssertionError: True is not false : Expecting test_valid_recipe to fail with an implementation missing lower.
----------------------------------------------------------------------
Ran 4 tests in 0.052s
FAILED (failures=2)