Back to index

python3.2  3.2.2
Public Member Functions | Static Public Attributes
test.test_warnings.CWarnTests Class Reference
Inheritance diagram for test.test_warnings.CWarnTests:
Inheritance graph
[legend]
Collaboration diagram for test.test_warnings.CWarnTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_accelerated
def setUp
def tearDown
def test_message
def test_warn_nonstandard_types
def test_filename
def test_stacklevel
def test_missing_filename_not_main
def test_missing_filename_main_with_argv
def test_missing_filename_main_without_argv
def test_missing_filename_main_with_argv_empty_string
def test_warn_explicit_type_errors
def test_bad_str

Static Public Attributes

 module = c_warnings

Detailed Description

Definition at line 363 of file test_warnings.py.


Member Function Documentation

def test.test_warnings.BaseTest.setUp (   self) [inherited]

Definition at line 47 of file test_warnings.py.

00047 
00048     def setUp(self):
00049         # The __warningregistry__ needs to be in a pristine state for tests
00050         # to work properly.
00051         if '__warningregistry__' in globals():
00052             del globals()['__warningregistry__']
00053         if hasattr(warning_tests, '__warningregistry__'):
00054             del warning_tests.__warningregistry__
00055         if hasattr(sys, '__warningregistry__'):
00056             del sys.__warningregistry__
00057         # The 'warnings' module must be explicitly set so that the proper
00058         # interaction between _warnings and 'warnings' can be controlled.
00059         sys.modules['warnings'] = self.module
00060         super(BaseTest, self).setUp()

Here is the caller graph for this function:

def test.test_warnings.BaseTest.tearDown (   self) [inherited]

Definition at line 61 of file test_warnings.py.

00061 
00062     def tearDown(self):
00063         sys.modules['warnings'] = original_warnings
00064         super(BaseTest, self).tearDown()
00065 

Here is the caller graph for this function:

Definition at line 368 of file test_warnings.py.

00368 
00369     def test_accelerated(self):
00370         self.assertFalse(original_warnings is self.module)
00371         self.assertFalse(hasattr(self.module.warn, '__code__'))

Here is the call graph for this function:

def test.test_warnings.WarnTests.test_bad_str (   self) [inherited]

Definition at line 349 of file test_warnings.py.

00349 
00350     def test_bad_str(self):
00351         # issue 6415
00352         # Warnings instance with a bad format string for __str__ should not
00353         # trigger a bus error.
00354         class BadStrWarning(Warning):
00355             """Warning with a bad format string for __str__."""
00356             def __str__(self):
00357                 return ("A bad formatted string %(err)" %
00358                         {"err" : "there is no %(err)s"})
00359 
00360         with self.assertRaises(ValueError):
00361             self.module.warn(BadStrWarning())
00362 

Here is the call graph for this function:

def test.test_warnings.WarnTests.test_filename (   self) [inherited]

Definition at line 222 of file test_warnings.py.

00222 
00223     def test_filename(self):
00224         with warnings_state(self.module):
00225             with original_warnings.catch_warnings(record=True,
00226                     module=self.module) as w:
00227                 warning_tests.inner("spam1")
00228                 self.assertEqual(os.path.basename(w[-1].filename),
00229                                     "warning_tests.py")
00230                 warning_tests.outer("spam2")
00231                 self.assertEqual(os.path.basename(w[-1].filename),
00232                                     "warning_tests.py")

Here is the call graph for this function:

def test.test_warnings.WarnTests.test_message (   self) [inherited]

Definition at line 200 of file test_warnings.py.

00200 
00201     def test_message(self):
00202         with original_warnings.catch_warnings(record=True,
00203                 module=self.module) as w:
00204             self.module.simplefilter("once")
00205             for i in range(4):
00206                 text = 'multi %d' %i  # Different text on each call.
00207                 self.module.warn(text)
00208                 self.assertEqual(str(w[-1].message), text)
00209                 self.assertTrue(w[-1].category is UserWarning)

Here is the call graph for this function:

Definition at line 274 of file test_warnings.py.

00274 
00275     def test_missing_filename_main_with_argv(self):
00276         # If __file__ is not specified and the caller is __main__ and sys.argv
00277         # exists, then use sys.argv[0] as the file.
00278         if not hasattr(sys, 'argv'):
00279             return
00280         filename = warning_tests.__file__
00281         module_name = warning_tests.__name__
00282         try:
00283             del warning_tests.__file__
00284             warning_tests.__name__ = '__main__'
00285             with warnings_state(self.module):
00286                 with original_warnings.catch_warnings(record=True,
00287                         module=self.module) as w:
00288                     warning_tests.inner('spam9', stacklevel=1)
00289                     self.assertEqual(w[-1].filename, sys.argv[0])
00290         finally:
00291             warning_tests.__file__ = filename
00292             warning_tests.__name__ = module_name

Here is the call graph for this function:

Definition at line 313 of file test_warnings.py.

