1import unittest
2from unittest.mock import mock_open, patch
3from secret import validate_recipe, RuinedNikuldenDinnerError
4
5
6class TestNikuldenValidator(unittest.TestCase):
7
8 def setUp(self):
9 self.test_path1 = 'test_path1.txt'
10 self.data1 = 'Аз обичам Риба и рибена чорба. Вкусна сьонга, ам, ам. Ще си уловя един Шаран сега'
11 self.test_path2 = 'test_path2.txt'
12 self.data2 = ('Рибата goes brrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr.'
13 'Петък, събота си леш, а в неделя палиш свещ'
14 'Обещаваш да се спреш, само ако нямаш cash, cash, cash'
15 'Само ако нямаш cash, cash, cash'
16 'И ще се направим ма, ма, ма'
17 'И ще се направим ма, ма, ма, мазаляк бе!'
18 )
19 self.fake_path = 'fake_path.txt'
20
21 def test_valid_recipe(self):
22 with patch('builtins.open', mock_open(read_data = self.data1)):
23 ans = validate_recipe(self.test_path1)
24 self.assertEqual(ans, True)
25
26 def test_invalid_recipe(self):
27 with patch('builtins.open', mock_open(read_data = self.data2)):
28 ans = validate_recipe(self.test_path2)
29 self.assertEqual(ans, False)
30
31 def test_bad_recipe_file(self):
32 with patch('builtins.open', side_effect = OSError):
33 with self.assertRaises(RuinedNikuldenDinnerError):
34 validate_recipe(self.fake_path)
35
36
37if __name__ == '__main__':
38 unittest.main()
..F.
======================================================================
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.020s
FAILED (failures=1)
07.12.2024 13:11
07.12.2024 13:10