Home | History | Annotate | Download | only in tests
      1 """Tests for distutils.util."""
      2 import sys
      3 import unittest
      4 from test.test_support import run_unittest
      5 
      6 from distutils.errors import DistutilsByteCompileError
      7 from distutils.util import byte_compile, grok_environment_error
      8 
      9 
     10 class UtilTestCase(unittest.TestCase):
     11 
     12     def test_dont_write_bytecode(self):
     13         # makes sure byte_compile raise a DistutilsError
     14         # if sys.dont_write_bytecode is True
     15         old_dont_write_bytecode = sys.dont_write_bytecode
     16         sys.dont_write_bytecode = True
     17         try:
     18             self.assertRaises(DistutilsByteCompileError, byte_compile, [])
     19         finally:
     20             sys.dont_write_bytecode = old_dont_write_bytecode
     21 
     22     def test_grok_environment_error(self):
     23         # test obsolete function to ensure backward compat (#4931)
     24         exc = IOError("Unable to find batch file")
     25         msg = grok_environment_error(exc)
     26         self.assertEqual(msg, "error: Unable to find batch file")
     27 
     28 
     29 def test_suite():
     30     return unittest.makeSuite(UtilTestCase)
     31 
     32 if __name__ == "__main__":
     33     run_unittest(test_suite())
     34