1import unittest
2from unittest.mock import patch, mock_open
3from secret import validate_recipe, RuinedNikuldenDinnerError
4
5
6class TestNikuldenValidator(unittest.TestCase):
7
8 def test_valid_recipe(self):
9 # All words are found
10 for content in ['риба', 'рибена', 'шаран', 'сьонга']:
11 with patch('builtins.open', mock_open(read_data=content)):
12 self.assertTrue(validate_recipe('dummy'))
13 # Words are found in between other words
14 content = 'Риба, ама цаца. Цаца, ама риба.'
15 with patch('builtins.open', mock_open(read_data=content)):
16 self.assertTrue(validate_recipe('dummy'))
17 # Case sensitivity
18 for content in ['Риба', 'риБЕна', 'шарАН', 'сьонгА']:
19 with patch('builtins.open', mock_open(read_data=content)):
20 self.assertTrue(validate_recipe('dummy'))
21
22 def test_invalid_recipe(self):
23 # No words
24 content = 'Никакви думи.'
25 with patch('builtins.open', mock_open(read_data=content)):
26 self.assertFalse(validate_recipe('dummy'))
27 # Empty
28 content = ''
29 with patch('builtins.open', mock_open(read_data=content)):
30 self.assertFalse(validate_recipe('dummy'))
31 # No spaces
32 content = 'рибаамаслято'
33 with patch('builtins.open', mock_open(read_data=content)):
34 self.assertFalse(validate_recipe('dummy'))
35
36 def test_bad_recipe_file(self):
37 # No spaces
38 with self.assertRaises(RuinedNikuldenDinnerError):
39 self.assertFalse(validate_recipe('няма такъв файл'))
40
41
42if __name__ == '__main__':
43 unittest.main()
....
----------------------------------------------------------------------
Ran 4 tests in 0.065s
OK