1import unittest
2from secret import validate_recipe, RuinedNikuldenDinnerError
3from unittest.mock import patch, mock_open
4
5class TestNikuldenValidator(unittest.TestCase):
6 def test_valid_recipe(self):
7 VALID_FILE_DATA = "Супа от рибена глава със сьонга"
8 m = mock_open(read_data=VALID_FILE_DATA)
9 with patch("builtins.open", m):
10 result = validate_recipe("valid_fish_recipe.txt")
11 self.assertTrue(result)
12
13 def test_invalid_recipe(self):
14 INVALID_FILE_DATA = "Пица пеперони"
15 m = mock_open(read_data=INVALID_FILE_DATA)
16 with patch("builtins.open", m):
17 result = validate_recipe("invalid_fish_recipe.txt")
18 self.assertFalse(result)
19
20 def test_bad_recipe_file(self):
21 with patch("builtins.open", side_effect=OSError):
22 with self.assertRaises(RuinedNikuldenDinnerError):
23 validate_recipe("fish_recipe.txt")
24
25 FILE_DATA = "Супа от рибена глава със сьонга"
26 m = mock_open(read_data=FILE_DATA)
27 with patch("builtins.open", m) as mock_file:
28 mock_file.return_value.read.side_effect = IOError
29 with self.assertRaises(RuinedNikuldenDinnerError):
30 validate_recipe("fish_recipe.txt")
31
32
33if __name__ == "__main__":
34 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.027s
FAILED (failures=2)
07.12.2024 14:12