Example #1
0
 def testassertWarnsTwice(self):
     """Issue warning twice, test fails"""
     with self.assertRaises(AssertionError):
         with spacepy_testing.assertWarns(self, 'always', r'f.*',
                                          SPTestWarning):
             warnings.warn('foo', SPTestWarning)
             warnings.warn('foo2', SPTestWarning)
Example #2
0
 def test_deprecation(self):
     """Deprecation warning on old name"""
     with spacepy_testing.assertWarns(
             self, 'always',
             r'Use spacepy\.plot\.Spectrogram \(capitalized\)\.',
             DeprecationWarning, r'spacepy.plot$'):
         a = spacepy.plot.spectrogram(
             self.data, variables=self.kwargs['variables'])
Example #3
0
    def testDeprecationNone(self):
        """Test the deprecation decorator with no docstring"""
        @spacepy.deprecated(0.1, 'pithy message')
        def testfunc(x):
            return x + 1

        self.assertEqual(
            "\n"
            "    .. deprecated:: 0.1\n"
            "       pithy message", testfunc.__doc__)
        with spacepy_testing.assertWarns(self, 'always', r'pithy message$',
                                         DeprecationWarning, r'spacepy$'):
            self.assertEqual(2, testfunc(1))
Example #4
0
 def testassertWarnsfilter(self):
     """assertWarns only acts on desired warnings"""
     with warnings.catch_warnings(record=True) as cm:
         with spacepy_testing.assertWarns(self, 'always', r'f.*',
                                          SPTestWarning):
             warnings.warn('foo', SPTestWarning)
             warnings.warn('foo')
             warnings.warn('bar', SPTestWarning)
     # Verify that the other two warnings were issued as expected
     self.assertEqual(2, len(cm))
     for w in cm:
         self.assertIn(w.category, (UserWarning, SPTestWarning))
         if w.category is UserWarning:
             self.assertEqual('foo', str(w.message))
         else:
             self.assertEqual('bar', str(w.message))
Example #5
0
    def testDeprecationDifferentMessage(self):
        """Test the deprecation decorator, docstring different from message"""
        @spacepy.deprecated(0.1, 'pithy message', docstring='foo\nbar')
        def testfunc(x):
            """test function

            this will test things
            """
            return x + 1

        self.assertEqual(
            "test function\n"
            "\n"
            "            .. deprecated:: 0.1\n"
            "               foo\n"
            "               bar\n"
            "\n"
            "            this will test things\n"
            "            ", testfunc.__doc__)
        with spacepy_testing.assertWarns(self, 'always', r'pithy message$',
                                         DeprecationWarning, r'spacepy$'):
            self.assertEqual(2, testfunc(1))
Example #6
0
    def testDeprecation(self):
        """Test the deprecation decorator"""
        @spacepy.deprecated(0.1, 'pithy message')
        def testfunc(x):
            """
            test function

            this will test things
            """
            return x + 1

        self.assertEqual(
            "\n"
            "            test function\n"
            "\n"
            "            .. deprecated:: 0.1\n"
            "               pithy message\n"
            "\n"
            "            this will test things\n"
            "            ", testfunc.__doc__)
        with spacepy_testing.assertWarns(self, 'always', r'pithy message$',
                                         DeprecationWarning, r'spacepy$'):
            self.assertEqual(2, testfunc(1))
Example #7
0
 def testassertWarnsSimple(self):
     """Simple test of assertWarns"""
     # This is most similar to how it would normally be used
     with spacepy_testing.assertWarns(self, 'always', r'f.*',
                                      SPTestWarning):
         warnings.warn('foo', SPTestWarning)