1import unittest
2from unittest.mock import mock_open, patch, Mock
3from secret import validate_recipe, RuinedNikuldenDinnerError
4
5
6class TestNikuldenValidator(unittest.TestCase):
7
8 def setUp(self):
9 self.first_valid_text = "Lorem ipsum dolor sit Риба amet, consectetur adipiscing elit. Fusce venenatis."
10 self.second_valid_text = "Lorem ipsum dolor sit amet, consectetur рибА adipiscing elit. Fusce venenatis."
11 self.third_valid_text = "Lorem ipsum dolor sit сьонга amet, consectetur adipiscing elit. Fusce venenatis."
12 self.fourth_valid_text = "Lorem ipsum dolor sit amet, consectetur СЬОНГА elit. Fusce venenatis."
13 self.fifth_valid_text = "Lorem ipsum dolor sit шаРАН amet, consectetur adipiscing elit. Fusce venenatis."
14 self.sixth_valid_text = "Lorem ipsum dolor sit amet, consectetur adipiscing шарАн. Fusce venenatis."
15 self.seventh_valid_text = "Lorem ipsum dolor sit amet, consectetur риБена adipiscing elit. Fusce venenatis."
16 self.eighth_valid_text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce рибена."
17
18 self.valid_texts = [self.first_valid_text, self.second_valid_text, self.third_valid_text,
19 self.fourth_valid_text, self.fifth_valid_text, self.sixth_valid_text,
20 self.seventh_valid_text, self.eighth_valid_text]
21
22 self.first_invalid_text = "сьомга ipsum скумрия sit amet, цаца adipiscing. Fusce venenatis."
23 self.second_invalid_text = "Lorem пържола sit amet, consectetur рибка elit. Fusce venenatis."
24 self.third_invalid_text = "Lorem рибъ amet, consectetur карАкуда elit. Fusce venenatis."
25
26 self.invalid_texts = [self.first_invalid_text, self.second_invalid_text, self.third_invalid_text]
27
28 def test_valid_recipe(self):
29 for current_text in self.valid_texts:
30 with patch('builtins.open', new_callable=mock_open, read_data=current_text):
31 self.assertTrue(validate_recipe("file.txt"))
32
33 def test_invalid_recipe(self):
34 for current_text in self.invalid_texts:
35 with patch('builtins.open', new_callable=mock_open, read_data=current_text):
36 self.assertFalse(validate_recipe("file.txt"))
37
38 def test_bad_recipe_file(self):
39 with patch('builtins.open', new_callable=mock_open) as mocked_open:
40 mocked_open.side_effect = OSError
41 with self.assertRaises(RuinedNikuldenDinnerError):
42 validate_recipe("file.txt")
43
44 with patch('builtins.open', new_callable=mock_open, read_data="Text") as mocked_open:
45 mock_read = Mock(side_effect=IOError)
46 mocked_open.return_value.read = mock_read
47 with self.assertRaises(RuinedNikuldenDinnerError):
48 validate_recipe("file.txt")
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.040s
FAILED (failures=1)
07.12.2024 11:46
07.12.2024 11:45
07.12.2024 12:03