1import unittest
2import unittest.mock as mock
3from secret import validate_recipe, RuinedNikuldenDinnerError
4
5FISH_VALUES = ['риба', 'рибена', 'шаран', 'сьонга']
6
7MOCKED_VALID_FILE_1 = """
8 И ловец съм, и рИба р съм!
9"""
10
11MOCKED_VALID_FILE_2 = """
12 рецепта за РиБенА чорба. Съставки - РИбА сЬОНГА Шаран вода
13"""
14
15MOCKED_VALID_FILE_3 = """
16 шеф иван манчев тази вечер ще ни учи как се готви рибЕна чорба с ШаРан
17"""
18
19MOCKED_INVALID_FILE_1 = """
20 За съжаление, как ще отбележи рождения си ден в 'На Кафе'
21 Гергана няма да видите сега, защото докато вървеше видеото
22 колегите ми казаха, че Гергана няма да дойде в предаването.
23"""
24
25MOCKED_INVALID_FILE_2 = """
26 Тованеерибенарецепта!
27"""
28
29MOCKED_INVALID_FILE_3 = """
30 риба, обаче с тая запетая не знам дали е валидно
31"""
32
33MOCKED_INVALID_FILE_4 = """
34 Шаранннннннннннн
35"""
36
37
38class TestNikuldenValidator(unittest.TestCase):
39
40 def test_valid_recipe(self, valid_file_name):
41 with mock.patch('builtins.open', mock_open_file_1=mock.mock_open(read_data=MOCKED_VALID_FILE_1)):
42 self.assertEqual(validate_recipe("mock_open_file_1"), True)
43
44 with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_VALID_FILE_2)):
45 self.assertEqual(validate_recipe("mock_open_file_2"), True)
46
47 with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_VALID_FILE_2)):
48 self.assertEqual(validate_recipe("mock_open_file_3"), True)
49
50 def test_invalid_recipe(self, invalid_file_name):
51 with mock.patch('builtins.open', mock_open_file_1=mock.mock_open(read_data=MOCKED_INVALID_FILE_1)):
52 self.assertEqual(validate_recipe("mock_open_file_1"), False)
53
54 with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_INVALID_FILE_2)):
55 self.assertEqual(validate_recipe("mock_open_file_2"), False)
56
57 with mock.patch('builtins.open', mock_open_file_3=mock.mock_open(read_data=MOCKED_INVALID_FILE_3)):
58 self.assertEqual(validate_recipe("mock_open_file_3"), False)
59
60 with mock.patch('builtins.open', mock_open_file_4=mock.mock_open(read_data=MOCKED_INVALID_FILE_4)):
61 self.assertEqual(validate_recipe("mock_open_file_4"), False)
62
63 def test_bad_recipe_file(self, bad_file_name):
64 with mock.patch('builtins.open', mock_open_file_1=mock.mock_open()):
65 mock.mock_open.side_effect = IOError()
66 with self.assertRaises(RuinedNikuldenDinnerError):
67 validate_recipe("mock_open_file_1")
68
69 with mock.patch('builtins.open', mock_open_file_2=mock.mock_open()):
70 mock.mock_open.side_effect = OSError()
71 with self.assertRaises(RuinedNikuldenDinnerError):
72 validate_recipe("mock_open_file_1")
FFFF
======================================================================
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 97, in test_naive_in_validator
mock_validate_recipe.assert_called()
File "/usr/lib/python3.12/unittest/mock.py", line 913, in assert_called
raise AssertionError(msg)
AssertionError: Expected 'validate_recipe' to have been called.
======================================================================
FAIL: test_no_error_handling_validator (test.TestTestNikuldenValidator.test_no_error_handling_validator)
Test with implementation missing error handling.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 80, in test_no_error_handling_validator
self.assertTrue(result.wasSuccessful(),
AssertionError: False is not true : Expecting test_invalid_recipe to pass with an implementation with error handling.
======================================================================
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 65, in test_no_lower_validator
self.assertTrue(result.wasSuccessful(),
AssertionError: False is not true : Expecting test_invalid_recipe to pass with an implementation missing lower.
======================================================================
FAIL: test_valid_validator (test.TestTestNikuldenValidator.test_valid_validator)
Test with a valid implementation.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 50, in test_valid_validator
self.assertTrue(result.wasSuccessful(),
AssertionError: False is not true : Expecting test_invalid_recipe to pass with valid implementation.
----------------------------------------------------------------------
Ran 4 tests in 0.004s
FAILED (failures=4)
Виктор Бечев
07.12.2024 13:27Тестовете ти не минават поради много причини, първата от която е излишният параметър на тестовите функции. Когато ползваш `patch` като декоратор - трябва ти, иначе - при извикване функцията не го намира.
|
f | 1 | import unittest | f | 1 | import unittest |
2 | import unittest.mock as mock | 2 | import unittest.mock as mock | ||
3 | from secret import validate_recipe, RuinedNikuldenDinnerError | 3 | from secret import validate_recipe, RuinedNikuldenDinnerError | ||
4 | 4 | ||||
5 | FISH_VALUES = ['риба', 'рибена', 'шаран', 'сьонга'] | 5 | FISH_VALUES = ['риба', 'рибена', 'шаран', 'сьонга'] | ||
6 | 6 | ||||
7 | MOCKED_VALID_FILE_1 = """ | 7 | MOCKED_VALID_FILE_1 = """ | ||
n | 8 | И ловец съм, и рИба р съм! | n | 8 | И ловец съм, и рИба р съм! |
9 | """ | 9 | """ | ||
10 | 10 | ||||
11 | MOCKED_VALID_FILE_2 = """ | 11 | MOCKED_VALID_FILE_2 = """ | ||
n | 12 | рецепта за РиБенА чорба. Съставки - РИбА, сЬОНГА, вода | n | 12 | рецепта за РиБенА чорба. Съставки - РИбА сЬОНГА Шаран вода |
13 | """ | 13 | """ | ||
14 | 14 | ||||
15 | MOCKED_VALID_FILE_3 = """ | 15 | MOCKED_VALID_FILE_3 = """ | ||
n | 16 | шеф иван манчев тази вечер ще ни учи как се готви сьОНга | n | 16 | шеф иван манчев тази вечер ще ни учи как се готви рибЕна чорба с ШаРан |
17 | """ | 17 | """ | ||
18 | 18 | ||||
19 | MOCKED_INVALID_FILE_1 = """ | 19 | MOCKED_INVALID_FILE_1 = """ | ||
20 | За съжаление, как ще отбележи рождения си ден в 'На Кафе' | 20 | За съжаление, как ще отбележи рождения си ден в 'На Кафе' | ||
21 | Гергана няма да видите сега, защото докато вървеше видеото | 21 | Гергана няма да видите сега, защото докато вървеше видеото | ||
22 | колегите ми казаха, че Гергана няма да дойде в предаването. | 22 | колегите ми казаха, че Гергана няма да дойде в предаването. | ||
23 | """ | 23 | """ | ||
24 | 24 | ||||
25 | MOCKED_INVALID_FILE_2 = """ | 25 | MOCKED_INVALID_FILE_2 = """ | ||
26 | Тованеерибенарецепта! | 26 | Тованеерибенарецепта! | ||
27 | """ | 27 | """ | ||
28 | 28 | ||||
29 | MOCKED_INVALID_FILE_3 = """ | 29 | MOCKED_INVALID_FILE_3 = """ | ||
30 | риба, обаче с тая запетая не знам дали е валидно | 30 | риба, обаче с тая запетая не знам дали е валидно | ||
n | n | 31 | """ | ||
32 | |||||
33 | MOCKED_INVALID_FILE_4 = """ | ||||
34 | Шаранннннннннннн | ||||
31 | """ | 35 | """ | ||
32 | 36 | ||||
33 | 37 | ||||
34 | class TestNikuldenValidator(unittest.TestCase): | 38 | class TestNikuldenValidator(unittest.TestCase): | ||
35 | 39 | ||||
36 | def test_valid_recipe(self, valid_file_name): | 40 | def test_valid_recipe(self, valid_file_name): | ||
37 | with mock.patch('builtins.open', mock_open_file_1=mock.mock_open(read_data=MOCKED_VALID_FILE_1)): | 41 | with mock.patch('builtins.open', mock_open_file_1=mock.mock_open(read_data=MOCKED_VALID_FILE_1)): | ||
38 | self.assertEqual(validate_recipe("mock_open_file_1"), True) | 42 | self.assertEqual(validate_recipe("mock_open_file_1"), True) | ||
39 | 43 | ||||
40 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_VALID_FILE_2)): | 44 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_VALID_FILE_2)): | ||
41 | self.assertEqual(validate_recipe("mock_open_file_2"), True) | 45 | self.assertEqual(validate_recipe("mock_open_file_2"), True) | ||
42 | 46 | ||||
43 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_VALID_FILE_2)): | 47 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_VALID_FILE_2)): | ||
44 | self.assertEqual(validate_recipe("mock_open_file_3"), True) | 48 | self.assertEqual(validate_recipe("mock_open_file_3"), True) | ||
45 | 49 | ||||
46 | def test_invalid_recipe(self, invalid_file_name): | 50 | def test_invalid_recipe(self, invalid_file_name): | ||
47 | with mock.patch('builtins.open', mock_open_file_1=mock.mock_open(read_data=MOCKED_INVALID_FILE_1)): | 51 | with mock.patch('builtins.open', mock_open_file_1=mock.mock_open(read_data=MOCKED_INVALID_FILE_1)): | ||
48 | self.assertEqual(validate_recipe("mock_open_file_1"), False) | 52 | self.assertEqual(validate_recipe("mock_open_file_1"), False) | ||
49 | 53 | ||||
50 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_INVALID_FILE_2)): | 54 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_INVALID_FILE_2)): | ||
51 | self.assertEqual(validate_recipe("mock_open_file_2"), False) | 55 | self.assertEqual(validate_recipe("mock_open_file_2"), False) | ||
52 | 56 | ||||
53 | with mock.patch('builtins.open', mock_open_file_3=mock.mock_open(read_data=MOCKED_INVALID_FILE_3)): | 57 | with mock.patch('builtins.open', mock_open_file_3=mock.mock_open(read_data=MOCKED_INVALID_FILE_3)): | ||
54 | self.assertEqual(validate_recipe("mock_open_file_3"), False) | 58 | self.assertEqual(validate_recipe("mock_open_file_3"), False) | ||
55 | 59 | ||||
t | t | 60 | with mock.patch('builtins.open', mock_open_file_4=mock.mock_open(read_data=MOCKED_INVALID_FILE_4)): | ||
61 | self.assertEqual(validate_recipe("mock_open_file_4"), False) | ||||
62 | |||||
56 | def test_bad_recipe_file(self, bad_file_name): | 63 | def test_bad_recipe_file(self, bad_file_name): | ||
57 | with mock.patch('builtins.open', mock_open_file_1=mock.mock_open()): | 64 | with mock.patch('builtins.open', mock_open_file_1=mock.mock_open()): | ||
58 | mock.mock_open.side_effect = IOError() | 65 | mock.mock_open.side_effect = IOError() | ||
59 | with self.assertRaises(RuinedNikuldenDinnerError): | 66 | with self.assertRaises(RuinedNikuldenDinnerError): | ||
60 | validate_recipe("mock_open_file_1") | 67 | validate_recipe("mock_open_file_1") | ||
61 | 68 | ||||
62 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open()): | 69 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open()): | ||
63 | mock.mock_open.side_effect = OSError() | 70 | mock.mock_open.side_effect = OSError() | ||
64 | with self.assertRaises(RuinedNikuldenDinnerError): | 71 | with self.assertRaises(RuinedNikuldenDinnerError): | ||
65 | validate_recipe("mock_open_file_1") | 72 | validate_recipe("mock_open_file_1") | ||
66 | 73 | ||||
67 | 74 | ||||
68 | 75 | ||||
69 | 76 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | import unittest | f | 1 | import unittest |
2 | import unittest.mock as mock | 2 | import unittest.mock as mock | ||
3 | from secret import validate_recipe, RuinedNikuldenDinnerError | 3 | from secret import validate_recipe, RuinedNikuldenDinnerError | ||
4 | 4 | ||||
5 | FISH_VALUES = ['риба', 'рибена', 'шаран', 'сьонга'] | 5 | FISH_VALUES = ['риба', 'рибена', 'шаран', 'сьонга'] | ||
6 | 6 | ||||
7 | MOCKED_VALID_FILE_1 = """ | 7 | MOCKED_VALID_FILE_1 = """ | ||
8 | И ловец съм, и рИба р съм! | 8 | И ловец съм, и рИба р съм! | ||
9 | """ | 9 | """ | ||
10 | 10 | ||||
11 | MOCKED_VALID_FILE_2 = """ | 11 | MOCKED_VALID_FILE_2 = """ | ||
12 | рецепта за РиБенА чорба. Съставки - РИбА, сЬОНГА, вода | 12 | рецепта за РиБенА чорба. Съставки - РИбА, сЬОНГА, вода | ||
13 | """ | 13 | """ | ||
14 | 14 | ||||
15 | MOCKED_VALID_FILE_3 = """ | 15 | MOCKED_VALID_FILE_3 = """ | ||
16 | шеф иван манчев тази вечер ще ни учи как се готви сьОНга | 16 | шеф иван манчев тази вечер ще ни учи как се готви сьОНга | ||
17 | """ | 17 | """ | ||
18 | 18 | ||||
19 | MOCKED_INVALID_FILE_1 = """ | 19 | MOCKED_INVALID_FILE_1 = """ | ||
20 | За съжаление, как ще отбележи рождения си ден в 'На Кафе' | 20 | За съжаление, как ще отбележи рождения си ден в 'На Кафе' | ||
21 | Гергана няма да видите сега, защото докато вървеше видеото | 21 | Гергана няма да видите сега, защото докато вървеше видеото | ||
22 | колегите ми казаха, че Гергана няма да дойде в предаването. | 22 | колегите ми казаха, че Гергана няма да дойде в предаването. | ||
23 | """ | 23 | """ | ||
24 | 24 | ||||
25 | MOCKED_INVALID_FILE_2 = """ | 25 | MOCKED_INVALID_FILE_2 = """ | ||
26 | Тованеерибенарецепта! | 26 | Тованеерибенарецепта! | ||
27 | """ | 27 | """ | ||
28 | 28 | ||||
29 | MOCKED_INVALID_FILE_3 = """ | 29 | MOCKED_INVALID_FILE_3 = """ | ||
30 | риба, обаче с тая запетая не знам дали е валидно | 30 | риба, обаче с тая запетая не знам дали е валидно | ||
31 | """ | 31 | """ | ||
32 | 32 | ||||
33 | 33 | ||||
34 | class TestNikuldenValidator(unittest.TestCase): | 34 | class TestNikuldenValidator(unittest.TestCase): | ||
35 | 35 | ||||
36 | def test_valid_recipe(self, valid_file_name): | 36 | def test_valid_recipe(self, valid_file_name): | ||
37 | with mock.patch('builtins.open', mock_open_file_1=mock.mock_open(read_data=MOCKED_VALID_FILE_1)): | 37 | with mock.patch('builtins.open', mock_open_file_1=mock.mock_open(read_data=MOCKED_VALID_FILE_1)): | ||
38 | self.assertEqual(validate_recipe("mock_open_file_1"), True) | 38 | self.assertEqual(validate_recipe("mock_open_file_1"), True) | ||
39 | 39 | ||||
40 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_VALID_FILE_2)): | 40 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_VALID_FILE_2)): | ||
41 | self.assertEqual(validate_recipe("mock_open_file_2"), True) | 41 | self.assertEqual(validate_recipe("mock_open_file_2"), True) | ||
42 | 42 | ||||
43 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_VALID_FILE_2)): | 43 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_VALID_FILE_2)): | ||
44 | self.assertEqual(validate_recipe("mock_open_file_3"), True) | 44 | self.assertEqual(validate_recipe("mock_open_file_3"), True) | ||
45 | 45 | ||||
46 | def test_invalid_recipe(self, invalid_file_name): | 46 | def test_invalid_recipe(self, invalid_file_name): | ||
47 | with mock.patch('builtins.open', mock_open_file_1=mock.mock_open(read_data=MOCKED_INVALID_FILE_1)): | 47 | with mock.patch('builtins.open', mock_open_file_1=mock.mock_open(read_data=MOCKED_INVALID_FILE_1)): | ||
48 | self.assertEqual(validate_recipe("mock_open_file_1"), False) | 48 | self.assertEqual(validate_recipe("mock_open_file_1"), False) | ||
49 | 49 | ||||
50 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_INVALID_FILE_2)): | 50 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_INVALID_FILE_2)): | ||
51 | self.assertEqual(validate_recipe("mock_open_file_2"), False) | 51 | self.assertEqual(validate_recipe("mock_open_file_2"), False) | ||
52 | 52 | ||||
53 | with mock.patch('builtins.open', mock_open_file_3=mock.mock_open(read_data=MOCKED_INVALID_FILE_3)): | 53 | with mock.patch('builtins.open', mock_open_file_3=mock.mock_open(read_data=MOCKED_INVALID_FILE_3)): | ||
54 | self.assertEqual(validate_recipe("mock_open_file_3"), False) | 54 | self.assertEqual(validate_recipe("mock_open_file_3"), False) | ||
55 | 55 | ||||
56 | def test_bad_recipe_file(self, bad_file_name): | 56 | def test_bad_recipe_file(self, bad_file_name): | ||
n | 57 | with mock.patch('builtins.open', mock_open_file_1=mock.mock_open(read_data=MOCKED_INVALID_FILE_1)): | n | 57 | with mock.patch('builtins.open', mock_open_file_1=mock.mock_open()): |
58 | mock.mock_open.side_effect = IOError() | 58 | mock.mock_open.side_effect = IOError() | ||
59 | with self.assertRaises(RuinedNikuldenDinnerError): | 59 | with self.assertRaises(RuinedNikuldenDinnerError): | ||
60 | validate_recipe("mock_open_file_1") | 60 | validate_recipe("mock_open_file_1") | ||
61 | 61 | ||||
t | 62 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_INVALID_FILE_2)): | t | 62 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open()): |
63 | mock.mock_open.side_effect = OSError() | 63 | mock.mock_open.side_effect = OSError() | ||
64 | with self.assertRaises(RuinedNikuldenDinnerError): | 64 | with self.assertRaises(RuinedNikuldenDinnerError): | ||
65 | validate_recipe("mock_open_file_1") | 65 | validate_recipe("mock_open_file_1") | ||
66 | 66 | ||||
67 | 67 | ||||
68 | 68 | ||||
69 | 69 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | import unittest | f | 1 | import unittest |
2 | import unittest.mock as mock | 2 | import unittest.mock as mock | ||
3 | from secret import validate_recipe, RuinedNikuldenDinnerError | 3 | from secret import validate_recipe, RuinedNikuldenDinnerError | ||
4 | 4 | ||||
5 | FISH_VALUES = ['риба', 'рибена', 'шаран', 'сьонга'] | 5 | FISH_VALUES = ['риба', 'рибена', 'шаран', 'сьонга'] | ||
6 | 6 | ||||
7 | MOCKED_VALID_FILE_1 = """ | 7 | MOCKED_VALID_FILE_1 = """ | ||
8 | И ловец съм, и рИба р съм! | 8 | И ловец съм, и рИба р съм! | ||
9 | """ | 9 | """ | ||
10 | 10 | ||||
11 | MOCKED_VALID_FILE_2 = """ | 11 | MOCKED_VALID_FILE_2 = """ | ||
12 | рецепта за РиБенА чорба. Съставки - РИбА, сЬОНГА, вода | 12 | рецепта за РиБенА чорба. Съставки - РИбА, сЬОНГА, вода | ||
13 | """ | 13 | """ | ||
14 | 14 | ||||
15 | MOCKED_VALID_FILE_3 = """ | 15 | MOCKED_VALID_FILE_3 = """ | ||
16 | шеф иван манчев тази вечер ще ни учи как се готви сьОНга | 16 | шеф иван манчев тази вечер ще ни учи как се готви сьОНга | ||
17 | """ | 17 | """ | ||
18 | 18 | ||||
19 | MOCKED_INVALID_FILE_1 = """ | 19 | MOCKED_INVALID_FILE_1 = """ | ||
20 | За съжаление, как ще отбележи рождения си ден в 'На Кафе' | 20 | За съжаление, как ще отбележи рождения си ден в 'На Кафе' | ||
21 | Гергана няма да видите сега, защото докато вървеше видеото | 21 | Гергана няма да видите сега, защото докато вървеше видеото | ||
22 | колегите ми казаха, че Гергана няма да дойде в предаването. | 22 | колегите ми казаха, че Гергана няма да дойде в предаването. | ||
23 | """ | 23 | """ | ||
24 | 24 | ||||
25 | MOCKED_INVALID_FILE_2 = """ | 25 | MOCKED_INVALID_FILE_2 = """ | ||
26 | Тованеерибенарецепта! | 26 | Тованеерибенарецепта! | ||
27 | """ | 27 | """ | ||
28 | 28 | ||||
29 | MOCKED_INVALID_FILE_3 = """ | 29 | MOCKED_INVALID_FILE_3 = """ | ||
30 | риба, обаче с тая запетая не знам дали е валидно | 30 | риба, обаче с тая запетая не знам дали е валидно | ||
31 | """ | 31 | """ | ||
32 | 32 | ||||
33 | 33 | ||||
34 | class TestNikuldenValidator(unittest.TestCase): | 34 | class TestNikuldenValidator(unittest.TestCase): | ||
35 | 35 | ||||
36 | def test_valid_recipe(self, valid_file_name): | 36 | def test_valid_recipe(self, valid_file_name): | ||
37 | with mock.patch('builtins.open', mock_open_file_1=mock.mock_open(read_data=MOCKED_VALID_FILE_1)): | 37 | with mock.patch('builtins.open', mock_open_file_1=mock.mock_open(read_data=MOCKED_VALID_FILE_1)): | ||
38 | self.assertEqual(validate_recipe("mock_open_file_1"), True) | 38 | self.assertEqual(validate_recipe("mock_open_file_1"), True) | ||
39 | 39 | ||||
40 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_VALID_FILE_2)): | 40 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_VALID_FILE_2)): | ||
41 | self.assertEqual(validate_recipe("mock_open_file_2"), True) | 41 | self.assertEqual(validate_recipe("mock_open_file_2"), True) | ||
42 | 42 | ||||
43 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_VALID_FILE_2)): | 43 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_VALID_FILE_2)): | ||
44 | self.assertEqual(validate_recipe("mock_open_file_3"), True) | 44 | self.assertEqual(validate_recipe("mock_open_file_3"), True) | ||
45 | 45 | ||||
46 | def test_invalid_recipe(self, invalid_file_name): | 46 | def test_invalid_recipe(self, invalid_file_name): | ||
47 | with mock.patch('builtins.open', mock_open_file_1=mock.mock_open(read_data=MOCKED_INVALID_FILE_1)): | 47 | with mock.patch('builtins.open', mock_open_file_1=mock.mock_open(read_data=MOCKED_INVALID_FILE_1)): | ||
48 | self.assertEqual(validate_recipe("mock_open_file_1"), False) | 48 | self.assertEqual(validate_recipe("mock_open_file_1"), False) | ||
49 | 49 | ||||
50 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_INVALID_FILE_2)): | 50 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_INVALID_FILE_2)): | ||
51 | self.assertEqual(validate_recipe("mock_open_file_2"), False) | 51 | self.assertEqual(validate_recipe("mock_open_file_2"), False) | ||
52 | 52 | ||||
53 | with mock.patch('builtins.open', mock_open_file_3=mock.mock_open(read_data=MOCKED_INVALID_FILE_3)): | 53 | with mock.patch('builtins.open', mock_open_file_3=mock.mock_open(read_data=MOCKED_INVALID_FILE_3)): | ||
54 | self.assertEqual(validate_recipe("mock_open_file_3"), False) | 54 | self.assertEqual(validate_recipe("mock_open_file_3"), False) | ||
55 | 55 | ||||
t | 56 | def test_bad_file(self, bad_file_name): | t | 56 | def test_bad_recipe_file(self, bad_file_name): |
57 | with mock.patch('builtins.open', mock_open_file_1=mock.mock_open(read_data=MOCKED_INVALID_FILE_1)): | 57 | with mock.patch('builtins.open', mock_open_file_1=mock.mock_open(read_data=MOCKED_INVALID_FILE_1)): | ||
58 | mock.mock_open.side_effect = IOError() | 58 | mock.mock_open.side_effect = IOError() | ||
59 | with self.assertRaises(RuinedNikuldenDinnerError): | 59 | with self.assertRaises(RuinedNikuldenDinnerError): | ||
60 | validate_recipe("mock_open_file_1") | 60 | validate_recipe("mock_open_file_1") | ||
61 | 61 | ||||
62 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_INVALID_FILE_2)): | 62 | with mock.patch('builtins.open', mock_open_file_2=mock.mock_open(read_data=MOCKED_INVALID_FILE_2)): | ||
63 | mock.mock_open.side_effect = OSError() | 63 | mock.mock_open.side_effect = OSError() | ||
64 | with self.assertRaises(RuinedNikuldenDinnerError): | 64 | with self.assertRaises(RuinedNikuldenDinnerError): | ||
65 | validate_recipe("mock_open_file_1") | 65 | validate_recipe("mock_open_file_1") | ||
66 | 66 | ||||
67 | 67 | ||||
68 | 68 | ||||
69 | 69 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|