00313 
00314     def test_missing_filename_main_with_argv_empty_string(self):
00315         # If __file__ is not specified, the caller is __main__, and sys.argv[0]
00316         # is the empty string, then '__main__ is the file name.
00317         # Tests issue 2743.
00318         file_name = warning_tests.__file__
00319         module_name = warning_tests.__name__
00320         argv = sys.argv
00321         try:
00322             del warning_tests.__file__
00323             warning_tests.__name__ = '__main__'
00324             sys.argv = ['']
00325             with warnings_state(self.module):
00326                 with original_warnings.catch_warnings(record=True,
00327                         module=self.module) as w:
00328                     warning_tests.inner('spam11', stacklevel=1)
00329                     self.assertEqual(w[-1].filename, '__main__')
00330         finally:
00331             warning_tests.__file__ = file_name
00332             warning_tests.__name__ = module_name
00333             sys.argv = argv

Here is the call graph for this function:

Definition at line 293 of file test_warnings.py.

00293 
00294     def test_missing_filename_main_without_argv(self):
00295         # If __file__ is not specified, the caller is __main__, and sys.argv
00296         # is not set, then '__main__' is the file name.
00297         filename = warning_tests.__file__
00298         module_name = warning_tests.__name__
00299         argv = sys.argv
00300         try:
00301             del warning_tests.__file__
00302             warning_tests.__name__ = '__main__'
00303             del sys.argv
00304             with warnings_state(self.module):
00305                 with original_warnings.catch_warnings(record=True,
00306                         module=self.module) as w:
00307                     warning_tests.inner('spam10', stacklevel=1)
00308                     self.assertEqual(w[-1].filename, '__main__')
00309         finally:
00310             warning_tests.__file__ = filename
00311             warning_tests.__name__ = module_name
00312             sys.argv = argv

Here is the call graph for this function:

Definition at line 260 of file test_warnings.py.

00260 
00261     def test_missing_filename_not_main(self):
00262         # If __file__ is not specified and __main__ is not the module name,
00263         # then __file__ should be set to the module name.
00264         filename = warning_tests.__file__
00265         try:
00266             del warning_tests.__file__
00267             with warnings_state(self.module):
00268                 with original_warnings.catch_warnings(record=True,
00269                         module=self.module) as w:
00270                     warning_tests.inner("spam8", stacklevel=1)
00271                     self.assertEqual(w[-1].filename, warning_tests.__name__)
00272         finally:
00273             warning_tests.__file__ = filename

Here is the call graph for this function:

Definition at line 233 of file test_warnings.py.

00233 
00234     def test_stacklevel(self):
00235         # Test stacklevel argument
00236         # make sure all messages are different, so the warning won't be skipped
00237         with warnings_state(self.module):
00238             with original_warnings.catch_warnings(record=True,
00239                     module=self.module) as w:
00240                 warning_tests.inner("spam3", stacklevel=1)
00241                 self.assertEqual(os.path.basename(w[-1].filename),
00242                                     "warning_tests.py")
00243                 warning_tests.outer("spam4", stacklevel=1)
00244                 self.assertEqual(os.path.basename(w[-1].filename),
00245                                     "warning_tests.py")
00246 
00247                 warning_tests.inner("spam5", stacklevel=2)
00248                 self.assertEqual(os.path.basename(w[-1].filename),
00249                                     "test_warnings.py")
00250                 warning_tests.outer("spam6", stacklevel=2)
00251                 self.assertEqual(os.path.basename(w[-1].filename),
00252                                     "warning_tests.py")
00253                 warning_tests.outer("spam6.5", stacklevel=3)
00254                 self.assertEqual(os.path.basename(w[-1].filename),
00255                                     "test_warnings.py")
00256 
00257                 warning_tests.inner("spam7", stacklevel=9999)
00258                 self.assertEqual(os.path.basename(w[-1].filename),
00259                                     "sys")

Here is the call graph for this function:

Definition at line 334 of file test_warnings.py.

00334 
00335     def test_warn_explicit_type_errors(self):
00336         # warn_explicit() should error out gracefully if it is given objects
00337         # of the wrong types.
00338         # lineno is expected to be an integer.
00339         self.assertRaises(TypeError, self.module.warn_explicit,
00340                             None, UserWarning, None, None)
00341         # Either 'message' needs to be an instance of Warning or 'category'
00342         # needs to be a subclass.
00343         self.assertRaises(TypeError, self.module.warn_explicit,
00344                             None, None, None, 1)
00345         # 'registry' must be a dict or None.
00346         self.assertRaises((TypeError, AttributeError),
00347                             self.module.warn_explicit,
00348                             None, Warning, None, 1, registry=42)

Here is the call graph for this function:

Definition at line 211 of file test_warnings.py.

00211 
00212     def test_warn_nonstandard_types(self):
00213         # warn() should handle non-standard types without issue.
00214         for ob in (Warning, None, 42):
00215             with original_warnings.catch_warnings(record=True,
00216                     module=self.module) as w:
00217                 self.module.simplefilter("once")
00218                 self.module.warn(ob)
00219                 # Don't directly compare objects since
00220                 # ``Warning() != Warning()``.
00221                 self.assertEqual(str(w[-1].message), str(UserWarning(ob)))

Here is the call graph for this function:


Member Data Documentation

Definition at line 364 of file test_warnings.py.


The documentation for this class was generated from the following file: