Exemplo n.º 1
0
 def test_fails_when_incorrect_warning_with_callable(self):
     """
     Test that assert_warns fails when we pass a specific warning and
     a different warning class is thrown.
     """
     with assertions.assert_raises(AssertionError):
         assertions.assert_warns(DeprecationWarning, self._create_user_warning)
Exemplo n.º 2
0
 def test_fails_when_incorrect_warning_with_callable(self):
     """
     Test that assert_warns fails when we pass a specific warning and
     a different warning class is thrown.
     """
     with assertions.assert_raises(AssertionError):
         assertions.assert_warns(DeprecationWarning,
                                 self._create_user_warning)
Exemplo n.º 3
0
    def test_fails_when_no_warning_with_callable(self):
        """Test that assert_warns fails when there is no warning thrown."""
        with assertions.assert_raises(AssertionError):

            def do_nothing():
                pass

            assertions.assert_warns(UserWarning, do_nothing)
Exemplo n.º 4
0
 def test_passes_with_specific_warning_with_callable_arguments(self):
     """Test that assert_warns passes args and kwargs to the callable correctly."""
     def _requires_args_and_kwargs(*args, **kwargs):
         if args != ['foo'] and kwargs != {'bar': 'bar'}:
             raise ValueError('invalid values for args and kwargs')
         self._create_user_warning()
     # If we hit the ArgumentError, our test fails.
     assertions.assert_warns(UserWarning, _requires_args_and_kwargs, 'foo', bar='bar')
Exemplo n.º 5
0
    def test_passes_with_specific_warning_with_callable_arguments(self):
        """Test that assert_warns passes args and kwargs to the callable correctly."""
        def _requires_args_and_kwargs(*args, **kwargs):
            if args != ['foo'] and kwargs != {'bar': 'bar'}:
                raise ValueError('invalid values for args and kwargs')
            self._create_user_warning()

        # If we hit the ArgumentError, our test fails.
        assertions.assert_warns(UserWarning,
                                _requires_args_and_kwargs,
                                'foo',
                                bar='bar')
Exemplo n.º 6
0
 def test_passes_with_specific_warning_with_callable(self):
     """Test that assert_warns passes if a specific warning class is given and thrown."""
     assertions.assert_warns(DeprecationWarning,
                             self._create_deprecation_warning)
Exemplo n.º 7
0
 def test_passes_with_any_warning(self):
     """Test that assert_warns passes if no specific warning class is given."""
     with assertions.assert_warns():
         self._create_user_warning()
Exemplo n.º 8
0
 def test_fails_when_no_warning(self):
     """Test that assert_warns fails when there is no warning thrown."""
     with assertions.assert_raises(AssertionError):
         with assertions.assert_warns():
             pass
Exemplo n.º 9
0
 def test_passes_with_specific_warning_with_callable(self):
     """Test that assert_warns passes if a specific warning class is given and thrown."""
     assertions.assert_warns(DeprecationWarning, self._create_deprecation_warning)
Exemplo n.º 10
0
 def test_passes_with_any_warning(self):
     """Test that assert_warns passes if no specific warning class is given."""
     with assertions.assert_warns():
         self._create_user_warning()
Exemplo n.º 11
0
 def test_fails_when_no_warning_with_callable(self):
     """Test that assert_warns fails when there is no warning thrown."""
     with assertions.assert_raises(AssertionError):
         do_nothing = lambda: None
         assertions.assert_warns(UserWarning, do_nothing)
Exemplo n.º 12
0
 def test_fails_when_no_warning(self):
     """Test that assert_warns fails when there is no warning thrown."""
     with assertions.assert_raises(AssertionError):
         with assertions.assert_warns():
             pass