コード例 #1
0
ファイル: warnings_test.py プロジェクト: bemehow/salt
 def raise_warning(**kwargs):
     _version_info_ = kwargs.pop('_version_info_', (0, 16, 0))
     kwargs_warn_until(
         kwargs,
         (0, 17),
         _version_info_=_version_info_
     )
コード例 #2
0
ファイル: warnings_test.py プロジェクト: bemehow/salt
    def test_kwargs_warn_until_warning_raised(self):
        # We *always* want *all* warnings thrown on this module
        warnings.filterwarnings('always', '', DeprecationWarning, __name__)

        def raise_warning(**kwargs):
            _version_info_ = kwargs.pop('_version_info_', (0, 16, 0))
            kwargs_warn_until(
                kwargs,
                (0, 17),
                _version_info_=_version_info_
            )

        # raise_warning({...}) should show warning until version info is >= (0, 17)
        with warnings.catch_warnings(record=True) as recorded_warnings:
            raise_warning(foo=42)  # with a kwarg
            self.assertEqual(
                'The following parameter(s) have been deprecated and '
                'will be removed in \'0.17.0\': \'foo\'.',
                str(recorded_warnings[0].message)
            )
        # With no **kwargs, should not show warning until version info is >= (0, 17)
        with warnings.catch_warnings(record=True) as recorded_warnings:
            kwargs_warn_until(
                {},  # no kwargs
                (0, 17),
                _version_info_=(0, 16, 0)
            )
            self.assertEqual(0, len(recorded_warnings))

        # Let's set version info to (0, 17), a RuntimeError should be raised
        # regardless of whether or not we pass any **kwargs.
        with self.assertRaisesRegexp(
                RuntimeError,
                r'The warning triggered on filename \'(.*)warnings_test.py\', '
                r'line number ([\d]+), is supposed to be shown until version '
                r'\'0.17.0\' is released. Current version is now \'0.17.0\'. '
                r'Please remove the warning.'):
            raise_warning(_version_info_=(0, 17))  # no kwargs

        with self.assertRaisesRegexp(
                RuntimeError,
                r'The warning triggered on filename \'(.*)warnings_test.py\', '
                r'line number ([\d]+), is supposed to be shown until version '
                r'\'0.17.0\' is released. Current version is now \'0.17.0\'. '
                r'Please remove the warning.'):
            raise_warning(bar='baz', qux='quux', _version_info_=(0, 17))  # some kwargs
コード例 #3
0
ファイル: warnings_test.py プロジェクト: micahhausler/salt
    def test_kwargs_warn_until_warning_raised(self, salt_version_mock):
        # We *always* want *all* warnings thrown on this module
        warnings.filterwarnings('always', '', DeprecationWarning, __name__)

        # Define a salt version info
        salt_version_mock.__version_info__ = (0, 16)

        def raise_warning(**kwargs):
            kwargs_warn_until(
                kwargs,
                (0, 17),
            )

        # raise_warning({...}) should show warning until version info is >= (0, 17)
        with warnings.catch_warnings(record=True) as recorded_warnings:
            raise_warning(foo=42)  # with a kwarg
            self.assertEqual(
                'The following parameter(s) have been deprecated and '
                'will be removed in 0.17: \'foo\'.',
                str(recorded_warnings[0].message))
        # With no **kwargs, should not show warning until version info is >= (0, 17)
        with warnings.catch_warnings(record=True) as recorded_warnings:
            kwargs_warn_until(
                {},  # no kwargs
                (0, 17),
            )
            self.assertEqual(0, len(recorded_warnings))

        # Let's set version info to (0, 17), a RuntimeError should be raised
        # regardless of whether or not we pass any **kwargs.
        salt_version_mock.__version_info__ = (0, 17)
        with self.assertRaisesRegexp(
                RuntimeError,
                r'The warning triggered on filename \'(.*)warnings_test.py\', '
                r'line number ([\d]+), is supposed to be shown until version '
                r'\'0.17\' is released. Current version is now \'0.17\'. Please '
                r'remove the warning.'):
            raise_warning()  # no kwargs
        with self.assertRaisesRegexp(
                RuntimeError,
                r'The warning triggered on filename \'(.*)warnings_test.py\', '
                r'line number ([\d]+), is supposed to be shown until version '
                r'\'0.17\' is released. Current version is now \'0.17\'. Please '
                r'remove the warning.'):
            raise_warning(bar='baz', qux='quux')  # some kwargs
コード例 #4
0
ファイル: warnings_test.py プロジェクト: micahhausler/salt
 def raise_warning(**kwargs):
     kwargs_warn_until(
         kwargs,
         (0, 17),
     )
コード例 #5
0
ファイル: warnings_test.py プロジェクト: yanghao-zh/salt
 def raise_warning(**kwargs):
     _version_info_ = kwargs.pop('_version_info_', (0, 16, 0))
     kwargs_warn_until(kwargs, (0, 17), _version_info_=_version_info_)
コード例 #6
0
ファイル: warnings_test.py プロジェクト: joehealy/pkg-salt
 def raise_warning(**kwargs):
     kwargs_warn_until(
         kwargs,
         (0, 17),
     )