|
| 1 | +''' |
| 2 | +Currently, the introduction of pydantic[1] to validate result dictionaries that |
| 3 | +handlers return is planned to just raise a deprecation warning. |
| 4 | +
|
| 5 | +After 1.0 -- ie. a backwards-incompatible release -- we should turn deprecation |
| 6 | +warning to actually start failing. See issue [2]. |
| 7 | +
|
| 8 | +[1| https://github.com/eficode/robotframework-oxygen/issues/43 |
| 9 | +[2] https://github.com/eficode/robotframework-oxygen/issues/45 |
| 10 | +''' |
| 11 | +from unittest import TestCase |
| 12 | +from unittest.mock import patch |
| 13 | +from oxygen.base_handler import BaseHandler |
| 14 | +from oxygen.oxygen import OxygenCLI |
| 15 | + |
| 16 | +from ..helpers import get_config, MINIMAL_SUITE_DICT |
| 17 | + |
| 18 | +class TestDeprecationWarningWhenValidating(TestCase): |
| 19 | + def setUp(self): |
| 20 | + self.cli = OxygenCLI() |
| 21 | + |
| 22 | + def test_warning_about_invalid_result(self): |
| 23 | + handler = BaseHandler(get_config()['oxygen.junit']) |
| 24 | + |
| 25 | + with self.assertWarns(UserWarning) as warning: |
| 26 | + handler._validate({}) |
| 27 | + |
| 28 | + warning_message = str(warning.warning) |
| 29 | + self.assertIn('oxygen.base_handler', warning_message) |
| 30 | + self.assertIn('validation error for typed-dict', warning_message) |
| 31 | + self.assertIn('In Oxygen 1.0, handlers will' |
| 32 | + ' need to produce valid results.', warning_message) |
| 33 | + |
| 34 | + @patch('oxygen.oxygen.RobotInterface') |
| 35 | + def test_warning_about_invalid_result_in_CLI(self, mock_iface): |
| 36 | + with self.assertWarns(UserWarning) as warning: |
| 37 | + self.cli.convert_to_robot_result({ |
| 38 | + 'result_file': 'doesentmatter', |
| 39 | + 'func': lambda **_: {**MINIMAL_SUITE_DICT, 'setup': []} |
| 40 | + }) |
| 41 | + |
| 42 | + mock_iface.assert_any_call() |
| 43 | + |
| 44 | + def test_deprecation_was_removed(self): |
| 45 | + '''Remove this test once deprecation warning has been removed''' |
| 46 | + if self.cli.__version__.startswith('1'): |
| 47 | + self.fail('Deprecation warning should have been removed in 1.0') |
0 commit comments