1import unittest
2from unittest.mock import patch, mock_open
3from secret import validate_recipe, RuinedNikuldenDinnerError
4from itertools import product
5
6
7class TestNikuldenValidator(unittest.TestCase):
8 def test_valid_recipe(self) -> None:
9 valid_words = ["риба", "рибена", "шаран", "сьонга"]
10 case_insensitive_words = []
11 generate = lambda word: ["".join(p) for p in product(*((c.lower(), c.upper()) for c in word))]
12 for word in valid_words:
13 case_insensitive_words.extend(generate(word))
14
15 for word in case_insensitive_words:
16 with patch("builtins.open", mock_open(read_data=f"Валидна рецепта с {word}")):
17 self.assertTrue(validate_recipe("valid_recipe.txt"))
18
19 def test_invalid_recipe(self):
20 recipe = "Супер мега невалидна рецепта за сьомга"
21 with patch("builtins.open", mock_open(read_data=recipe)):
22 self.assertFalse(validate_recipe("invalid_recipe.txt"))
23
24 def test_bad_recipe_file(self):
25 for error in [OSError, IOError]:
26 with patch("builtins.open", side_effect=error):
27 with self.assertRaises(RuinedNikuldenDinnerError):
28 validate_recipe("bad_test_file.txt")
29
30
31if __name__ == "__main__":
32 unittest.main()
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.
----------------------------------------------------------------------
Ran 4 tests in 0.740s
FAILED (failures=1)