1import unittest
2from unittest.mock import patch, mock_open
3from secret import validate_recipe, RuinedNikuldenDinnerError
4
5class TestNikuldenValidator(unittest.TestCase):
6 def test_valid_recipe(self):
7 mock_content = "Айде от мен да мине, сготвих рибена чорба и СЬОНГА."
8 with patch("builtins.open", mock_open(read_data=mock_content)):
9 result = validate_recipe("някъв_файл.txt")
10 self.assertTrue(result)
11
12 def test_invalid_recipe(self):
13 mock_content = "Аз тва не го ям, направих си пържоли."
14 with patch("builtins.open", mock_open(read_data=mock_content)):
15 result = validate_recipe("някъв_файл.txt")
16 self.assertFalse(result)
17
18 def test_bad_recipe_file(self):
19 with patch("builtins.open", side_effect=OSError):
20 with self.assertRaises(RuinedNikuldenDinnerError):
21 validate_recipe("няма_го_този_файл.txt")
22
23 with patch("builtins.open", side_effect=IOError ):
24 with self.assertRaises(RuinedNikuldenDinnerError):
25 validate_recipe("няма_го_този_файл.txt")
26
27
28if __name__ == "__main__":
29 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.013s
FAILED (failures=2)