Предизвикателства > Валидатор за Никулденска рецепта > Решения > Решението на Мариана Терзиева

Резултати
0 точки от тестове
0 точки от учител

0 точки общо

0 успешни теста
4 неуспешни теста
Код
Скрий всички коментари

 1from secret import validate_recipe, RuinedNikuldenDinnerError
 2import os
 3import unittest
 4from unittest.mock import patch
 5
 6class TestNikuldenValidator(unittest.TestCase):
 7    def setUp(self):
 8        self.valid_recipe_file = 'valid_recipe.txt'
 9        self.invalid_recipe_file = 'invalid_recipe.txt'
10        self.error_recipe_file = 'error_recipe.txt'
11
12        with open(self.valid_recipe_file, 'w') as valid_file:
13            valid_file.write('Риба, ШарАн, сьоНга и рибЕна чорба.')
14
15        with open(self.invalid_recipe_file, 'w') as invalid_file:
16            invalid_file.write('Ще се яде лютеница на Никулден.')
17        
18        with open(self.error_recipe_file, 'w') as wrong_file:
19            wrong_file.write('')
20
21    def tearDown(self):
22        test_files = [self.valid_recipe_file, self.invalid_recipe_file, self.error_recipe_file]
23        for file in test_files:
24            try:
25                os.remove(file)
26            except FileNotFoundError:
27                pass
28
29    def test_valid_recipe(self):
30        self.assertTrue(validate_recipe(self.valid_recipe_file))
31
32    def test_invalid_recipe(self):
33        self.assertFalse(validate_recipe(self.invalid_recipe_file))
34    
35    def test_bad_recipe_file(self):
36        with patch('builtins.open', side_effect=OSError):
37            with self.assertRaises(RuinedNikuldenDinnerError):
38                validate_recipe('error_recipe.txt')
39
40if __name__ == "__main__":
41    unittest.main()

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 95, in test_naive_in_validator
self.assertTrue(result.wasSuccessful(),
AssertionError: False is not true : Expecting test_bad_recipe_file to pass with an implementation missing word splits.

======================================================================
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 82, in test_no_error_handling_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_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_bad_recipe_file 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_bad_recipe_file to pass with valid implementation.

----------------------------------------------------------------------
Ran 4 tests in 0.004s

FAILED (failures=4)

Дискусия
История
Това решение има само една версия.