1import unittest
2from secret import validate_recipe, RuinedNikuldenDinnerError
3
4class TestNikuldenValidator(unittest.TestCase):
5 def test_valid_recipe(self):
6 valid_recipes = ["Рецепта за врачанска рибена чорба",
7 "Сьонга на фурна с картофи",
8 "Рецепта за шаран и малко вино",
9 "Някаква рецепта за риба от съседката"]
10
11 for recipe in valid_recipes:
12 result = validate_recipe(recipe)
13 self.assertTrue(result)
14
15 def test_invalid_recipe(self):
16 invalid_recipes = ["Мръвки с лук",
17 "Картофи на фурна",
18 "Бъркани яйца"]
19 for recipe in invalid_recipes:
20 result = validate_recipe(recipe)
21 self.assertFalse(result)
22
23 def test_bad_recipe_file(self):
24 with self.assertRaises(RuinedNikuldenDinnerError):
25 validate_recipe(None)
26
27if __name__ == "__main__":
28 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_valid_recipe 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 80, in test_no_error_handling_validator
self.assertTrue(result.wasSuccessful(),
AssertionError: False is not true : Expecting test_valid_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_valid_recipe to pass with valid implementation.
----------------------------------------------------------------------
Ran 4 tests in 0.004s
FAILED (failures=4)
Виктор Бечев
07.12.2024 12:06Понеже fail-овете на тестовете не са супер подробни, обяснение защо ти фейлват тестовете - по дефиниция функцията приема име на файл. Отваря файла. И така нататък. В твоя случай функцията получава стринг, опитва се да го отвори и... Край.
|